Documentation
¶
Overview ¶
Package a2amcp serves the `a2a` MCP tools over HTTP, replacing the per-session stdio shim (a2a-mcp.py) every Claude Code session used to start for itself.
The tools are an A2A *client*: they reach an operator-configured target agent, not this controller's own /a2a surface. The controller only hosts them because it is a long-running KeepAlive process on the operator's machine.
Index ¶
Constants ¶
const ( A2AVersionHeader = "A2A-Version" A2AProtocolVersion = "1.0" )
A2AVersionHeader declares the A2A protocol version this client speaks, and A2AProtocolVersion is its value.
⚠️ REQUIRED, NOT OPTIONAL. a2a-go v2 serves 1.0 only, and a request that omits the header is read as 0.3 and refused with `VERSION_NOT_SUPPORTED` ("requested \"0.3\", served \"1.0\""). Measured 2026-11-08 against bborbe/agent-claude:local-scratch: the identical request fails without the header and returns the agent's reply with it. The stdio shim sends no version header, so it is broken against every 1.0 worker — this client must not inherit that.
const ( ReasonMissingBearer = "missing_bearer" ReasonInvalidBearer = "invalid_bearer" ReasonNonLoopback = "non_loopback" ReasonOriginNotAllowed = "origin_not_allowed" )
The refusal reasons a log line and a 4xx body carry.
const ( ToolAgentCard = "a2a_agent_card" ToolSend = "a2a_send" )
Tool names, identical to the stdio shim's so no caller changes.
const AgentCardPath = "/.well-known/agent-card.json"
AgentCardPath is the well-known path the target's Agent Card is served at.
const BearerFileName = "mcp-bearer" //nolint:gosec // G101: a file name, not a credential
BearerFileName is the local bearer's file name under the controller's state directory.
const DefaultTimeout = 300 * time.Second
DefaultTimeout bounds one call to the target agent. It matches the stdio shim's 300 s read budget: an A2A turn is a full model turn and routinely takes minutes.
const Path = pkg.MCPPath
Path is the route the MCP endpoint is served at. It is declared in pkg, beside the bearer gate's exemption list, so the two cannot drift apart.
const SecurityCommand = "security"
SecurityCommand is the macOS Keychain CLI the local-target branch shells out to.
const SessionHeader = "X-Claude-Code-Session-Id"
SessionHeader carries the calling Claude Code session's id. Claude Code's headersHelper (mcp-headers-helper.sh) sets it; it is the same header the claude-wrapper MCP faces use.
Variables ¶
This section is empty.
Functions ¶
func DefaultBearerFile ¶ added in v0.22.0
DefaultBearerFile returns where the /mcp bearer lives: the controller's own state directory.
⚠️ WHY A LOCAL BEARER AT ALL. A loopback check cannot tell a docker worker from a local session: measured 2026-11-08 on OrbStack, a container calling host.docker.internal arrives with a loopback peer AND local address, and it chooses its own Host header. The bearer is what a worker cannot hold — the file is readable only by the operator's uid, and the docker backend's mount allowlist never reaches the state directory.
func LoadOrCreateBearer ¶ added in v0.22.0
LoadOrCreateBearer returns the bearer stored at path, creating it on first use.
It persists rather than rotating per start: a running session holds the header its headersHelper produced at connect time, so a bearer that changed on every controller restart would cut off every connected session until it reconnected.
The value is a secret: it must never be logged or returned in an error.
func NewHandler ¶ added in v0.23.0
NewHandler returns the MCP endpoint backed by client, requiring bearer.
⚠️ This route is exempt from the controller's bearer gate and gated here instead: it must be reachable by every local session without each holding the controller's token, yet it sends A2A with the operator's token. It requires the local bearer (see LoadOrCreateBearer) and a non-empty session id — a call is authenticated AND attributed, never defaulted.
The loopback, Host and Origin checks stay as cheap outer layers (they turn away a LAN caller and a rebinding browser page), but they are NOT the authentication: measured 2026-11-08 on OrbStack, a docker worker reaches the host from a loopback peer and local address and sends whatever Host it likes. Only the bearer separates it from a session.
Types ¶
type Client ¶ added in v0.23.0
type Client interface {
// AgentCard fetches the target's Agent Card. The card is public: no credential is sent.
AgentCard(ctx context.Context) (map[string]any, error)
// Send posts one user message to the endpoint the card advertises and returns its reply.
// contextID selects the remote conversation; empty means the agent's default.
Send(ctx context.Context, text string, contextID string) (map[string]any, error)
}
Client is the A2A client behind the two MCP tools. Both methods return the same result shapes the stdio shim (a2a-mcp.py) returned, field for field, so a caller sees no change.
type KeychainReader ¶
type KeychainReader interface {
Read(ctx context.Context, service string, account string) (string, error)
}
KeychainReader reads one generic password from the macOS Keychain.
func NewKeychainReader ¶
func NewKeychainReader() KeychainReader
NewKeychainReader returns the KeychainReader that shells out to `security`.
type TokenConfig ¶
type TokenConfig struct {
// Token is the explicit value; when non-empty it wins outright.
Token string
// TargetURL is the agent the token is presented to. The Keychain branch applies only when
// it names localhost or 127.0.0.1 — the local worker's token never leaves this machine.
TargetURL string
// KeychainService and KeychainAccount name the local worker's Keychain item.
KeychainService string
KeychainAccount string
// TeamVaultKey is the final fallback, resolved through TeamVault.
TeamVaultKey string
}
TokenConfig is the precedence the stdio shim's wrapper (a2a-mcp-wrapper.sh) applies, carried unchanged so the move is footprint-only.
type TokenSource ¶
TokenSource resolves the bearer token the A2A client presents to the target agent.
The returned value is a secret: it must never be logged, echoed into a tool result, or written to a file.
func NewTokenSource ¶
func NewTokenSource( config TokenConfig, keychain KeychainReader, teamVault pkg.TeamVaultResolver, ) TokenSource
NewTokenSource returns the TokenSource applying config's precedence: explicit token, else (local target only) the Keychain item, else the TeamVault key.
It resolves on every call rather than caching: a rotated token takes effect without a restart, and a2a_send is rare enough that one subprocess per call costs nothing.