Expand description
Serve Rig agents and tools over the Model Context Protocol, so any MCP client (Claude Code, Cursor, Zed, Claude Desktop, another agent) can use them.
- An
agentbecomes a tool that takes a message and an optionalsession_id, keeps the conversation, streams its text as progress notifications, and stops when the client cancels. - A
typed_agentanswers with structured content matching its output schema. - A plain Rig
toolis exposed as itself, with its annotations, and runs without a model.
Built on the official MCP Rust SDK, rmcp.
use rig_mcp_server::{McpServer, ServeError};
async fn serve(agent: rig_agent::Agent) -> Result<(), ServeError> {
// A local client launches this binary and talks to it over stdio.
McpServer::new("my-agents").agent(agent).serve_stdio().await
}Over Streamable HTTP the same server answers at /mcp. With a bearer token,
calls without it get HTTP 401:
use rig_mcp_server::McpServer;
async fn serve_http(server: McpServer, token: &str) -> Result<(), Box<dyn std::error::Error>> {
let app = server.bearer_token(token).into_router()?;
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await?;
rig_mcp_server::axum::serve(listener, app).await?;
Ok(())
}An HTTP client connects to http://127.0.0.1:3000/mcp and sends the token on
every request, as Authorization: Bearer <token>. For Claude Code:
claude mcp add --transport http my-agents http://127.0.0.1:3000/mcp --header "Authorization: Bearer <token>".
Prompts and replies go on the trace only when the agent records them, with
AgentBuilder::record_content_telemetry(true). It is off by default, as in Rig.
Re-exports§
pub use axum;pub use rig_memory;pub use rmcp;
Structs§
- Completion
Request - One
completion/completerequest, as a completer sees it. - McpServer
- Rig agents and tools served over the Model Context Protocol.
- Presentation
- The title and icons a client may show for a tool, resource or prompt.
- Template
Vars - The values of a resource template’s variables, taken from a read URI.
Enums§
- Build
Error - Why an
McpServercould not be served. - Completion
Target - What a client asks completions for.
Constants§
- DEFAULT_
HISTORY_ TOKENS - How many tokens of history a request sends by default.
- DEFAULT_
MAX_ CONCURRENT_ CALLS - How many calls run at once by default; more are answered as busy.
- DEFAULT_
MAX_ CONTEXTS - How many sessions the in-memory store remembers by default.
- DEFAULT_
MAX_ REQUEST_ BYTES - The largest HTTP request body by default, in bytes: the limit the MCP SDK already applied (4 MiB). A larger POST gets 413 Payload Too Large.
- DEFAULT_
MAX_ RUN_ DURATION - How long one agent run may take by default before it is stopped.
- MCP_
PATH - Where the Streamable HTTP endpoint is mounted by
McpServer::into_router.
Type Aliases§
- Serve
Error - Why a server stopped serving.