Skip to content

McpServer: follow the OpenTelemetry MCP semantic conventions for spans #10293

Closed

Description

@dbrxnds

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/call doesn't separate one tool from another, so the tool shows up only in a non-standard tool attribute.
  • Tool arguments are recorded on every span by default. That's the raw parameters object, 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):

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:

  • McpServer sets the span name and mcp.* / 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 parameters annotation in Toolkit.handle becomes gen_ai.tool.call.arguments behind an option, off by default, e.g. McpServer.layer({ ..., tracing: { recordToolArguments: true } }).
  • The server extracts traceparent / tracestate / baggage from params._meta and uses them as the remote parent.
  • Optional: the mcp.server.operation.duration and mcp.server.session.duration metrics 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 the parameters attribute 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.

Activity

  1. self-assigned this
    on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions