An MCP server over stdio
An MCP server that a client starts as a program of its own and talks to over standard input and output, as most local tool servers run. Every request gets:
- a span named for what it asks, such as
tools/call add, which continues the client’s trace when the client sends one; - that trace id, and the request’s fields, on every log line the tool writes;
- its duration in
mcp.server.operation.duration, and the session’s inmcp.server.session.durationwhen the session ends.
Standard output carries the protocol, so nothing else may be written there. oxtel writes log lines to standard error unless told otherwise, so the server works as it is.
The code
Section titled “The code”use rmcp::handler::server::wrapper::Parameters;use rmcp::{ServiceExt, tool, tool_router};
/// The arguments of the `add` tool.#[derive(serde::Deserialize, schemars::JsonSchema)]struct Numbers { a: i64, b: i64,}
#[derive(Clone)]struct Calculator;
#[tool_router(server_handler)]impl Calculator { /// Runs inside the request's span, so its log lines carry the client's /// trace id. #[tool(description = "Add two whole numbers.")] fn add(&self, Parameters(Numbers { a, b }): Parameters<Numbers>) -> String { tracing::info!(a, b, "adding"); (a + b).to_string() }}
#[tokio::main]async fn main() -> Result<(), Box<dyn std::error::Error>> { // rmcp logs each session's start and end at `info`, with everything the // client said about itself, in a span of its own. Keep rmcp to its // warnings, unless RUST_LOG says otherwise. let filter = std::env::var("RUST_LOG").unwrap_or_else(|_| "info,rmcp=warn".into()); // First, so the MCP metrics find oxtel's recorder. Keep the guard until // main returns: dropping it sends what's left. let _telemetry = oxtel::builder() .with_traces_filter(&filter) .with_logs_filter(&filter) .install()?;
let server = oxtel_rmcp::Instrumented::new(Calculator) // What `network.transport` records: stdio is a pipe. .with_transport("pipe") .serve(rmcp::transport::stdio()) .await?; // Until the client closes standard input. server.waiting().await?; Ok(())}Dependencies
Section titled “Dependencies”[dependencies]oxtel = "0.4"oxtel-rmcp = "0.4"rmcp = { version = "3.5", features = ["transport-io"] }schemars = "1"serde = { version = "1", features = ["derive"] }tokio = { version = "1", features = ["macros", "rt-multi-thread"] }tracing = "0.1"Run it
Section titled “Run it”A client starts the server and writes requests to it. To stand in for one, this command, run from a checkout of the repository, sends the server a short session from a file:
cargo run -p oxtel-examples --example mcp-stdio < examples/input/mcp-stdio.jsonlThe session starts, asks for the server’s tools, and calls add:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"example-client","version":"1.0.0"}}}{"jsonrpc":"2.0","method":"notifications/initialized"}{"jsonrpc":"2.0","id":2,"method":"tools/list"}{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"add","arguments":{"a":2,"b":3},"_meta":{"traceparent":"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"}}}The call to add carries a traceparent in its _meta: that’s how an MCP client sends its trace along. When standard input closes, the session ends and the server stops.
What it prints
Section titled “What it prints”The server’s answers go to standard output, for the client. Its log lines go to standard error:
{"timestamp":"2026-11-27T16:32:39.803275Z","level":"INFO","target":"oxtel","message":"log lines: standard error, as JSON; traces, metrics and logs: not exported (set OTEL_EXPORTER_OTLP_ENDPOINT to send them to a collector)"}{"timestamp":"2026-11-27T16:32:39.806782Z","level":"INFO","target":"mcp_stdio","message":"adding","trace_id":"4bf92f3577b34da6a3ce929d0e0e4736","span_id":"e3ceeef7d45f7a5c","mcp.method.name":"tools/call","jsonrpc.request.id":"3","mcp.protocol.version":"2025-11-25","gen_ai.tool.name":"add","gen_ai.operation.name":"execute_tool","network.transport":"pipe","a":2,"b":3}2026-11-27T16:32:40.210552Z INFO oxtel: log lines: standard error, as text; traces, metrics and logs: not exported (set OTEL_EXPORTER_OTLP_ENDPOINT to send them to a collector)2026-11-27T16:32:40.213703Z INFO tools/call add: mcp_stdio: adding a=2 b=3 trace_id=4bf92f3577b34da6a3ce929d0e0e4736 span_id=03e420669a7a3fc7- The line from
addhas the trace id the client sent,4bf92f3577b34da6a3ce929d0e0e4736. The server’s span continues the client’s trace, so a backend shows the tool’s work inside the client’s call. - In JSON, the line also carries the request’s fields: the method, the tool, the protocol version and
network.transport. - The other requests wrote no log lines, but each still got a span:
initialize,notifications/initializedandtools/list, each a trace of its own, since they didn’t carry the client’s. - rmcp’s own lines aren’t there: the program keeps rmcp to its warnings, as For production explains.
- Over HTTP, the server is wrapped differently: an MCP server over HTTP shows how.
CI runs the example with this session and checks it still prints these lines.
What’s recorded
Section titled “What’s recorded”The names follow the OpenTelemetry conventions for MCP, which are still in development.
| Span name | The method, and the tool, prompt or resource it’s for, such as tools/call add |
mcp.method.name | tools/call |
jsonrpc.request.id | The request’s id; notifications have none |
mcp.protocol.version | The protocol version the session agreed on |
gen_ai.tool.name | For a tool call, the tool, with gen_ai.operation.name set to execute_tool |
network.transport | pipe, from with_transport("pipe") |
error.type | tool_error when a tool reports a failure, or the JSON-RPC error code when the server fails |
mcp.server.operation.duration | A histogram of each request’s duration in seconds |
mcp.server.session.duration | The session’s duration in seconds, when it ends |
Tool arguments and results aren’t recorded, since they may hold personal or secret data. .with_payloads(true) records them, cut at 16 KiB, as gen_ai.tool.call.arguments and gen_ai.tool.call.result.
For production
Section titled “For production”- Keep standard output for the protocol. Don’t set
OXTEL_LOG_OUTPUT=stdout, and don’t turn on the console exporters, such asOTEL_TRACES_EXPORTER=console: they print on standard output, and the client would try to read what they print as protocol messages. - Configure it in the client. The client starts the server, so the server’s environment comes from the client’s settings for it. Set
OTEL_EXPORTER_OTLP_ENDPOINTandOTEL_SERVICE_NAMEthere. Many clients keep what the server writes to standard error in a log of their own. - Keep rmcp to its warnings. rmcp logs each session’s start and end at
info, with everything the client said about itself, in a span of its own that lasts the whole session. The example keeps rmcp to its warnings unlessRUST_LOGis set; if you setRUST_LOG, includermcp=warn. - Let the session end. The server stops when the client closes its standard input, and
mainreturning sends what’s left. A client that kills the server instead loses what hasn’t been sent yet, the last few seconds. - Callers’ trace ids. The server continues any trace a client sends. For a server that untrusted clients reach,
.with_propagation(false)starts a new trace for every request instead.