Expand description
Expose any klieo ToolInvoker as an MCP server over stdio or HTTP (see the http cargo feature).
This crate is the inverse of klieo-tools-mcp: instead of a Rust
host calling external MCP servers, it lets external MCP hosts
(Claude Desktop, Continue, LangGraph, OpenAI Agents SDK) call
into a Rust-built klieo ToolInvoker.
Polyglot strategy: klieo exposes three wire-level contracts so non-Rust hosts can integrate without depending on klieo crates — the NATS bus (durable pipelines), this MCP server (stdio/HTTP tool calls), and the A2A peer protocol (JSON-RPC). This crate covers the MCP-server contract.
§Scope
- stdio transport — newline-delimited JSON-RPC 2.0 frames on stdin/stdout, matching the MCP reference spec.
tools/list— derived from the invoker’s catalogue.tools/call— dispatches toToolInvoker::invokewith aToolCtxminted per request from theMcpServerBuilder::with_tool_ctx_factory-supplied factory. Default factory is the in-memory noop wiring (Pubsub/KvStore/JobQueuefromklieo-bus-memory, fresh per call). Override the factory to expose tools that need real bus access.initialize/shutdown— standard MCP handshake.
Out-of-scope:
- SSE streaming responses (HTTP transport returns JSON only).
- Multi-tenant auth (wrap
router()with a tower auth layer, or front with an auth-enforcing reverse proxy).
§Agent exposure (0.9, ADR-010)
McpServer::expose_agent_with_schema(agent, schema, ctx_factory)
wraps any klieo_core::Agent as a single MCP tool whose
inputSchema is the caller-supplied JSON Schema. The
ctx_factory closure is called per tools/call to mint a
fresh klieo_core::agent::AgentContext (so each invocation gets its own RunId).
Behind the schemars cargo feature, expose_agent::<A>(agent, ctx_factory) derives the schema automatically via
schema_for!(A::Input). See ADR-010 for the trade-off.
Re-exports§
pub use outbound_sink::OutboundFrameSink;pub use outbound_sink::OutboundSinkError;pub use sampling::ModelHint;pub use sampling::ModelPreferences;pub use sampling::SamplingContent;pub use sampling::SamplingMessage;pub use sampling::SamplingRequest;pub use sampling::SamplingResponse;pub use roots::Root;pub use outbound_ext::McpOutboundExt;pub use outbound_sink::bench_stdio_sink;
Modules§
- outbound_
ext - Typed extension methods over
klieo_core::ServerOutbound. - outbound_
sink - Per-transport frame-write abstraction over JSON-RPC envelopes.
- roots
- MCP roots — client-declared URI scopes the server may operate on.
- sampling
- MCP
sampling/createMessagewire-format types.
Structs§
- McpServer
- MCP server that exposes a
klieo-coreToolInvokeras a stdio MCP server. - McpServer
Builder - Builder for
McpServer. Collects one or more invokers (rawToolInvokers orAgents wrapped as single-tool invokers) and configures server-level concerns such as transports, parent cancel, leader election, tenant binding, and authentication.
Enums§
- McpBuild
Error - Errors returned by
McpServerBuilder::buildandMcpServerBuilder::build_arc. - McpServer
Error - Top-level error from the MCP server loop.
- Orphan
Outcome - Re-export the cluster-0.24 follower-side orphan re-invoke gate
for integration tests. Gated on
test-fixturesso production callers cannot reach the helper. Seecrate::http::OrphanOutcome
Constants§
- LEADER_
TTL - Leader-claim TTL for the
klieo-leadersKV bucket used bystream_tools_call(claim on invoke) andstream_resume(orphan check on resume). Operators MUST configure the JetStream KV bucket withmax_ageequal to this value so a dead replica’s leader entry evicts automatically; the registry’s heartbeat runs everyTTL / 2. See ADR-020. - MCP_
LEADER_ KEY_ PREFIX - Leader-key prefix for the MCP transport in the shared
klieo-leadersbucket. Mirrorsa2a.<task_id>on the A2A side. - MCP_
PROTOCOL_ VERSION - MCP protocol revision advertised on every
initializeresponse.
Functions§
- bench_
filter_ replay - Scans a replay-buffer snapshot and returns entries with
event_id > since_id. Approximates the per-frame scan cost of the SSE replay path without HTTP header parsing or lock acquisition overhead. Available only under thebenchfeature. - encode_
sse_ frame - Encodes one SSE frame into a
Bytesbuffer:id: <N>\ndata: <json>\n\n. - handle_
dead_ leader_ orphan_ mcp - Re-export the cluster-0.24 follower-side orphan re-invoke gate
for integration tests. Gated on
test-fixturesso production callers cannot reach the helper. Seecrate::http::OrphanOutcome
Type Aliases§
- Agent
Context Factory - Factory for fresh
klieo_core::agent::AgentContextvalues, called once pertools/callso each invocation gets its ownRunId+ cancel token. Caller-owned to keepklieo-mcp-serverfree of opinions about which memory / bus / llm backends an agent runs against. - Tool
CtxFactory - Factory for fresh
klieo_core::tool::ToolCtxvalues, called once pertools/callso each invocation gets its ownPubsub/KvStore/JobQueue(or a shared one, caller’s choice). Default =default_tool_ctx_factorywhich mints the same per-request in-memory wiringserve_stdiohas used since 0.8. Override viaMcpServerBuilder::with_tool_ctx_factoryto expose bus-using tools through this server.