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
5 changes: 5 additions & 0 deletions hugo/config/_default/menus/main.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,11 @@ menu:
identifier: mcp_server_tools
parent: mcp_server
weight: 2
- name: Code Execution
url: mcp_server/code_execution
identifier: mcp_server_code_execution
parent: mcp_server
weight: 3
- name: Partners
url: partners/
pre: colab
Expand Down
3 changes: 3 additions & 0 deletions hugo/content/en/mcp_server/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ further_reading:
- link: "mcp_server/tools"
tag: "Documentation"
text: "Datadog MCP Server Tools"
- link: "mcp_server/code_execution"
tag: "Documentation"
text: "Code Execution"
- link: "bits_ai/"
tag: "Documentation"
text: "Bits AI Overview"
Expand Down
77 changes: 77 additions & 0 deletions hugo/content/en/mcp_server/code_execution.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: Code Execution
description: "Run agent-authored JavaScript against Datadog APIs in a single MCP tool call to investigate issues that span multiple Datadog products."
algolia:
tags: ["mcp", "mcp server", "code execution", "code-exec"]
rank: 65
further_reading:
- link: "mcp_server"
tag: "Documentation"
text: "Datadog MCP Server"
- link: "mcp_server/setup"
tag: "Documentation"
text: "Set Up the Datadog MCP Server"
- link: "mcp_server/tools"
tag: "Documentation"
text: "Datadog MCP Server Tools"
---

## Overview

The `code-exec` toolset lets your AI agent write and run JavaScript against Datadog APIs in a single MCP tool call, instead of one tool call per API request. The agent's generated code runs inside a Datadog-managed sandbox. Only the value the code returns is sent back to the agent. This keeps large API responses out of the model's context.

Use code execution for investigations that span multiple Datadog products, or that need the agent to join, filter, or summarize data from several calls. An example is correlating error logs with APM latency for the same service and time window.

## Why use code execution

Without code execution, an agent that wants to enrich the top error-generating services with APM latency data needs a separate tool call for each service. It also needs additional turns to combine the results. Each of those calls and turns consumes context window space.

With code execution, the agent expresses the same investigation as a single script:

1. Query logs for the services with the most error logs in a time window.
1. For each returned service, query spans for latency data.
1. Join the two result sets and return a compact object.

The MCP Server runs the script and returns only the joined result. The agent completes the investigation in one tool call instead of one call per service.

## Available tools

The `code-exec` toolset provides:

- **`execute_code`**: Runs agent-authored JavaScript in the sandbox and returns a structured result. See [`execute_code`][1] in the MCP Server Tools reference for permissions and example prompts.
- **`search_datadog_sdk`**: Looks up the SDK functions and API methods available to the agent for writing scripts. See [`search_datadog_sdk`][2] in the MCP Server Tools reference.

Generated code is JavaScript based on the public [Datadog API Client for TypeScript][3].

## What the sandbox can access

Code executed by the `code-exec` toolset runs against Datadog APIs using your own user identity. An agent can only read data that you already have access to:

- The sandbox is isolated. Scripts can't access your local machine, file system, arbitrary network destinations, or raw Datadog credentials.
- The sandbox only exposes read-only Datadog API calls. An agent can't use `execute_code` to perform write actions, such as creating a monitor or updating a dashboard.
- API calls made from a script apply your existing [role permissions][4]. If you don't have access to a dataset, the agent can't query it through `execute_code` either.
- Raw API responses stay inside the sandbox while the script processes them. Only the value the script returns is sent to the agent. Review what a script returns if the underlying data is sensitive, such as customer data stored in logs.

## Enable code execution

To enable code execution, include `code-exec` in the `toolsets` query parameter when you connect your AI client to the Datadog MCP Server. See [Set Up the Datadog MCP Server][5] for client-specific connection instructions.

{{< site-region region="us,us3,us5,eu,ap1,ap2,uk1" >}}
For example, based on your selected [Datadog site][6] ({{< region-param key="dd_site_name" >}}), this URL enables the core toolset alongside code execution:

<pre><code>{{< region-param key="mcp_server_endpoint" >}}?toolsets=core,code-exec</code></pre>

`code-exec` is included in `toolsets=all`, so you don't need to add it separately if you already enable all generally available toolsets.

[6]: /getting_started/site/
{{< /site-region >}}

## Further reading

{{< partial name="whats-next/whats-next.html" >}}

