Why trace your MCP server
Your MCP server is a product, and agents are its users. Tracing it shows how agents actually use it:- See every tool call: The arguments the agent sent and the result your server returned.
- Track usage and reliability: The prebuilt dashboard charts run counts, error rates, and latency for your most-called tools.
- Catch failures early: Calls that return an MCP error result are marked as errors. Set alerts on error rate or latency.
- Improve your tools: Score tool results with online evaluators as you change tool descriptions, schemas, or responses.
How it works
You add tracing to your server with the LangSmith SDK. Each tool call the server runs becomes atool run in LangSmith, whichever agent or client made the call. The agents that call your server need no changes.
Create an agent once before sending traces. Use agent addressing to select its identifier and environment. If an integration requires
project_name, use the selected environment’s tracer_session_name.Set up tracing
The SDK integrations support servers built with the MCP Python SDK and the MCP TypeScript SDK. For other MCP libraries, see Instrument tool calls manually.- Python
- JavaScript
Install the packages
Requires
langsmith>=0.16.3 and mcp>=2. configure_mcp requires langsmith>=0.16.4. For servers on mcp 1.x, upgrade to mcp>=2 or instrument tool calls manually.Configure your environment
Set these variables in the server process:Shell
Trace your server
Pass anMCPServer or a low-level mcp.server.lowlevel.Server to wrap_mcp_server. Each tool call the server runs becomes a tool run:server.py
configure_mcp once at startup instead, before you create the server:configure_mcp patches the mcp package, so every MCPServer or low-level Server created after the call is traced. It also traces each call_tool on an mcp.Client or mcp.ClientSession in the same process. It returns False when mcp>=2 is not installed.Run your server and call a tool
Start the server. It listens athttp://localhost:8000/mcp:call_tool.py
View traces in LangSmith
Open the LangSmith UI and view the traces for your agent’s environment. Each call toget_weather appears as its own trace with one tool run:
- Inputs and outputs: The tool arguments, and the full tool result.
- Latency: How long the tool call took.
- Errors: Tool results with
isErrorset appear as errors, with the messageMCP tool returned an error.
ls_integration: mcp. Filter on it to see only MCP tool calls in a project. To see trends across calls, open the environment’s prebuilt dashboard, which includes run counts, error rates, and latency for your five most-called tools.
When the server issues an MCP session ID, as a stateful streamable HTTP server can, each tool run that starts its own trace gets a thread_id derived from that session, so the session’s calls group into one thread. Calls over stdio, stateless requests, and runs that continue a client’s trace get no thread ID from the server. The example server on this page does not issue a session ID, so each call appears as a separate trace.
Advanced tracing
The setup above is all you need to trace your server. If you also own the MCP client, trace it too, and connect the client’s and the server’s runs into one trace. The client sends its trace context with each request, and the server continues the same trace, even when the two run in separate processes: With both sides traced and connected, a call toget_weather produces this trace:
- Python
- JavaScript
Trace your client
Pass anmcp.Client or mcp.ClientSession to wrap_mcp_client. Each call_tool becomes a tool run. When the call happens inside a traced function, the run nests under that function’s run:client.py
LANGSMITH_* variables from Configure your environment in the client process too.Connect client and server traces
By default, the client’s and the server’s runs land in separate traces. When you own both sides, setdistributed_tracing=True on both. The client sends its trace context in the request’s _meta field, and the server continues that trace:get_weather run appears under the client’s get_weather run, inside the weather_agent trace.configure_mcp also accepts distributed_tracing, which applies to every server and client in the process. A wrap_mcp_server or wrap_mcp_client call on top of configure_mcp records each tool call once, and its distributed_tracing setting takes precedence.If a request carries trace context that does not parse, the server ignores it and starts a new trace. The tool call still runs. For more on how LangSmith propagates trace context, see Implement distributed tracing.Instrument tool calls manually
If your server uses an MCP library the SDK integrations do not support, such asmcp 1.x, trace tool calls with traceable. Put the tool’s work in a function marked run_type="tool", and call it from the tool handler. This example uses MCPServer for illustration. The pattern is the same in any library:
traceable off the tool handler itself. It adds a config parameter to the function signature, which then appears in the tool’s input schema. For more on traceable, see Custom instrumentation.
Trace servers you do not own
The SDK integrations trace servers and clients that you run. To trace an agent’s calls to a third-party MCP server, use one of these instead:- LangSmith CLI proxy: Run
langsmith mcp proxyin front of any local or remote MCP server, with no code changes. - Tool Gateway: Agents that call MCP servers through Tool Gateway get a trace for each call. These traces record metadata only, not tool arguments or results.
See also
- Implement distributed tracing
- Custom instrumentation
- Set up alerts on tool error rate or latency
- Score tool results with online evaluators
- Trace Claude Code sessions, including the MCP tool calls the agent makes
- Trace LangChain agents, including tools loaded with
langchain-mcp-adapters
Connect these docs to your agent of choice via MCP for real-time answers.

