gRPC
The contract every service with an agent lane implements, and the two halves that speak it.
The case MCP does not cover: a fleet of services, each owning some tools, and one host — an MCP server, an agent loop — that has to offer all of them.
dotnet add package ApricotFramework.Agentic.Tools.Grpc # the contract, messages only
dotnet add package ApricotFramework.Agentic.Tools.Grpc.Server # a service that owns tools
dotnet add package ApricotFramework.Agentic.Tools.Grpc.Client # a host that federates themThe contract
apricot.agentic.v1, domain neutral on purpose: every service with an agent lane implements the
same one, so a consumer needs a single client rather than one per domain. The .proto ships
inside the package under protos/, so a service in another language can implement it too.
service AgentTools {
rpc ListTools (ListToolsRequest) returns (ListToolsResponse);
rpc InvokeTool (InvokeToolRequest) returns (InvokeToolResponse);
rpc InvokeToolStream (InvokeToolRequest) returns (stream InvokeToolChunk);
}
message AgentToolDeclaration {
string name = 1;
string title = 2;
string description = 3;
string input_schema = 4; // json text
string output_schema = 5; // json text, empty where none
bool read_only = 6;
bool destructive = 7;
bool idempotent = 8;
bool open_world = 9;
AgentToolResultKind result_kind = 10;
map<string, string> labels = 11;
}Schemas and results are JSON text, never google.protobuf.Struct. A Struct carries every
number as a double, which silently truncates an Int64 identifier past 2^53 — and a schema is
something to pass along rather than something to compute on. It is the same reason the schemas are
generated from .NET types rather than from the protobuf ones: proto3 cannot tell an unset string
from an empty one, so a schema derived from it tells a model every field is optional.
What is deliberately not on the wire: a target service, a resource, a scope. Those are a
deployment's idea of itself, and this library is unaware of its hosts. A fleet that wants them
puts them in labels, where nothing here interprets them.
Serving
builder.Services.AddGrpc(); // yours: this library does not call it
builder.Services.AddAgentToolsWeb();
builder.Services.AddAgentToolType<TicketTools>();
app.MapAgentTools()
.RequireAuthorization(); // whether there is a caller at allA thin projection and nothing more. Who the caller is, which tools they may reach and what a failure means are decided by the executor and its filters, exactly as for an HTTP endpoint or an MCP session — so a tool does not get a second, weaker set of rules for having been reached over gRPC.
The endpoint is the right place for this host's own authentication: the endpoint decides whether there is a caller, and the tools behind it decide what that caller may reach.
MapAgentTools() does not call AddGrpc, AddGrpcReflection or anything else. How a host serves
gRPC is its own business, and a library that decided would be one more thing to unpick.
Errors
A status code cannot say who failed. NOT_FOUND is "no tool by that name" when the framework
refused the call and "no record by that identifier" when the tool ran — and a caller acting on the
wrong reading tells a model the tool is gone when only its argument was wrong. So every failure the
framework describes carries trailers saying which (AgentToolTrailers in the contract package):
| Trailer | Values |
|---|---|
apricot-agentic-outcome | refused — the framework refused before the tool ran; failed — the tool ran and failed |
apricot-agentic-reason | refused: not_found, access_denied, unauthenticated, invalid_arguments, not_invocable; failed: fault, not_found, invalid, conflict, denied, unauthenticated, rate_limited, unavailable, timeout |
apricot-agentic-retryable | failed only: true where trying again unchanged may succeed |
| Thrown | Status | Outcome |
|---|---|---|
AgentToolNotFoundException | NotFound | refused |
AgentToolUnauthenticatedException | Unauthenticated | refused |
AgentToolAccessDeniedException | PermissionDenied | refused |
AgentToolArgumentException | InvalidArgument | refused |
AgentToolNotInvocableException | Unimplemented | refused |
AgentToolFailedException | by kind: NotFound, InvalidArgument, FailedPrecondition, PermissionDenied, Unauthenticated, ResourceExhausted, Unavailable, DeadlineExceeded, Internal | failed |
any other AgentToolException | Internal | failed |
Anything else a tool throws is the host's own, and leaves the service as the host's pipeline has
it. Describe it once with an IAgentToolExceptionTranslator — see
Hosting — and it crosses as a failure of the right
kind instead.
A failure part way through a stream fails the call rather than closing it quietly, so a caller cannot mistake a truncated sequence for a complete one.
Federating
The client is yours. Register it however this fleet registers a gRPC client — by hand, from configuration, through discovery — with its addressing, deadlines, retries, error mapping and credentials, none of which belong here. Then say which client reaches which service.
Every service implements the same contract, so the generated AgentToolsClient cannot tell them
apart. Two things can:
A type per service — the one to reach for first:
public sealed class BillingAgentToolsClient(CallInvoker invoker) : AgentTools.AgentToolsClient(invoker);
builder.Services.AddGrpcClient<BillingAgentToolsClient>(client => client.Address = new Uri("https://billing.internal"))
.AddCallCredentials(…);
builder.Services.AddGrpcAgentTools<BillingAgentToolsClient>(options => options.Prefix = "billing_");No string has to match in two places, a missing registration fails naming the type to register, and it works with registration helpers that name a client after its type — two services, two types, two names. The client factory ignores the namespace when it does that, so give each type a name of its own rather than the same name in two namespaces.
A name per service, for a host that would rather not declare types:
builder.Services.AddGrpcClient<AgentTools.AgentToolsClient>("tickets", client => client.Address = …);
builder.Services.AddGrpcAgentTools("tickets", options => options.Prefix = "tickets_");One call per service federated, each with its own source and its own options.
One service being down costs its tools, and nothing else. A remote source is external, so the
registry logs a service that fails to answer and leaves its tools out; a remote tool whose schema
cannot be read, or that one of this host's validators refuses, or whose name is already taken here
is logged and left out the same way. RequireService = true holds a service to the rules for this
host's own tools instead, for a host that would rather not run than run without it. A client this
host never registered is not an outage but a wiring bug, and fails loudly with
AgentToolConfigurationException either way.
A call reaches one service. Invoking a tool asks each source in turn for that one name and
stops at the first that has it; a source whose Prefix the name does not carry answers without
asking its service at all. A call to billing does not list tickets, and does not fail because
tickets is down.
Deadlines. A client registration's deadline — a container-wide default, say — applies to
agent tool calls too, and a tool can run for far longer than a listing takes. CallDeadline sets
one for invoking this service's tools only.
No client is held. The factory caches the channel, so a client is cheap to make — but it is made in a scope, and anything configured per client, such as an interceptor or call credentials, reads its services from that scope. A source lives as long as the process, and a client it held would carry the scope of whoever asked first to every caller after. So the source, and every tool it produces, holds only a way to get a client: one is made for each listing and each call, from the services of the caller's scope. A cached listing is therefore safe to keep for as long as you like — it holds declarations, not clients.
A remote tool arrives as a declaration built from the wire, paired with a RemoteAgentTool that
calls back through a client of the same name. It sits in the registry beside a tool written in
this process and nothing downstream can tell the difference: it goes into ChatOptions.Tools, it
can be offered over MCP, it can be re-served over gRPC.
IsOpenWorld is forced true whatever the serving host said — a tool reached over a wire is
outside this application by construction. A failed call is read from the trailers and comes back
as the same exception the serving side raised — a refusal stays a refusal across the hop, and a
failure of the operation arrives as AgentToolFailedException of the kind the serving host
reported, retryable or not. A status without trailers — an endpoint's own authentication, a
proxy — is read by its code where the code alone is unambiguous (UNAUTHENTICATED,
PERMISSION_DENIED, INVALID_ARGUMENT, UNIMPLEMENTED); an untrailed NOT_FOUND could be a tool
or a record, so it, and anything else, is left as it is rather than guessed at.
That holds when the host translates transport failures on its clients — AddGrpcErrorMapping()
on the builder, or container-wide where it reaches this client without its registration saying
so. The status is read from the whole exception chain, so a translation that keeps the original
as its inner exception reads the same, and the host's own error becomes the refusal's inner
exception. A status the serving framework did not describe is left exactly as the host's client
threw it.
Caching
Lifetime is zero by default, meaning the service is asked on every listing. Set, a listing is
held per caller: the serving host filters its listing by who is asking, so one caller's answer
is never another's. The default key is the caller's sub or name-identifier claim, or the
identity's name; CacheKey replaces it, returning null to leave a call out of the cache, or a
constant for a host whose remote surface is the same for everybody.
Point to point
The call goes from the host that federates to the service that owns the tool, directly. Nothing sits in the middle, which matters for three reasons: a middle would need credentials for every domain in the fleet, it would erase whichever claim distinguishes one agent surface from another, and it would add a hop to every one of the five to fifteen sequential calls an agent loop makes per turn.