[1]: /mcp_server/tools/#execute_code
[2]: /mcp_server/tools/#search_datadog_sdk
[3]: https://github.com/DataDog/datadog-api-client-typescript
[4]: /account_management/rbac/permissions/
[5]: /mcp_server/setup
8 changes: 6 additions & 2 deletions hugo/content/en/mcp_server/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ further_reading:
- link: "mcp_server/tools"
tag: "Documentation"
text: "Datadog MCP Server Tools"
- link: "mcp_server/code_execution"
tag: "Documentation"
text: "Code Execution"
- link: "https://www.datadoghq.com/blog/kubernetes-mcp-tools/"
tag: "Blog"
text: "Investigate Kubernetes resources with Datadog MCP tools"
Expand Down Expand Up @@ -710,7 +713,7 @@ These toolsets are generally available. See [Datadog MCP Server Tools][49] for a
- `core`: The default toolset for logs, metrics, traces, dashboards, monitors, incidents, hosts, services, events, and notebooks
- `alerting`: Tools for validating and creating monitors, searching monitor groups, retrieving monitor templates, analyzing monitor coverage, and searching SLOs
- `audit-trail`: Tools for [Audit Trail][70], including searching and retrieving Audit Trail events and forming Audit Trail search queries
- `code-exec`: A single tool that runs agent-authored TypeScript in a Datadog-managed sandbox with direct access to Datadog APIs, for multi-signal investigation and ad-hoc data exploration in one call
- `code-exec`: A single tool that runs agent-authored TypeScript in a Datadog-managed sandbox with direct access to Datadog APIs, for multi-signal investigation and ad-hoc data exploration in one call. See [Code Execution][73] for more information.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we're referring to the toolset here, should we avoid calling it "a single tool"?

- `cost`: Tools for [Cloud Cost Management][63], including listing cost-saving recommendations ranked by estimated potential daily savings
- `dashboards`: Tools for retrieving, creating, updating, and deleting [dashboards][46], plus widget schema reference and validation
- `data-observability`: Tools for [Data Observability][69], including data catalog search, lineage analysis, data quality monitoring, and cost and performance recommendations for data warehouses and Spark jobs
Expand Down Expand Up @@ -996,4 +999,5 @@ Local authentication is recommended for Cline and when remote authentication is
[69]: /data_observability/
[70]: /account_management/audit_trail/
[71]: https://x.ai/build
[72]: https://github.com/xai-org/plugin-marketplace
[72]: https://github.com/xai-org/plugin-marketplace
[73]: /mcp_server/code_execution/
15 changes: 14 additions & 1 deletion hugo/content/en/mcp_server/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ further_reading:
- link: "mcp_server/setup"
tag: "Documentation"
text: "Set Up the Datadog MCP Server"
- link: "mcp_server/code_execution"
tag: "Documentation"
text: "Code Execution"
- link: "https://www.datadoghq.com/blog/datadog-mcp-apps/"
tag: "Blog"
text: "Datadog MCP Apps: Interactive experiences in AI workflows"
Expand Down Expand Up @@ -500,7 +503,7 @@ Lists an organization's Cloud Cost Management cost-saving recommendations, ranke

## Code Execution

A single tool that runs agent-authored TypeScript in a Datadog-managed sandbox with direct access to Datadog APIs, for multi-signal investigation and ad-hoc data exploration in one call.
A single tool that runs agent-authored TypeScript in a Datadog-managed sandbox with direct access to Datadog APIs, for multi-signal investigation and ad-hoc data exploration in one call. See [Code Execution][74] for more information on how this toolset works and when to use it.

Code executed by this toolset runs against your Datadog APIs using your own user identity. The sandbox applies your existing [role permissions][56] to every API call, so an agent can only read or modify data that you can already access in Datadog.

Expand All @@ -513,6 +516,15 @@ Executes AI agent-authored TypeScript in a Datadog-managed sandbox. The code rec
- Compare error-span counts, monitor alerts, and config changes for the `payments` service over the last day, and identify anything that moved at the same time.
- For `auth-service`, correlate the top error patterns in logs with CPU and memory metrics from the last hour to see whether errors track resource pressure.

### `search_datadog_sdk`
*Toolset: **code-exec***\
*Permissions Required: None*\
Looks up the SDK functions, types, and API methods available for writing `execute_code` scripts. Call this before writing a script to confirm which methods exist and their signatures.

- What SDK methods are available for querying logs in a script?
- Show me the available methods for aggregating spans.
- What does the `dd.time` namespace provide?

## Dashboards

Tools for retrieving, creating, updating, and deleting [dashboards][46], plus widget schema reference and validation.
Expand Down Expand Up @@ -2511,6 +2523,7 @@ Cancels a running workflow execution instance. Invoke this tool only when the us
[71]: /account_management/audit_trail/
[72]: /actions/forms/
[73]: /real_user_monitoring/operations_monitoring/
[74]: /mcp_server/code_execution/

## Further reading

Expand Down
Loading