Skip to content

Commit 8fa4641

Browse files
Add Node.js MCP client auto-instrumentation docs (#37638)
* Add Node.js MCP client auto-instrumentation docs Document the dd-trace-js MCP client integration (@modelcontextprotocol/sdk, shipped in dd-trace 5.99.0): - Add a Node.js tab to the MCP auto-instrumentation section in mcp_client.md - Add MCP to the Node.js supported frameworks table in auto_instrumentation.md - Add a Node.js tab to the MCP integration reference (package and integration names, traced client methods) Covers client-side tracing only; server-side support is not yet available. * Chores: fix whitespace * Update Node MCP link in auto_instrumentation.md * Fix Node.js MCP run command and link to SDK setup guide - Correct the Node.js run command to invoke node explicitly (NODE_OPTIONS="--import dd-trace/initialize.mjs" node <YOUR_APP_ENTRYPOINT>) in both the auto-instrumentation and manual sections, for parity with the existing Agent Observability instrumentation guides - Add a link to the Agent Observability SDK setup guide at the end of each auto-instrumentation tab for additional configuration options * chore: use reference-style links for MCP setup guide Match the reference-link convention used elsewhere in the docs by defining the setup guide links per-tab instead of inline. --------- Co-authored-by: Janine Chan <janine.chan@datadoghq.com>
1 parent b56bacd commit 8fa4641

2 files changed

Lines changed: 93 additions & 33 deletions

File tree

content/en/llm_observability/instrumentation/auto_instrumentation.md

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Agent Observability can automatically trace and annotate calls to supported LLM
5656
| [Amazon Bedrock](#amazon-bedrock) | >= 3.422.0 | >= 5.35.0 (CJS), >=5.35.0 (ESM) |
5757
| [Anthropic](#anthropic) | >= 0.14.0 | >= 5.71.0 (CJS), >=5.71.0 (ESM) |
5858
| [LangChain](#langchain) | >= 0.1.0 | >= 5.32.0 (CJS), >=5.38.0 (ESM) |
59+
| [MCP](#mcp) | >= 1.27.1 | >= 5.99.0 (CJS), >=5.99.0 (ESM) |
5960
| [OpenAI](#openai), [Azure OpenAI](#openai) | >= 3.0.0 | >= 4.49.0, >= 5.25.0 (CJS), >= 5.38.0 (ESM) |
6061
| [Vercel AI SDK](#vercel-ai-sdk) | >=4.0.0 | >= 5.63.0 (CJS), >=5.63.0 (ESM) |
6162
| [VertexAI](#vertex-ai) | >= 1.0.0 | >= 5.44.0 (CJS), >=5.44.0 (ESM) |
@@ -129,7 +130,7 @@ Datadog's LLM integrations capture latency, errors, input parameters, input and
129130
{{% tab "Python" %}}
130131
The [Amazon Bedrock integration][1] provides automatic instrumentation for the Amazon Bedrock Runtime Python SDK's chat model calls (using [Boto3][2]/[Botocore][3]).
131132

132-
**Package name:** `boto3`
133+
**Package name:** `boto3`\
133134
**Integration name:** `botocore`
134135

135136
### Traced methods
@@ -159,7 +160,7 @@ The Amazon Bedrock integration instruments the following methods:
159160
{{% tab "Node.js" %}}
160161
The [Amazon Bedrock integration][1] provides automatic tracing for the Amazon Bedrock Runtime Node.js SDK's chat model calls (using [BedrockRuntimeClient][2]).
161162

162-
**Package name:** `@aws-sdk/client-bedrock-runtime`
163+
**Package name:** `@aws-sdk/client-bedrock-runtime`\
163164
**Integration name:** `aws-sdk`
164165

165166
### Traced methods
@@ -183,7 +184,7 @@ The Amazon Bedrock integration instruments the following methods:
183184
{{% tab "Python" %}}
184185
The Amazon Bedrock Agents integration provides automatic tracing for the Amazon Bedrock Agents Runtime Python SDK's agent invoke calls (using [Boto3][1]/[Botocore][2]).
185186

186-
**Package name:** `boto3`
187+
**Package name:** `boto3`\
187188
**Integration name:** `botocore`
188189

189190
### Traced methods
@@ -208,7 +209,7 @@ tracing intra-agent steps, you must set <code>enableTrace=True</code> in the <co
208209
{{% tab "Python" %}}
209210
The [Anthropic integration][1] provides automatic tracing for the [Anthropic Python SDK's][2] chat message calls.
210211

211-
**Package name:** `anthropic`
212+
**Package name:** `anthropic`\
212213
**Integration name:** `anthropic`
213214

214215
### Traced methods
@@ -229,7 +230,7 @@ The Anthropic integration instruments the following methods:
229230
{{% tab "Node.js" %}}
230231
The [Anthropic integration][1] provides automatic tracing for the [Anthropic Node.js SDK's][2] chat message calls.
231232

232-
**Package name:** `@anthropic-ai/sdk`
233+
**Package name:** `@anthropic-ai/sdk`\
233234
**Integration name:** `anthropic`
234235

235236
### Traced methods
@@ -254,7 +255,7 @@ The Anthropic integration instruments the following methods:
254255
{{% tab "Python" %}}
255256
The Claude Agent SDK integration provides automatic tracing for agent queries made through the [Claude Agent SDK for Python][1].
256257

257-
**Package name:** `claude-agent-sdk`
258+
**Package name:** `claude-agent-sdk`\
258259
**Integration name:** `claude_agent_sdk`
259260

260261
### Traced methods
@@ -278,7 +279,7 @@ The Claude Agent SDK integration instruments the following methods:
278279
{{% tab "Python" %}}
279280
The [CrewAI integration][1] automatically traces execution of Crew kickoffs, including task/agent/tool invocations, made through [CrewAI's Python SDK][2].
280281

281-
**Package name:** `crewai`
282+
**Package name:** `crewai`\
282283
**Integration name:** `crewai`
283284

284285
### Traced methods
@@ -316,7 +317,7 @@ The CrewAI integration instruments the following methods:
316317
{{% tab "Python" %}}
317318
The Google ADK integration provides automatic tracing for agent runs, tool calls, and code executions made through [Google's ADK Python SDK][1].
318319

319-
**Package name:** `google-adk`
320+
**Package name:** `google-adk`\
320321
**Integration name:** `google_adk`
321322

322323
### Traced methods
@@ -342,7 +343,7 @@ Both `run_live` and `run_async` methods are supported.
342343
{{% tab "Python" %}}
343344
The Google GenAI integration automatically traces methods in the [Google GenAI Python SDK][1].
344345

345-
**Package name:** `google-genai`
346+
**Package name:** `google-genai`\
346347
**Integration name:** `google_genai`
347348

348349
**Note:** The [Google GenAI Python SDK][1] succeeds the Google GenerativeAI SDK, and exposes both Gemini Developer API as well as Vertex.
@@ -367,7 +368,7 @@ The Google GenAI integration automatically traces methods in the [Google GenAI N
367368

368369
**Note:** The [Google GenAI Node.js SDK][1] succeeds the [Google GenerativeAI SDK][6], and exposes both Gemini Developer API as well as Vertex.
369370

370-
**Package name:** `@google/genai`
371+
**Package name:** `@google/genai`\
371372
**Integration name:** `google-genai`
372373

373374
### Traced methods
@@ -392,7 +393,7 @@ The Google GenAI integration instruments the following methods:
392393
{{% tab "Python" %}}
393394
The [LangChain integration][1] provides automatic tracing for the [LangChain Python SDK's][2] LLM, chat model, and chain calls.
394395

395-
**Package name:** `langchain`, `langchain_openai`, `langchain_anthropic`, and [other langchain partner packages][10]
396+
**Package name:** `langchain`, `langchain_openai`, `langchain_anthropic`, and [other langchain partner packages][10]\
396397
**Integration name:** `langchain`
397398

398399
### Traced methods
@@ -441,7 +442,7 @@ The LangChain integration instruments the following methods:
441442
{{% tab "Node.js" %}}
442443
The [LangChain integration][1] provides automatic tracing for the [LangChain Node.js SDK's][2] LLM, chat model, chain, and OpenAI embeddings calls.
443444

444-
**Package name:** `langchain`, `@langchain/openai`, `@langchain/anthropic`, and [other langchain partner packages][7]
445+
**Package name:** `langchain`, `@langchain/openai`, `@langchain/anthropic`, and [other langchain partner packages][7]\
445446
**Integration name:** `langchain`
446447

447448
### Traced methods
@@ -475,7 +476,7 @@ The LangChain integration instruments the following methods:
475476
{{% tab "Python" %}}
476477
The LangGraph integration automatically traces `Pregel/CompiledGraph` and `RunnableSeq (node)` invocations made through the [LangGraph Python SDK][1].
477478

478-
**Package name:** `langgraph`
479+
**Package name:** `langgraph`\
479480
**Integration name:** `langgraph`
480481

481482
### Traced methods
@@ -497,7 +498,7 @@ The LangGraph integration instruments synchronous and asynchronous versions of t
497498
{{% tab "Python" %}}
498499
The [LiteLLM integration][1] provides automatic tracing for the [LiteLLM Python SDK][2] and [proxy server router methods][3].
499500

500-
**Package name:** `litellm`
501+
**Package name:** `litellm`\
501502
**Integration name:** `litellm`
502503

503504
### Traced methods
@@ -531,7 +532,7 @@ The LiteLLM integration instruments the following methods:
531532
{{% tab "Python" %}}
532533
The Model Context Protocol (MCP) integration instruments client and server tool calls in the [MCP][1] SDK.
533534

534-
**Package name:** `mcp`
535+
**Package name:** `mcp`\
535536
**Integration name:** `mcp`
536537

537538
### Traced methods
@@ -548,6 +549,24 @@ The MCP integration instruments the following methods:
548549
[2]: https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file#writing-mcp-clients
549550
[3]: https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file#tools
550551
{{% /tab %}}
552+
553+
{{% tab "Node.js" %}}
554+
The Model Context Protocol (MCP) integration instruments client tool calls in the [MCP JavaScript SDK][1].
555+
556+
**Package name:** `@modelcontextprotocol/sdk`\
557+
**Integration name:** `modelcontextprotocol-sdk`
558+
559+
### Traced methods
560+
561+
The MCP integration instruments the following methods:
562+
563+
- [Client Tool Calls][2]:
564+
- `Client.callTool()`
565+
- `Client.listTools()`
566+
567+
[1]: https://github.com/modelcontextprotocol/typescript-sdk
568+
[2]: https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/client.md#tools
569+
{{% /tab %}}
551570
{{< /tabs >}}
552571
{{% /collapse-content %}}
553572

@@ -556,7 +575,7 @@ The MCP integration instruments the following methods:
556575
{{% tab "Python" %}}
557576
The [OpenAI integration][1] provides automatic tracing for the [OpenAI Python SDK's][2] completion and chat completion endpoints to OpenAI and Azure OpenAI.
558577

559-
**Package name:** `openai`
578+
**Package name:** `openai`\
560579
**Integration name:** `openai`
561580

562581
### Traced methods
@@ -588,7 +607,7 @@ The OpenAI integration instruments the following methods, including streamed cal
588607
{{% tab "Node.js" %}}
589608
The [OpenAI integration][1] provides automatic tracing for the [OpenAI Node.js SDK's][2] completion, chat completion, and embeddings endpoints to OpenAI and [Azure OpenAI][3].
590609

591-
**Package name:** `openai`
610+
**Package name:** `openai`\
592611
**Integration name:** `openai`
593612

594613
### Traced methods
@@ -661,7 +680,7 @@ The provider (OpenAI vs Azure OpenAI) is automatically detected based on the `ba
661680
The OpenAI Agents integration converts the [built-in tracing][1] from the [OpenAI Agents SDK][2] into
662681
Agent Observability format and sends it to Agent Observability product by adding a Datadog trace processor.
663682

664-
**Package name:** `openai-agents`
683+
**Package name:** `openai-agents`\
665684
**Integration name:** `openai_agents`
666685

667686
The following operations are supported:
@@ -693,7 +712,7 @@ The following operations are supported:
693712
{{% tab "Python" %}}
694713
The Pydantic AI integration instruments agent invocations and tool calls made using the [Pydantic AI][1] agent framework.
695714

696-
**Package name:** `pydantic-ai`
715+
**Package name:** `pydantic-ai`\
697716
**Integration name:** `pydantic_ai`
698717

699718
### Traced methods
@@ -730,7 +749,7 @@ For setup instructions and a complete example, see [OpenTelemetry Instrumentatio
730749
{{% tab "Node.js" %}}
731750
The [Vercel AI SDK][1] integration automatically traces text and object generation, embeddings, and tool calls by intercepting the OpenTelemetry spans created by the underlying core [Vercel AI SDK][2] and converting them into Agent Observability spans.
732751

733-
**Package name:** `ai`
752+
**Package name:** `ai`\
734753
**Integration name:** `ai`
735754

736755
### Traced methods
@@ -795,7 +814,7 @@ async function main () {
795814
{{% tab "Python" %}}
796815
The [Vertex AI integration][1] automatically traces content generation and chat message calls made through [Google's Vertex AI Python SDK][2].
797816

798-
**Package name:** `vertexai`
817+
**Package name:** `vertexai`\
799818
**Integration name:** `vertexai`
800819

801820
### Traced methods
@@ -819,7 +838,7 @@ The Vertex AI integration instruments the following methods:
819838
{{% tab "Node.js" %}}
820839
The [Vertex AI integration][1] automatically traces content generation and chat message calls made through [Google's Vertex AI Node.js SDK][2].
821840

822-
**Package name:** `@google-cloud/vertexai`
841+
**Package name:** `@google-cloud/vertexai`\
823842
**Integration name:** `google-cloud-vertexai`
824843

825844
### Traced methods
@@ -846,7 +865,7 @@ The Vertex AI integration instruments the following methods:
846865
{{% tab "Python" %}}
847866
The vLLM integration automatically traces request processing and token generation in the [vLLM][1] inference engine. It captures model name, input and output tokens, and latency metrics (time to first token, queue time, prefill time, decode time, and inference time).
848867

849-
**Package name:** `vllm`
868+
**Package name:** `vllm`\
850869
**Integration name:** `vllm`
851870

852871
### Traced methods

content/en/llm_observability/monitoring/mcp_client.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ further_reading:
1111

1212
You can monitor your MCP clients with Agent Observability in two ways:
1313

14-
- [Automatic instrumentation](#automatically-instrument-your-mcp-client): If you are using the official [MCP Python SDK][1]
15-
- [Manual instrumentation](#manually-instrument-your-mcp-client): If you are not using the official MCP Python SDK, or your MCP clients are written in Node.js or Java
14+
- [Automatic instrumentation](#automatically-instrument-your-mcp-client): If you are using the official [MCP Python SDK][1] or [MCP JavaScript SDK][3]
15+
- [Manual instrumentation](#manually-instrument-your-mcp-client): If you are not using an official MCP SDK, or your MCP clients are written in Java
1616

1717
## Automatically instrument your MCP client
1818

19+
{{< tabs >}}
20+
21+
{{% tab "Python" %}}
1922
If you are using the official MCP Python SDK to connect to an MCP server with an MCP client session, use the following steps to automatically instrument your MCP client application:
2023

2124
1. Install `ddtrace`:
2225

23-
{{< code-block lang="shell">}}
24-
pip install ddtrace
25-
{{< /code-block >}}
26+
```shell
27+
pip install ddtrace
28+
```
2629

2730
2. Set the required environment variables:
2831

@@ -36,9 +39,46 @@ pip install ddtrace
3639

3740
3. Run your application with the `ddtrace-run` command:
3841

39-
{{< code-block lang="shell">}}
40-
ddtrace-run <YOUR_APP_STARTUP_COMMAND>
41-
{{< /code-block >}}
42+
```shell
43+
ddtrace-run <YOUR_APP_STARTUP_COMMAND>
44+
```
45+
46+
For additional configuration options, see the [Agent Observability SDK setup guide][1].
47+
48+
[1]: /llm_observability/instrumentation/sdk?tab=python#setup
49+
{{% /tab %}}
50+
51+
{{% tab "Node.js" %}}
52+
If you are using the official MCP JavaScript SDK to connect to an MCP server with an MCP client session, use the following steps to automatically instrument your MCP client application:
53+
54+
1. Install `dd-trace`:
55+
56+
```shell
57+
npm install dd-trace
58+
```
59+
60+
2. Set the required environment variables:
61+
62+
```shell
63+
export DD_LLMOBS_ENABLED=true
64+
export DD_LLMOBS_ML_APP=<YOUR_ML_APP_NAME>
65+
export DD_LLMOBS_AGENTLESS_ENABLED=true
66+
export DD_API_KEY=<YOUR_API_KEY>
67+
export DD_SITE={{< region-param key="dd_site" >}}
68+
```
69+
70+
3. Run your application:
71+
72+
```shell
73+
NODE_OPTIONS="--import dd-trace/initialize.mjs" node <YOUR_APP_ENTRYPOINT>
74+
```
75+
76+
For additional configuration options, see the [Agent Observability SDK setup guide][1].
77+
78+
[1]: /llm_observability/instrumentation/sdk?tab=nodejs#setup
79+
{{% /tab %}}
80+
81+
{{< /tabs >}}
4282

4383
## Manually instrument your MCP client
4484

@@ -401,7 +441,7 @@ ddtrace-run <YOUR_APP_STARTUP_COMMAND>
401441

402442
{{% tab "Node.js" %}}
403443
{{< code-block lang="shell">}}
404-
NODE_OPTIONS="--import dd-trace/initialize.mjs" <YOUR_APP_STARTUP_COMMAND>
444+
NODE_OPTIONS="--import dd-trace/initialize.mjs" node <YOUR_APP_ENTRYPOINT>
405445
{{< /code-block >}}
406446
{{% /tab %}}
407447

@@ -418,4 +458,5 @@ java -javaagent:dd-java-agent.jar -Ddd.llmobs.enabled=true -Ddd.llmobs.ml-app=<Y
418458
{{< partial name="whats-next/whats-next.html" >}}
419459

420460
[1]: https://github.com/modelcontextprotocol/python-sdk
421-
[2]: /llm_observability/instrumentation/sdk
461+
[2]: /llm_observability/instrumentation/sdk
462+
[3]: https://github.com/modelcontextprotocol/typescript-sdk

0 commit comments

Comments
 (0)