Skip to main content
The Model Context Protocol (MCP) is an open protocol that lets agents call tools that a server exposes. When you build an MCP server, LangSmith helps you understand how agents use your tools in production: trace each tool call, monitor usage and reliability, find failures, and evaluate tool quality. This guide shows how to trace your MCP server with the LangSmith Python or JavaScript SDK, without changing the agents that call it. To trace a server you do not own, see Trace servers you do not own.

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 a tool 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.

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 an MCPServer or a low-level mcp.server.lowlevel.Server to wrap_mcp_server. Each tool call the server runs becomes a tool run:
server.py
To trace every server in a process without wrapping each one, call 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 at http://localhost:8000/mcp:
Call a tool from any MCP client, such as your agent. This client has no tracing code:
call_tool.py

View traces in LangSmith

Open the LangSmith UI and view the traces for your agent’s environment. Each call to get_weather appears as its own trace with one tool run:
Each tool run shows:
  • Inputs and outputs: The tool arguments, and the full tool result.
  • Latency: How long the tool call took.
  • Errors: Tool results with isError set appear as errors, with the message MCP tool returned an error.
Runs from the SDK integrations carry the metadata 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 to get_weather produces this trace:

Trace your client

Pass an mcp.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
Set the 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, set distributed_tracing=True on both. The client sends its trace context in the request’s _meta field, and the server continues that trace:
With this change, the server’s 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.
The trace context includes the client’s project, tags, and metadata. Turn on distributed_tracing on a client only for servers you own. On a server, it is off by default, so a client cannot place the server’s runs in another trace or project. Turn it on only when you own the clients too.
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 as mcp 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:
Keep 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 proxy in 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