Skip to main content

Crate emperor_mcp

Crate emperor_mcp 

Source
Expand description

Opinionated framework for building MCP servers: stateless Streamable HTTP, content-aware output framing, and per-request credential forwarding.

Hatched from the kowalski workspace; servers built there (kowalski-mcp-rookery, kowalski-mcp-datafusion) are the reference consumers.

Two server styles share the same conventions (stateless HTTP, output framing, no auth shortcuts):

  1. transport::McpHandler — hand-rolled JSON-RPC dispatch; use transport::run_stdio (local/dev) or transport::serve_http.
  2. serve::serve — rmcp ServerHandler + #[tool_router] bootstrap at /mcp + /health, with credential-forwarding middleware for multi-tenant deployments.

Every server binary also ships a doctor subcommand built from doctor checks.

Also in the box: credentials (an upstream 401/403 becomes the MCP response’s status), limits (caps on what a tool returns), schema (lean tool definitions: strips JSON Schema boilerplate from tools/list, opt in with Self::tool_router().compact_schemas()), and two optional features: cli (shared --bind/--stdio/--allowed-host/--allowed-origin flags, cli::ServeArgs) and testkit (tool-list conformance checks for a server’s own tests, testkit::assert_tools).

See MCP_REQUIREMENTS.md and MANIFEST_SPEC.md in the repository root.

Re-exports§

pub use credentials::Rejection;
pub use credentials::credentials_rejected;
pub use framing::FrameKind;
pub use framing::frame;
pub use framing::structured_framed;
pub use headers::ForwardConfig;
pub use headers::ForwardedHeaders;
pub use headers::forward_headers_middleware;
pub use limits::Limits;
pub use limits::truncate_chars;
pub use serve::ServeOptions;
pub use serve::serve;
pub use transport::ACCEPT_STREAMABLE;
pub use transport::McpHandler;
pub use transport::http_router;
pub use transport::run_stdio;
pub use transport::serve_http;
pub use transport::wants_sse;

Modules§

clicli
Shared command-line flags for server binaries (feature cli).
credentials
Upstream credential rejection: tell the MCP client to sign in again.
doctor
doctor: an environment check every server binary ships as a subcommand.
framing
Content-aware output framing for first-party MCP tool results.
headers
Credential forwarding.
limits
Output and input caps every tool should apply: characters returned, results per call, and bytes downloaded or read from a file.
schema
Lean tool definitions: strip JSON Schema boilerplate a model pays for on every request.
serve
Streamable-HTTP server bootstrap.
testkittestkit
Conformance checks a server runs in its own tests (feature testkit).
transport
Lightweight JSON-RPC transport for hand-rolled MCP servers (McpHandler).

Functions§

init_tracing
Initialise tracing/logging to stderr (stdout stays clean for the stdio transport) with an RUST_LOG-configurable filter, defaulting to info.