Skip to content

Commit add270d

Browse files
committed
Document MCP intent capture feature and expand MCP server instrumentation details
1 parent c92ef14 commit add270d

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

content/en/llm_observability/instrumentation/auto_instrumentation.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,17 +537,36 @@ The Model Context Protocol (MCP) integration instruments client and server tool
537537

538538
### Traced methods
539539

540-
The MCP integration instruments the following methods:
540+
The MCP integration instruments both MCP clients and servers.
541+
542+
#### MCP clients
543+
544+
The MCP client-side instrumentation records client tool calls.
541545

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

545-
- [Server Tool Calls][3]:
546-
- `mcp.server.fastmcp.tools.tool_manager.ToolManager.call_tool`
549+
#### MCP servers
550+
551+
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.
552+
553+
The following tags are recorded on server spans:
554+
- `mcp_method`: The MCP method called.
555+
- `mcp_session_id`: The MCP [session ID][6], recorded when available in the request.
556+
- `client_name`: The name of the client as provided to `initialize`.
557+
- `client_version`: The version of the client as provided to `initialize`.
558+
559+
- Server methods instrumented:
560+
- `mcp.server.shared.session.RequestResponder.__enter__`
561+
- `mcp.server.shared.session.RequestResponder.__exit__`
562+
- `mcp.server.shared.session.RequestResponder.respond`
547563

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

553572
{{% tab "Node.js" %}}

content/en/llm_observability/instrumentation/sdk.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ DD_LLMOBS_ML_APP=<YOUR_ML_APP_NAME> ddtrace-run <YOUR_APP_STARTUP_COMMAND>
9292
: optional - _string_
9393
<br />Your Datadog API key. Only required if you are not using the Datadog Agent.
9494

95-
[1]: /getting_started/tagging/unified_service_tagging?tab=kubernetes#non-containerized-environment
95+
`DD_MCP_CAPTURE_INTENT`
96+
: optional - _integer or string_ - **default**: `false`
97+
<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.
9698
{{% /tab %}}
9799

100+
[1]: /getting_started/tagging/unified_service_tagging?tab=kubernetes#non-containerized-environment
101+
98102
{{% tab "Node.js" %}}
99103
Enable Agent Observability by running your application with `NODE_OPTIONS="--import dd-trace/initialize.mjs"` and specifying the required environment variables.
100104

@@ -224,6 +228,10 @@ LLMObs.enable(
224228
: optional - _string_
225229
<br />The name of the service used for your application. If not provided, this defaults to the value of `DD_SERVICE`.
226230

231+
`capture_intent`
232+
: optional - _boolean_ - **default**: `false`
233+
<br />When set to `True`, adds an argument to every MCP server 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`.
234+
227235
[1]: /llm_observability/instrumentation/auto_instrumentation/
228236
{{% /tab %}}
229237

@@ -1957,6 +1965,33 @@ The versioning system works as follows:
19571965

19581966
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.
19591967

1968+
## MCP intent capture
1969+
1970+
To gain insight into why your MCP tools were called, enable intent capture on your MCP server. 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.
1971+
1972+
{{< tabs >}}
1973+
{{% tab "Python" %}}
1974+
1975+
Enable MCP intent capture with the `DD_MCP_CAPTURE_INTENT` environment variable:
1976+
1977+
{{< code-block lang="shell" >}}
1978+
DD_MCP_CAPTURE_INTENT=1 DD_SITE=<YOUR_DATADOG_SITE> DD_API_KEY=<YOUR_API_KEY> DD_LLMOBS_ENABLED=1 \
1979+
DD_LLMOBS_ML_APP=<YOUR_ML_APP_NAME> ddtrace-run <YOUR_APP_STARTUP_COMMAND>
1980+
{{< /code-block >}}
1981+
1982+
Or, enable it programmatically with the `capture_intent` parameter on `LLMObs.enable()`:
1983+
1984+
{{< code-block lang="python" >}}
1985+
from ddtrace.llmobs import LLMObs
1986+
LLMObs.enable(
1987+
ml_app="<YOUR_ML_APP_NAME>",
1988+
capture_intent=True,
1989+
)
1990+
{{< /code-block >}}
1991+
1992+
{{% /tab %}}
1993+
{{< /tabs >}}
1994+
19601995
## Cost monitoring
19611996
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].
19621997

0 commit comments

Comments
 (0)