/grpcclient-jl:grpcclient-jlfrom grpcclient-jl
Covers generating gRPC client stubs from .proto files with protojl and using the gRPCChannel + service-module API in Julia. Includes unary/streaming RPC, deadlines, cancellation, bearer tokens, metadata, and exception handling.
Ships in grpcclient-jl. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
A Julia gRPC client built on libcurl for HTTP/2 transport, with client stubs generated by ProtoBuf.jl. Version 1.2.0-rc1. Requires Julia 1.10, streaming RPC included.
Exported names: grpc_init, grpc_shutdown, grpc_global_handle, grpc_register_service_codegen, gRPCChannel, gRPCAsync, grpc_async_request, grpc_async_await, grpc_sync_request, grpc_cancel, gRPCCURL, gRPCRequest, gRPCServiceClient, gRPCAsyncChannelResponse, gRPCException, gRPCServiceCallException.
Codegen emits two client APIs, both on by default:
gRPCChannel plus one baremodule per service, where each RPC is a function called as MyService.MyRPC(chan, request). Prefer it for new code.MyService_MyRPC_Client constructors driven by grpc_sync_request / grpc_async_request / grpc_async_await. Kept for backwards compatibility.Both are generated from the same .proto. grpc_register_service_codegen(legacy = false) before protojl drops the legacy half, generating less code and giving cleaner IDE completions.
using gRPCClient must come before protojl. Loading the package registers the service codegen hook in __init__. Generate stubs without it loaded and the output contains message structs but no service module or *_Client constructors, with no error to tell you.included, not usinged. They are plain scripts, not registered packages.using ProtoBuf
using gRPCClient # before protojl, see rule 1
protojl("path/to/service.proto", "proto_search_root", "output_dir")
The arguments are the .proto file, the directory used to resolve its import statements, and the output directory. For package foo, output lands in output_dir/foo/foo_pb.jl with a thin output_dir/foo/foo.jl module wrapper. Read references/codegen.md for the generated layout, the two emitted APIs, the grpc_register_service_codegen switches, cross-package imports, and the proto to Julia type mapping.
A gRPCChannel is a lightweight value holding a handle, host, port, and options. Create one and reuse it for every RPC against that server:
using gRPCClient
include("gen/foo/foo_pb.jl")
chan = gRPCChannel("localhost", 50051; deadline = 30)
Connection options, accepted by gRPCChannel and overridable per call (the per-call value wins):
| Option | Default | Notes |
|---|---|---|
secure | false | true selects https, false selects http |
deadline | 10 | Seconds, covering the whole call from submission including time queued for a concurrency slot. Inf disables it. 0 expires immediately; negative, NaN, and -Inf raise INVALID_ARGUMENT |
keepalive | 60 | Seconds; sets both TCP keepalive idle time and probe interval |
max_send_message_length | 4*1024*1024 | Per outgoing message, excluding the 5-byte gRPC frame |
max_recieve_message_length | 4*1024*1024 | Per incoming message. The keyword carries a spelling error, recieve, and must be written exactly that way |
token | nothing | Sent as authorization: Bearer <token> on every request |
metadata | nothing | Dict{String,String} of extra headers. Per-call metadata merges key by key with channel metadata rather than replacing it |
Any other keyword raises ArgumentError: Invalid field of gRPCConnectionOptions, which is what a misspelling looks like. The grpc handle (which connection pool and concurrency limit to use, see references/concurrency.md) is a keyword too: gRPCChannel("host", 50051; grpc = h).
Setting token and an authorization metadata entry together raises INVALID_ARGUMENT, since they are the same header; the check is case insensitive. To override a channel-level token per call, pass token = nothing next to the new metadata.
grpc_init() runs automatically when the package loads, so no setup call is needed. grpc_shutdown() closes connections and cancels in-flight requests, which is useful under Revise or before exiting.
Each service becomes a baremodule; each RPC is an exported function inside it. Pass the channel (or a bare host, port pair) plus the request wherever the request side is unary. How the call is driven depends on the RPC's shape, and only synchronous unary returns the response directly — every other form returns a call handle.
chan = gRPCChannel("localhost", 50051)
# Unary, synchronous: blocks, returns the decoded response, throws on error
response = MyService.MyRPC(chan, MyRequest(42, UInt64[]))
# Bare host/port instead of a channel (builds a one-off channel)
response = MyService.MyRPC("localhost", 50051, MyRequest(42, UInt64[]))
Pass gRPCAsync() to start the call without blocking; it returns a gRPCUnaryCall. fetch waits for the response (raising on error) and releases resources. fetch does not consume: repeated calls return the same response.
rpc = MyService.MyRPC(chan, MyRequest(42, UInt64[]), gRPCAsync())
# ... other work while the call is in flight ...
response = fetch(rpc)
For many in-flight calls whose responses you want as they land, pass a channel and an index instead:
ch = Channel{gRPCAsyncChannelResponse{MyResponse}}(10)
for (index, request) in enumerate(requests)
MyService.MyRPC(chan, request, ch, index) # returns nothing
end
for _ in 1:length(requests)
cr = take!(ch) # fields: index, response, ex
isnothing(cr.ex) || throw(cr.ex) # a failed call arrives with ex set, response nothing
handle(cr.index, cr.response)
end
| Shape | Open with | Send | Receive | Finish |
|---|---|---|---|---|
| Client streaming | MyService.MyClientStreamRPC(chan) | put!(rpc, msg) | fetch(rpc) (the single response) | fetch closes the request stream for you |
| Server streaming | MyService.MyServerStreamRPC(chan, req) | — | take!(rpc) / for r in rpc | close(rpc) or detach(rpc) |
| Bidirectional | MyService.MyBidiRPC(chan) | put!(rpc, msg) | take!(rpc) / for r in rpc | put!(rpc; done = true), then close/detach |
# Client streaming: many requests, one response
rpc = MyService.MyClientStreamRPC(chan)
for i in 1:100
put!(rpc, MyRequest(i, UInt64[]))
end
response = fetch(rpc) # ends the request stream and returns the response
# Server streaming, known count
rpc = MyService.MyServerStreamRPC(chan, MyRequest(10, UInt64[]))
for _ in 1:10
response = take!(rpc)
end
close(rpc)
# Server / bidirectional streaming, unknown count
for response in rpc # ends cleanly when the server closes the stream
handle(response)
end
Read references/streaming.md before writing streaming code — it covers draining safely, the take!/fetch/wait semantics, and finishing with close vs detach.
Every form except synchronous unary returns an AbstractgRPCCall handle. Supported operations, the shapes that accept them, and when each throws (on failure = only when the call ends with a non-OK status; a clean call never throws there):
| Operation | Applies to | Throws |
|---|---|---|
put!(rpc, msg) | client, bidi | If the call has ended |
put!(rpc[, msg]; done = true) | client, bidi | Only when sending msg |
isfull(rpc) (Julia 1.12 or later) | client, bidi | Never |
isopen(rpc) | all | Never |
isready(rpc) | all | Never |
wait(rpc) | all | On failure |
fetch(rpc) | async unary, client, server, bidi | On failure (streaming: when ended and drained) |
take!(rpc) | server, bidi | When ended and drained |
for r in rpc / iterate | server, bidi | On failure |
close(rpc) | all | On failure |
detach(rpc; throws = true) | all | On failure |
Pass Vector{UInt8} in place of a typed message to send an already-encoded payload, or as an extra argument to receive one undecoded. Either side is independent. Works on the call itself and on put! / take! / fetch.
using ProtoBuf
io = IOBuffer(); encode(ProtoEncoder(io), MyRequest(42, UInt64[])); raw = take!(io)
response = MyService.MyRPC(chan, raw) # raw request, typed response
raw_resp = MyService.MyRPC(chan, MyRequest(42, UInt64[]), Vector{UInt8}) # raw response
resp = take!(server_stream_rpc, Vector{UInt8}) # raw streaming response
For a large raw unary request, borrow_request = true sends it from the vector without a copy; the vector must then not be written, resized or emptied until the call completes. See references/raw-buffers.md.
struct gRPCServiceCallException <: gRPCException
grpc_status::Int # gRPC status code
message::String
end
The GRPC_* status constants are not exported. Qualify them (gRPCClient.GRPC_DEADLINE_EXCEEDED) or import them explicitly. Available: GRPC_OK, GRPC_CANCELLED, GRPC_UNKNOWN, GRPC_INVALID_ARGUMENT, GRPC_DEADLINE_EXCEEDED, GRPC_NOT_FOUND, GRPC_ALREADY_EXISTS, GRPC_PERMISSION_DENIED, GRPC_RESOURCE_EXHAUSTED, GRPC_FAILED_PRECONDITION, GRPC_ABORTED, GRPC_OUT_OF_RANGE, GRPC_UNIMPLEMENTED, GRPC_INTERNAL, GRPC_UNAVAILABLE, GRPC_DATA_LOSS, GRPC_UNAUTHENTICATED.
Where the error surfaces depends on how the call is driven: a synchronous unary call raises directly; async and streaming calls raise only submission-time programming errors when created and defer everything time- or server-dependent to fetch/take!/wait/close/detach; put! raises once the call stops accepting requests. references/deadlines-cancellation.md has the full contract.
Still generated by default. One constructor is generated per RPC, named {ServiceName}_{RPCName}_Client, hitting path /{package}.{ServiceName}/{RPCName}. A client is a lightweight value: it holds a handle, host, port, path, and options, so construct one per RPC and reuse it. It takes the same connection options as gRPCChannel, plus constructor-only grpc, TRequest, and TResponse keywords.
client = MyService_MyRPC_Client("localhost", 50051; deadline = 30)
# Simplest: send and block
response = grpc_sync_request(client, MyRequest(42, UInt64[]))
# Submit now, collect later: lets many requests fly concurrently
reqs = [grpc_async_request(client, MyRequest(i, UInt64[])) for i in 1:10]
for req in reqs
response = grpc_async_await(client, req) # returns the decoded response
end
# Out-of-order completion: handle each response as it lands
ch = Channel{gRPCAsyncChannelResponse{MyResponse}}(10)
for (index, request) in enumerate(requests)
grpc_async_request(client, request, ch, index) # returns nothing
end
for _ in 1:length(requests)
cr = take!(ch) # fields: index, response, ex
isnothing(cr.ex) || throw(cr.ex)
handle(cr.index, cr.response)
end
The channel form never throws at submission time; a failed request arrives as a gRPCAsyncChannelResponse whose ex is set and whose response is nothing, so always check ex before touching response.
Requests and responses move through Channels, and the streaming side of the call is chosen by the RPC definition, not by the call site:
| RPC variant | Call shape | grpc_async_await |
|---|---|---|
| Client streaming | grpc_async_request(client, request_c) | grpc_async_await(client, req) returns the single response |
| Server streaming | grpc_async_request(client, request, response_c) | grpc_async_await(req) raises only, returns no data |
| Bidirectional | grpc_async_request(client, request_c, response_c) | grpc_async_await(req) raises only, returns no data |
Close your request channel to signal end of stream; the library closes the response channel when the stream ends. Read references/streaming.md before writing streaming code: channel ownership, the await asymmetry above, and cancellation of a long-lived stream are all easy to get wrong.
| File | Read it when |
|---|---|
references/codegen.md | Generating or debugging stubs, the two emitted APIs and grpc_register_service_codegen switches, predicting generated names, mapping proto types to Julia, cross-package proto imports |
references/streaming.md | Writing or reviewing any streaming call, draining a response stream safely, or debugging a stream that hangs or never closes |
references/concurrency.md | Choosing a handle, tuning max_streams, the sticky scheduling model, thread safety, isolating a connection pool |
references/deadlines-cancellation.md | Deadline accounting, deadline = Inf lifetimes, detach/grpc_cancel, the watchdog, spurious or missing DEADLINE_EXCEEDED |
references/raw-buffers.md | Forwarding already-encoded bytes, or partially decoding a large response |
| Symptom | Cause |
|---|---|
UndefVarError: MyService or MyService_MyRPC_Client | protojl ran without gRPCClient loaded, or the generated file was not included |
UndefVarError on a GRPC_* constant | The constants are not exported; qualify with gRPCClient. |
MethodError on a keyword named max_receive_message_length | The keyword is max_recieve_message_length |
ArgumentError: Invalid field of gRPCConnectionOptions: x | Unknown channel or per-call option keyword, most often a misspelling |
ArgumentError mentioning borrow_request | It was passed to a typed request, a streaming call, or the Channel unary form; it applies only to a raw unary request |
| A drain loop drops responses or blocks forever | Guarded on isopen/isready; use iteration, a known count, or wait + isready |
take!/fetch throws "no more responses are available" | Read past the end of a finished stream; stop when iteration ends or a known count is reached |
Streaming fetch keeps returning the same message | fetch does not remove; use take! to consume |
DEADLINE_EXCEEDED under load with a healthy server | The 10 second default deadline includes time queued for one of the handle's 16 concurrency slots; see references/concurrency.md |
| A client or bidi stream never finishes | The request stream was never ended (put!(rpc; done = true), or fetch for client streaming) |
INVALID_ARGUMENT mentioning the authorization header | token and an authorization metadata entry were both set |
| Call hangs forever | deadline = Inf with no detach/grpc_cancel, which is the documented behavior of that setting |
What SKILL.md sets; muted values are Claude Code's defaults
2 skills in this plugin
npx claudepluginhub juliaio/grpcclient.jl --plugin grpcclient-jlOther plugins' skills for the same job