Expand description
A simple framework for writing Model Context Protocol servers.
The types and headers modules are unconditional — both sides of the
protocol need all of them, and they cost nothing but serde. headers is
shared rather than split because a client deriving what to send and a server
checking what arrived are the same derivation; splitting them is how they
drift. Everything else sits behind a feature
naming either a side of the protocol or a transport; see the [features]
table in Cargo.toml. The default is everything.
A server that speaks a transport this crate does not implement wants
default-features = false, features = ["server"]: that is traits, the
tools! macro, and handle_request, which answers a decoded request
without doing any I/O.
A client wants default-features = false, features = ["client"]: the
client module, which is the same split from the other side — it builds
requests and classifies the messages that arrive, and leaves framing,
connections, and authorization to the transport. It pulls no dependencies
this crate does not already have.
The dependencies re-exported at the root are there for the macros to name and for a downstream tool to use without duplicating the version requirement. Each is present only under the features that pull it.
Re-exports§
pub use anyhow;serverorsessionpub use clap;clipub use dirs;cliorsessionpub use fieldwork;serverpub use log;pub use schemars;serverpub use serde;pub use serde_json;pub use shellexpand;cliorsession
Modules§
- client
client - Transport-agnostic client protocol — the mirror of
handle_request. - headers
- The standard request headers HTTP transports carry from
2026-07-28onward (SEP-2243), and the validation a server owes them. - session
session - traits
server - types
- Serialization types for the Model Context Protocol.
Macros§
- server_
info server - structured_
output server - Implement
ToolOutputfor types that deriveJsonSchemaandSerialize, using the spec’s recommended lossless shape. - tools
server
Structs§
- Server
Config server - Everything the serve loop needs beyond the tools themselves.
Constants§
- DEFAULT_
TOOLS_ TTL_ MS server - How long a client may consider a
tools/listresult fresh.
Functions§
- handle_
request server - Answer one request. Dispatch is stateless: every supported revision’s
entry points are answerable at any time, so both the
initializehandshake (revisions through 2025-11-25) and the statelessserver/discoverflow (2026-07-28) work against the same loop. - run
cli - serve
stdio - Read messages from stdin until EOF, answering each request on stdout.