Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -537,17 +537,36 @@ The Model Context Protocol (MCP) integration instruments client and server tool

### Traced methods

The MCP integration instruments the following methods:
The MCP integration instruments both MCP clients and servers.

#### MCP clients

The MCP client-side instrumentation records client tool calls.

- [Client Tool Calls][2]:
- `mcp.client.session.ClientSession.call_tool`

- [Server Tool Calls][3]:
- `mcp.server.fastmcp.tools.tool_manager.ToolManager.call_tool`
#### MCP servers

The MCP server-side integration instruments [`initialize`][3] and [`tools/call`][4] MCP methods. [`tools/list`][5] calls are optionally intercepted when intent capture is enabled.

The following tags are recorded on server spans:
- `mcp_method`: The MCP method called.
- `mcp_session_id`: The MCP [session ID][6], recorded when available in the request.
- `client_name`: The name of the client as provided to `initialize`.
- `client_version`: The version of the client as provided to `initialize`.

- Server methods instrumented:
- `mcp.server.shared.session.RequestResponder.__enter__`
- `mcp.server.shared.session.RequestResponder.__exit__`
- `mcp.server.shared.session.RequestResponder.respond`

[1]: https://modelcontextprotocol.io/docs/getting-started/intro
[2]: https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file#writing-mcp-clients
[3]: https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file#tools
[3]: https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization
[4]: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#calling-tools
[5]: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#listing-tools
[6]: https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#session-management
{{% /tab %}}

{{% tab "Node.js" %}}
Expand Down
35 changes: 35 additions & 0 deletions content/en/llm_observability/instrumentation/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ DD_LLMOBS_ML_APP=<YOUR_ML_APP_NAME> ddtrace-run <YOUR_APP_STARTUP_COMMAND>
<br />Your Datadog API key. Only required if you are not using the Datadog Agent.

[1]: /getting_started/tagging/unified_service_tagging?tab=kubernetes#non-containerized-environment

`DD_MCP_CAPTURE_INTENT`
: optional - _integer or string_ - **default**: `false`
<br />When set to `1` or `true`, adds an argument to every MCP tool requesting that the calling model describe why it chose to call the tool. The intent is recorded on the tool span.
{{% /tab %}}

{{% tab "Node.js" %}}
Expand Down Expand Up @@ -224,6 +228,10 @@ LLMObs.enable(
: optional - _string_
<br />The name of the service used for your application. If not provided, this defaults to the value of `DD_SERVICE`.

`capture_intent`
: optional - _boolean_ - **default**: `false`
<br />When set to `True`, adds an argument to every MCP tool requesting that the calling model describe why it chose to call the tool. The intent is recorded on the tool span. If not provided, this defaults to the value of `DD_MCP_CAPTURE_INTENT`.

[1]: /llm_observability/instrumentation/auto_instrumentation/
{{% /tab %}}

Expand Down Expand Up @@ -1957,6 +1965,33 @@ The versioning system works as follows:

This gives you the flexibility to either rely on automatic version management based on template content changes, or maintain full control over versioning with your own version labels.

## MCP intent capture

To gain insight into why your MCP tools were called, enable intent capture. When enabled, the SDK adds an argument to every MCP tool requesting that the calling model describe why it chose to call the tool. The intent is recorded on the tool span, helping you improve your tool definitions and descriptions.

{{< tabs >}}
{{% tab "Python" %}}

Enable MCP intent capture with the `DD_MCP_CAPTURE_INTENT` environment variable:

{{< code-block lang="shell" >}}
DD_MCP_CAPTURE_INTENT=1 DD_SITE=<YOUR_DATADOG_SITE> DD_API_KEY=<YOUR_API_KEY> DD_LLMOBS_ENABLED=1 \
DD_LLMOBS_ML_APP=<YOUR_ML_APP_NAME> ddtrace-run <YOUR_APP_STARTUP_COMMAND>
{{< /code-block >}}

Or, enable it programmatically with the `capture_intent` parameter on `LLMObs.enable()`:

{{< code-block lang="python" >}}
from ddtrace.llmobs import LLMObs
LLMObs.enable(
ml_app="<YOUR_ML_APP_NAME>",
capture_intent=True,
)
{{< /code-block >}}

{{% /tab %}}
{{< /tabs >}}

## Cost monitoring
Attach token metrics (for automatic cost tracking) or cost metrics (for manual cost tracking) to your LLM/embedding spans. Token metrics allow Datadog to calculate costs using provider pricing, while cost metrics let you supply your own pricing when using custom or unsupported models. For more details, see [Costs][14].

Expand Down
Loading