An MCP server over HTTP
An MCP server that clients reach over the network with MCP’s streamable HTTP transport, mounted in an axum app. 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; - the session’s id, the protocol version and the transport, on that span and on every log line the tool writes;
- its duration in
mcp.server.operation.duration.
The client is instrumented too. oxtel_rmcp::client::call_tool makes the call in a client span of its own and sends the trace along in _meta, so one trace runs from the client’s work into the tool. Here the server and client are in one program, which calls its own server once and stops, so one command shows both sides.
The code
Section titled “The code”use std::sync::Arc;
use rmcp::handler::server::wrapper::Parameters;use rmcp::model::CallToolRequestParams;use rmcp::transport::streamable_http_server::session::local::LocalSessionManager;use rmcp::transport::{StreamableHttpClientTransport, StreamableHttpService};use rmcp::{ServiceExt, tool, tool_router};use tracing::Instrument;
/// 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 spans 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()?;
// A server for each session, each instrumented. rmcp's HTTP server takes // a handler, so it's InstrumentedHandler rather than Instrumented. let mcp = StreamableHttpService::new( || Ok(oxtel_rmcp::InstrumentedHandler::new(Calculator)), Arc::new(LocalSessionManager::default()), Default::default(), ); let app = axum::Router::new().nest_service("/mcp", mcp); let listener = tokio::net::TcpListener::bind("127.0.0.1:3003").await?; let server = tokio::spawn(async move { axum::serve(listener, app).await });
let transport = StreamableHttpClientTransport::from_uri("http://127.0.0.1:3003/mcp"); let client = ().serve(transport).await?; // The client's own work, in a span of its own: the tool call is part of // its trace, on both sides. async { let mut call = CallToolRequestParams::new("add"); call.arguments = serde_json::json!({ "a": 2, "b": 3 }).as_object().cloned(); let result = oxtel_rmcp::client::call_tool(client.peer(), call, Default::default()).await?; let answer = result.content.first().and_then(|c| c.as_text()); tracing::info!(answer = answer.map(|t| t.text.as_str()), "answered"); Ok::<_, Box<dyn std::error::Error>>(()) } .instrument(tracing::info_span!("ask")) .await?; client.cancel().await?;
server.abort(); Ok(())}rmcp’s HTTP server takes a ServerHandler, the trait the tools are written against, rather than a service. So the server is wrapped in InstrumentedHandler, not the Instrumented that the stdio server uses. Both record the same spans and metrics. InstrumentedHandler is new in oxtel-rmcp 0.4.1.
Dependencies
Section titled “Dependencies”[dependencies]oxtel = "0.4"# 0.4.1 for InstrumentedHandler; `client` for the client's side, which a# server alone doesn't need.oxtel-rmcp = { version = "0.4.1", features = ["client"] }# The HTTP server, then the client.rmcp = { version = "3.5", features = ["transport-streamable-http-server", "client", "transport-streamable-http-client-reqwest"] }axum = "0.8"schemars = "1"serde = { version = "1", features = ["derive"] }serde_json = "1"tokio = { version = "1", features = ["macros", "rt-multi-thread"] }tracing = "0.1"Run it
Section titled “Run it”From a checkout of the repository:
cargo run -p oxtel-examples --example mcp-httpOTEL_TRACES_EXPORTER=console cargo run -p oxtel-examples --example mcp-http # and the spansWhat it prints
Section titled “What it prints”The log lines of the server’s tool and of the client:
{"timestamp":"2026-11-27T17:41:32.667921Z","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-27T17:41:32.677405Z","level":"INFO","target":"mcp_http","message":"adding","trace_id":"bb466783fe483b2164e0aa8f1df3c9ef","span_id":"17e5283db9c8e3f8","mcp.method.name":"tools/call","jsonrpc.request.id":"1","mcp.session.id":"a1f1bf39-d542-49aa-887a-dab25948729c","mcp.protocol.version":"2025-11-25","gen_ai.tool.name":"add","gen_ai.operation.name":"execute_tool","network.transport":"tcp","network.protocol.name":"http","network.protocol.version":"1.1","a":2,"b":3}{"timestamp":"2026-11-27T17:41:32.677891Z","level":"INFO","target":"mcp_http","message":"answered","trace_id":"bb466783fe483b2164e0aa8f1df3c9ef","span_id":"a47a99adb8243a56","answer":"5"}2026-11-27T17:41:33.929306Z 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-27T17:41:33.938527Z INFO tools/call add: mcp_http: adding a=2 b=3 trace_id=c30b0f19d5045847b86e78ec27be742e span_id=1eedaf36a339a4082026-11-27T17:41:33.938901Z INFO ask: mcp_http: answered answer=5 trace_id=c30b0f19d5045847b86e78ec27be742e span_id=61c0ef3108086d03- The tool’s line and the client’s
answeredline have the same trace id. The client’s work, its call and the server’s work on it are one trace. - In JSON, the tool’s line also carries the session’s id,
mcp.session.id, and the transport:tcp, with HTTP 1.1.
With OTEL_TRACES_EXPORTER=console, as in the second command above, the spans are printed on standard output as they end:
2026-11-27T17:41:33.301867Z span "initialize" kind=server status=unset duration=0.109ms trace_id=eafea366eb2d1afa99d85651883df52c span_id=0514a8a29e40bd64 mcp.method.name=initialize jsonrpc.request.id=0 mcp.protocol.version=2025-11-25 network.transport=tcp network.protocol.name=http network.protocol.version=1.12026-11-27T17:41:33.303362Z span "notifications/initialized" kind=server status=unset duration=0.028ms trace_id=c32a9cadbfedd4614871e094d884cd22 span_id=4dff41d4327336d7 mcp.method.name=notifications/initialized mcp.session.id=f54419bd-1586-4b7d-93e9-5ec51507f5be mcp.protocol.version=2025-11-25 network.transport=tcp network.protocol.name=http network.protocol.version=1.12026-11-27T17:41:33.304143Z span "tools/call add" kind=server status=unset duration=0.238ms trace_id=0055982e25b301244cb769eef33c7739 span_id=5c655e80fee5614f parent_id=cc8dfac4abfd2e96 mcp.method.name=tools/call jsonrpc.request.id=1 mcp.session.id=f54419bd-1586-4b7d-93e9-5ec51507f5be mcp.protocol.version=2025-11-25 gen_ai.tool.name=add gen_ai.operation.name=execute_tool network.transport=tcp network.protocol.name=http network.protocol.version=1.1 event="adding"2026-11-27T17:41:33.303449Z span "tools/call add" kind=client status=unset duration=1.325ms trace_id=0055982e25b301244cb769eef33c7739 span_id=cc8dfac4abfd2e96 parent_id=d7df9a94e391e004 mcp.method.name=tools/call mcp.protocol.version=2025-11-25 gen_ai.tool.name=add gen_ai.operation.name=execute_tool2026-11-27T17:41:33.303377Z span "ask" kind=internal status=unset duration=1.433ms trace_id=0055982e25b301244cb769eef33c7739 span_id=d7df9a94e391e004 event="answered"- The server’s
tools/call addhas the client’stools/call addas its parent, and that hasask. That’s the chain a backend draws as a tree. initializeandnotifications/initializedare each a trace of their own, since they don’t carry a trace of the client’s.initializehas no session id, since the server starts the session while answering it.- Both sides record the protocol version they agreed on.
CI runs the example both ways 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, on both sides |
mcp.method.name | tools/call |
jsonrpc.request.id | The request’s id, on the server’s span; notifications have none |
mcp.session.id | The session the request belongs to, on the server’s span |
mcp.protocol.version | The protocol version the client and server agreed on |
gen_ai.tool.name | For a tool call, the tool, with gen_ai.operation.name set to execute_tool |
network.transport, network.protocol.name, network.protocol.version | tcp, http and the HTTP version, on the server’s span |
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, on the server |
mcp.server.session.duration | Each session’s duration in seconds, when it ends |
mcp.client.operation.duration | A histogram of each call’s duration in seconds, on the client |
Tool arguments and results aren’t recorded, since they may hold personal or secret data. On the server, .with_payloads(true) records them; on the client, ClientOptions { payloads: true, ..Default::default() } in place of Default::default().
For production
Section titled “For production”- Run it until it’s stopped, and stop gracefully, as in a web service, so the last requests’ telemetry is sent.
- Allow your host name. rmcp’s HTTP server accepts only requests addressed to
localhost,127.0.0.1or::1unless told otherwise, which guards against DNS rebinding. Behind a domain, pass aStreamableHttpServerConfigwithwith_allowed_hostsnaming it. - Keep rmcp to its warnings. rmcp logs every session’s start and end at
info, with everything the client said about itself, in spans of its own. The example keeps rmcp to its warnings unlessRUST_LOGis set; if you setRUST_LOG, includermcp=warn. - 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. - What isn’t recorded.
InstrumentedHandlersees a request once rmcp hands it to the server’s code. A request rmcp turns away itself, such as one for a protocol version the server doesn’t support, gets no span.