Expand description
rustlavel-mcp: the Model Context Protocol, both directions.
An application uses this crate to be an MCP server — handing an agent
its own features as tools and resources — and to be an MCP client,
using servers somebody else wrote. Both halves speak JSON-RPC 2.0 written
from scratch on rustlavel_core::Json; there is no MCP SDK underneath.
§Serving
Registrations go in one place, and a transport is chosen at the edge:
ⓘ
fn mcp() -> Server {
Server::new("shop", env!("CARGO_PKG_VERSION"))
.instructions("Use `orders.total` before quoting a refund.")
.tool(Tool::new(
"orders.total",
"Total value of one customer's orders",
Schema::object().integer("customer_id", "Which customer"),
|args: Json| async move { Ok(Json::from(total_for(&args))) },
))
}
// Over HTTP, as part of the application:
App::new().plugin(Mcp::new(mcp()))
// Or over stdio, for a desktop client that launches the binary:
stdio::serve_stdio(Arc::new(mcp())).await?§Consuming
ⓘ
let mut client = McpClient::spawn("some-mcp-server", &[])?;
client.initialize().await?;
for tool in client.list_tools().await? {
println!("{}: {}", tool.name, tool.description);
}§What the design insists on
- Schemas are built, not typed. A tool declares its input through
Schema, and the same declaration is what an agent reads and what the server enforces — the two cannot drift apart. - Arguments are untrusted. They arrive from a language model. Every
tools/callis validated against the declared schema before any application code runs. - A tool cannot take the process down. Handlers run inside a panic
guard; a panic becomes an
isErrorresult the agent can read. - Every call is instrumented.
tools/calldispatches anmcp.callevent — tool, duration, outcome — so Telescope can show it.
Re-exports§
pub use client::McpClient;pub use http::Mcp;pub use prompt::Prompt;pub use protocol::Content;pub use protocol::Implementation;pub use protocol::PROTOCOL_VERSION;pub use protocol::PromptArgument;pub use protocol::PromptInfo;pub use protocol::PromptMessage;pub use protocol::ResourceInfo;pub use protocol::Role;pub use protocol::ServerInfo;pub use protocol::ToolInfo;pub use protocol::ToolResult;pub use resource::Resource;pub use rpc::Id;pub use rpc::RpcError;pub use schema::Field;pub use schema::FieldType;pub use schema::Schema;pub use server::Server;pub use tool::Tool;
Modules§
- client
- The client half: using somebody else’s MCP server from an application.
- http
- The streamable HTTP transport, mounted on the application’s own router.
- prompt
- A prompt: a reusable message template the user picks, not the model.
- protocol
- The MCP message shapes, as the specification defines them.
- resource
- A resource: something an application lets an agent read.
- rpc
- JSON-RPC 2.0, written on
rustlavel_core::Json. - schema
- The input schema a tool declares, and the validator that guards it.
- server
- The MCP server: what turns an application’s features into an agent’s tools.
- stdio
- The stdio transport: newline-delimited JSON over a pipe.
- tool
- A tool: something an application lets an agent do.