Agent / foldkit-agent-mcp

Diagnostics

The adapter answers some failures without telling the client why, since the cause may carry application internals. Each is a typed diagnostic, reported through foldkit-surface's Diagnostics channel:

_taglevelWhen
AuthenticateDefecterrorauthenticate died or threw; the request was answered 500.
CapabilityDefecterrorA capability's dispatch died; the call was answered a tool error naming no cause.
RequestDefecterrorHandling a request threw (a projection, a resource read); it was answered an internal error.
ToolListDefecterrorListing the tools threw after the Model changed, so no tools/list_changed was sent.
TransportEndDefectwarningA client transport's end threw as its session ended; the session ended anyway.

The host runs outside any Effect context of yours, so the reporter is an option, diagnostics, on handler, httpHandler, httpApp and stdio. Without it, a diagnostic goes to Diagnostics.Reporter's default, Effect's log, or to stderr under stdio:

ts
const reported = AgentMcp.httpHandler({
  authenticate: request => verify(request.headers['authorization']),
  createAgent: ({ principal }) => bindAgentFor(principal),
  diagnostics: diagnostic => Effect.logError(`mcp: ${diagnostic.message}`),
})

In a test, pass Diagnostics.collect().report and assert on reported.

Choosing an adapter

All four adapters serve the same AssistantAgent contract through a bound runtime.

Where the agent runsAdapter
In the page, beside the userfoldkit-agent-webmcp
An external MCP client, over stdio or HTTPfoldkit-agent-mcp
Another agent, over A2Afoldkit-agent-a2a
An Agent Native hostfoldkit-agent-native

See also

  • Agents guide — builder → contract → runtime and the authority model.
  • foldkit-agent — the protocol-neutral contract and runtime.
  • examples/todo — a focused contract served through adapters.