Repository navigation
Closed
Description
What is the problem this feature would solve?
McpServer traces through the generic RPC tracing in RpcServer.make(..., { spanPrefix: "McpServer" }). Every JSON-RPC request gets a span like this:
// name: "McpServer.tools/call", kind: "server"
{ "rpc.system.name": "effect_rpc", "rpc.method": "tools/call" }Toolkit.handle runs inside that span without opening its own, and it adds { tool: name, parameters: params } with Effect.annotateCurrentSpan.
This has three effects:
- Backends can't recognise MCP or tool-call spans. They expect the MCP conventions, which other MCP SDK instrumentations already emit.
- Every tool call has the same span name.
McpServer.tools/calldoesn't separate one tool from another, so the tool shows up only in a non-standardtoolattribute. - Tool arguments are recorded on every span by default. That's the raw
parametersobject, which can hold user data. The conventions make arguments opt-in.
The conventions also define trace propagation through params._meta (traceparent / tracestate / baggage, see SEP-414). As far as I can tell, McpServer doesn't read those, so a client's trace isn't continued on the server.
What is the feature you are proposing to solve the problem?
Follow the OpenTelemetry semantic conventions for MCP (status: Development):
- Spec: https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/mcp.md
- Attribute registry: https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/registry/attributes/mcp.md
- (The old page at https://opentelemetry.io/docs/specs/semconv/gen-ai/mcp/ points to the repository above.)
For server spans, that means:
| Convention | |
|---|---|
| Span name | {mcp.method.name} {target}, where target is the gen_ai.tool.name or gen_ai.prompt.name; plain {mcp.method.name} otherwise. For example tools/call get_weather, initialize. Don't put mcp.resource.uri in the name by default. |
| Span kind | SERVER |
| Required | mcp.method.name |
| Conditionally required | gen_ai.tool.name (tool calls), gen_ai.prompt.name (prompts), mcp.resource.uri (resource requests), jsonrpc.request.id (requests), error.type and rpc.response.status_code (on failure; a tools/call result with isError: true sets error.type to tool_error) |
| Recommended | gen_ai.operation.name: "execute_tool" (tool calls only), mcp.protocol.version, mcp.session.id, network.transport, network.protocol.name / network.protocol.version |
| Opt-in | gen_ai.tool.call.arguments, gen_ai.tool.call.result, gen_ai.prompt.variable.<name> |
A possible shape:
McpServersets the span name andmcp.*/gen_ai.*attributes per method. Only the server knows the session id, the negotiated protocol version and the JSON-RPC id, so the user can't add these from a handler.- The
parametersannotation inToolkit.handlebecomesgen_ai.tool.call.argumentsbehind an option, off by default, e.g.McpServer.layer({ ..., tracing: { recordToolArguments: true } }). - The server extracts
traceparent/tracestate/baggagefromparams._metaand uses them as the remote parent. - Optional: the
mcp.server.operation.durationandmcp.server.session.durationmetrics from the same spec.
What alternatives have you considered?
- Annotating from tool handlers with
Effect.annotateCurrentSpan. This fixes some attributes, but not the span name, the session id, the protocol version,jsonrpc.request.id, or theparametersattribute already being recorded. - Renaming spans in an OpenTelemetry collector processor. It works, but each deployment has to redo it, and it can't add data the span doesn't carry.
Metadata
Metadata
Assignees
Labels
No labels
Activity