@braxtonbooth/datadog-mcp-server 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +330 -0
- package/dist/index.js +224 -0
- package/dist/tools/aggregateLogs.js +64 -0
- package/dist/tools/getDashboard.js +36 -0
- package/dist/tools/getDashboards.js +43 -0
- package/dist/tools/getEvents.js +46 -0
- package/dist/tools/getIncidents.js +58 -0
- package/dist/tools/getMetricMetadata.js +36 -0
- package/dist/tools/getMetrics.js +37 -0
- package/dist/tools/getMonitor.js +36 -0
- package/dist/tools/getMonitors.js +48 -0
- package/dist/tools/searchLogs.js +73 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 datadog-mcp-server
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
# Datadog MCP Server
|
|
2
|
+
|
|
3
|
+
> **Note:** This is an audited fork of [GeLi2001/datadog-mcp-server](https://github.com/GeLi2001/datadog-mcp-server) maintained by [@braxtonbooth](https://github.com/braxtonbooth). Security reviewed and monitored via Dependabot.
|
|
4
|
+
|
|
5
|
+
A Model Context Protocol (MCP) server for interacting with the Datadog API.
|
|
6
|
+
|
|
7
|
+
<a href="https://glama.ai/mcp/servers/@GeLi2001/datadog-mcp-server">
|
|
8
|
+
<img width="380" height="200" src="https://glama.ai/mcp/servers/@GeLi2001/datadog-mcp-server/badge" alt="Datadog MCP server" />
|
|
9
|
+
</a>
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Monitoring**: Access monitor data and configurations
|
|
14
|
+
- **Dashboards**: Retrieve and view dashboard definitions
|
|
15
|
+
- **Metrics**: Query available metrics and their metadata
|
|
16
|
+
- **Events**: Search and retrieve events within timeframes
|
|
17
|
+
- **Logs**: Search logs with advanced filtering and sorting options
|
|
18
|
+
- **Incidents**: Access incident management data
|
|
19
|
+
- **API Integration**: Direct integration with Datadog's v1 and v2 APIs
|
|
20
|
+
- **Comprehensive Error Handling**: Clear error messages for API and authentication issues
|
|
21
|
+
- **Service-Specific Endpoints**: Support for different endpoints for logs and metrics
|
|
22
|
+
|
|
23
|
+
## Prerequisites
|
|
24
|
+
|
|
25
|
+
1. Node.js (version 16 or higher)
|
|
26
|
+
2. Datadog account with:
|
|
27
|
+
- API key - Found in Organization Settings > API Keys
|
|
28
|
+
- Application key - Found in Organization Settings > Application Keys
|
|
29
|
+
|
|
30
|
+
## Application Key Scopes
|
|
31
|
+
|
|
32
|
+
For improved security, you can scope your Application Key to grant only the minimum permissions required by this MCP server. By default, Application Keys inherit all permissions from the user who created them, but [scoped Application Keys](https://docs.datadoghq.com/account_management/api-app-keys/#scopes) allow you to follow the principle of least privilege.
|
|
33
|
+
|
|
34
|
+
### Required Scopes
|
|
35
|
+
|
|
36
|
+
The following scopes are required for the corresponding features:
|
|
37
|
+
|
|
38
|
+
| Tool(s) | Required Scope | Description |
|
|
39
|
+
|---------|----------------|-------------|
|
|
40
|
+
| `get-monitors`, `get-monitor` | `monitors_read` | Read access to monitor configurations and states |
|
|
41
|
+
| `get-dashboards`, `get-dashboard` | `dashboards_read` | Read access to dashboard definitions |
|
|
42
|
+
| `get-metrics`, `get-metric-metadata` | `metrics_read` | Read access to metrics list and metadata |
|
|
43
|
+
| `get-events` | `events_read` | Read access to events from the event stream |
|
|
44
|
+
| `search-logs`, `aggregate-logs` | `logs_read_data` | Read access to log data for search and aggregation |
|
|
45
|
+
| `get-incidents` | `incident_read` | Read access to incident management data |
|
|
46
|
+
|
|
47
|
+
### Creating a Scoped Application Key
|
|
48
|
+
|
|
49
|
+
1. Go to **Organization Settings** > **Application Keys**
|
|
50
|
+
2. Click **New Key**
|
|
51
|
+
3. Enter a name (e.g., "MCP Server - Read Only")
|
|
52
|
+
4. Under **Scopes**, select only the permissions you need:
|
|
53
|
+
- For full functionality: `monitors_read`, `dashboards_read`, `metrics_read`, `events_read`, `logs_read_data`, `incident_read`
|
|
54
|
+
- For logs only: `logs_read_data`
|
|
55
|
+
- For monitoring only: `monitors_read`, `dashboards_read`, `metrics_read`
|
|
56
|
+
5. Click **Create Key**
|
|
57
|
+
|
|
58
|
+
> **Note**: If you don't specify any scopes when creating an Application Key, it will have full access with all permissions of the creating user. For production use, we recommend always specifying explicit scopes.
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
### Via npm (recommended)
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm install -g datadog-mcp-server
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### From Source
|
|
69
|
+
|
|
70
|
+
1. Clone this repository
|
|
71
|
+
2. Install dependencies:
|
|
72
|
+
```bash
|
|
73
|
+
npm install
|
|
74
|
+
```
|
|
75
|
+
3. Build the project:
|
|
76
|
+
```bash
|
|
77
|
+
npm run build
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Configuration
|
|
81
|
+
|
|
82
|
+
You can configure the Datadog MCP server using either environment variables or command-line arguments.
|
|
83
|
+
|
|
84
|
+
### Environment Variables
|
|
85
|
+
|
|
86
|
+
Create a `.env` file with your Datadog credentials:
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
DD_API_KEY=your_api_key_here
|
|
90
|
+
DD_APP_KEY=your_app_key_here
|
|
91
|
+
DD_SITE=datadoghq.com
|
|
92
|
+
DD_LOGS_SITE=datadoghq.com
|
|
93
|
+
DD_METRICS_SITE=datadoghq.com
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Note**: `DD_LOGS_SITE` and `DD_METRICS_SITE` are optional and will default to the value of `DD_SITE` if not specified.
|
|
97
|
+
|
|
98
|
+
### Command-line Arguments
|
|
99
|
+
|
|
100
|
+
Basic usage with global site setting:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
datadog-mcp-server --apiKey=your_api_key --appKey=your_app_key --site=datadoghq.eu
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Advanced usage with service-specific endpoints:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
datadog-mcp-server --apiKey=your_api_key --appKey=your_app_key --site=datadoghq.com --logsSite=logs.datadoghq.com --metricsSite=metrics.datadoghq.com
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Note: Site arguments don't need `https://` - it will be added automatically.
|
|
113
|
+
|
|
114
|
+
### Regional Endpoints
|
|
115
|
+
|
|
116
|
+
Different Datadog regions have different endpoints:
|
|
117
|
+
|
|
118
|
+
- US (Default): `datadoghq.com`
|
|
119
|
+
- EU: `datadoghq.eu`
|
|
120
|
+
- US3 (GovCloud): `ddog-gov.com`
|
|
121
|
+
- US5: `us5.datadoghq.com`
|
|
122
|
+
- AP1: `ap1.datadoghq.com`
|
|
123
|
+
|
|
124
|
+
### Usage with Claude Desktop
|
|
125
|
+
|
|
126
|
+
Add this to your `claude_desktop_config.json`:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"mcpServers": {
|
|
131
|
+
"datadog": {
|
|
132
|
+
"command": "npx",
|
|
133
|
+
"args": [
|
|
134
|
+
"datadog-mcp-server",
|
|
135
|
+
"--apiKey",
|
|
136
|
+
"<YOUR_API_KEY>",
|
|
137
|
+
"--appKey",
|
|
138
|
+
"<YOUR_APP_KEY>",
|
|
139
|
+
"--site",
|
|
140
|
+
"<YOUR_DD_SITE>(e.g us5.datadoghq.com)"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
For more advanced configurations with separate endpoints for logs and metrics:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"mcpServers": {
|
|
152
|
+
"datadog": {
|
|
153
|
+
"command": "npx",
|
|
154
|
+
"args": [
|
|
155
|
+
"datadog-mcp-server",
|
|
156
|
+
"--apiKey",
|
|
157
|
+
"<YOUR_API_KEY>",
|
|
158
|
+
"--appKey",
|
|
159
|
+
"<YOUR_APP_KEY>",
|
|
160
|
+
"--site",
|
|
161
|
+
"<YOUR_DD_SITE>",
|
|
162
|
+
"--logsSite",
|
|
163
|
+
"<YOUR_LOGS_SITE>",
|
|
164
|
+
"--metricsSite",
|
|
165
|
+
"<YOUR_METRICS_SITE>"
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Locations for the Claude Desktop config file:
|
|
173
|
+
|
|
174
|
+
- MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
175
|
+
- Windows: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
176
|
+
|
|
177
|
+
## Usage with MCP Inspector
|
|
178
|
+
|
|
179
|
+
To use with the MCP Inspector tool:
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
npx @modelcontextprotocol/inspector datadog-mcp-server --apiKey=your_api_key --appKey=your_app_key
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Available Tools
|
|
186
|
+
|
|
187
|
+
The server provides these MCP tools:
|
|
188
|
+
|
|
189
|
+
- **get-monitors**: Fetch monitors with optional filtering
|
|
190
|
+
- **get-monitor**: Get details of a specific monitor by ID
|
|
191
|
+
- **get-dashboards**: List all dashboards
|
|
192
|
+
- **get-dashboard**: Get a specific dashboard by ID
|
|
193
|
+
- **get-metrics**: List available metrics
|
|
194
|
+
- **get-metric-metadata**: Get metadata for a specific metric
|
|
195
|
+
- **get-events**: Fetch events within a time range
|
|
196
|
+
- **get-incidents**: List incidents with optional filtering
|
|
197
|
+
- **search-logs**: Search logs with advanced query filtering
|
|
198
|
+
- **aggregate-logs**: Perform analytics and aggregations on log data
|
|
199
|
+
|
|
200
|
+
## Examples
|
|
201
|
+
|
|
202
|
+
### Example: Get Monitors
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
{
|
|
206
|
+
"method": "tools/call",
|
|
207
|
+
"params": {
|
|
208
|
+
"name": "get-monitors",
|
|
209
|
+
"arguments": {
|
|
210
|
+
"groupStates": ["alert", "warn"],
|
|
211
|
+
"limit": 5
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Example: Get a Dashboard
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
{
|
|
221
|
+
"method": "tools/call",
|
|
222
|
+
"params": {
|
|
223
|
+
"name": "get-dashboard",
|
|
224
|
+
"arguments": {
|
|
225
|
+
"dashboardId": "abc-def-123"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Example: Search Logs
|
|
232
|
+
|
|
233
|
+
```javascript
|
|
234
|
+
{
|
|
235
|
+
"method": "tools/call",
|
|
236
|
+
"params": {
|
|
237
|
+
"name": "search-logs",
|
|
238
|
+
"arguments": {
|
|
239
|
+
"filter": {
|
|
240
|
+
"query": "service:web-app status:error",
|
|
241
|
+
"from": "now-15m",
|
|
242
|
+
"to": "now"
|
|
243
|
+
},
|
|
244
|
+
"sort": "-timestamp",
|
|
245
|
+
"limit": 20
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Example: Aggregate Logs
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
{
|
|
255
|
+
"method": "tools/call",
|
|
256
|
+
"params": {
|
|
257
|
+
"name": "aggregate-logs",
|
|
258
|
+
"arguments": {
|
|
259
|
+
"filter": {
|
|
260
|
+
"query": "service:web-app",
|
|
261
|
+
"from": "now-1h",
|
|
262
|
+
"to": "now"
|
|
263
|
+
},
|
|
264
|
+
"compute": [
|
|
265
|
+
{
|
|
266
|
+
"aggregation": "count"
|
|
267
|
+
}
|
|
268
|
+
],
|
|
269
|
+
"groupBy": [
|
|
270
|
+
{
|
|
271
|
+
"facet": "status",
|
|
272
|
+
"limit": 10,
|
|
273
|
+
"sort": {
|
|
274
|
+
"aggregation": "count",
|
|
275
|
+
"order": "desc"
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Example: Get Incidents
|
|
285
|
+
|
|
286
|
+
```javascript
|
|
287
|
+
{
|
|
288
|
+
"method": "tools/call",
|
|
289
|
+
"params": {
|
|
290
|
+
"name": "get-incidents",
|
|
291
|
+
"arguments": {
|
|
292
|
+
"includeArchived": false,
|
|
293
|
+
"query": "state:active",
|
|
294
|
+
"pageSize": 10
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Troubleshooting
|
|
301
|
+
|
|
302
|
+
If you encounter a 403 Forbidden error, verify that:
|
|
303
|
+
|
|
304
|
+
1. Your API key and Application key are correct
|
|
305
|
+
2. The keys have the necessary permissions to access the requested resources
|
|
306
|
+
3. Your account has access to the requested data
|
|
307
|
+
4. You're using the correct endpoint for your region (e.g., `datadoghq.eu` for EU customers)
|
|
308
|
+
|
|
309
|
+
## Debugging
|
|
310
|
+
|
|
311
|
+
If you encounter issues, check Claude Desktop's MCP logs:
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
# On macOS
|
|
315
|
+
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
|
|
316
|
+
|
|
317
|
+
# On Windows
|
|
318
|
+
Get-Content -Path "$env:APPDATA\Claude\Logs\mcp*.log" -Tail 20 -Wait
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
Common issues:
|
|
322
|
+
|
|
323
|
+
- 403 Forbidden: Authentication issue with Datadog API keys
|
|
324
|
+
- API key or App key format invalid: Ensure you're using the full key strings
|
|
325
|
+
- Site configuration errors: Make sure you're using the correct Datadog domain
|
|
326
|
+
- Endpoint mismatches: Verify that service-specific endpoints are correctly set if you're using separate domains for logs and metrics
|
|
327
|
+
|
|
328
|
+
## License
|
|
329
|
+
|
|
330
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
8
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
9
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
+
const minimist_1 = __importDefault(require("minimist"));
|
|
11
|
+
const zod_1 = require("zod");
|
|
12
|
+
// Import tools
|
|
13
|
+
const aggregateLogs_js_1 = require("./tools/aggregateLogs.js");
|
|
14
|
+
const getDashboard_js_1 = require("./tools/getDashboard.js");
|
|
15
|
+
const getDashboards_js_1 = require("./tools/getDashboards.js");
|
|
16
|
+
const getEvents_js_1 = require("./tools/getEvents.js");
|
|
17
|
+
const getIncidents_js_1 = require("./tools/getIncidents.js");
|
|
18
|
+
const getMetricMetadata_js_1 = require("./tools/getMetricMetadata.js");
|
|
19
|
+
const getMetrics_js_1 = require("./tools/getMetrics.js");
|
|
20
|
+
const getMonitor_js_1 = require("./tools/getMonitor.js");
|
|
21
|
+
const getMonitors_js_1 = require("./tools/getMonitors.js");
|
|
22
|
+
const searchLogs_js_1 = require("./tools/searchLogs.js");
|
|
23
|
+
// Parse command line arguments
|
|
24
|
+
const argv = (0, minimist_1.default)(process.argv.slice(2));
|
|
25
|
+
// Load environment variables from .env file (if it exists)
|
|
26
|
+
dotenv_1.default.config();
|
|
27
|
+
// Define environment variables - from command line or .env file
|
|
28
|
+
const DD_API_KEY = argv.apiKey || process.env.DD_API_KEY;
|
|
29
|
+
const DD_APP_KEY = argv.appKey || process.env.DD_APP_KEY;
|
|
30
|
+
// Get site configuration - defines the base domain for Datadog APIs
|
|
31
|
+
const DD_SITE = argv.site || process.env.DD_SITE || "datadoghq.com";
|
|
32
|
+
// Define service-specific endpoints for different Datadog services
|
|
33
|
+
// This follows Datadog's recommended approach for configuring regional endpoints
|
|
34
|
+
const DD_LOGS_SITE = argv.logsSite || process.env.DD_LOGS_SITE || DD_SITE;
|
|
35
|
+
const DD_METRICS_SITE = argv.metricsSite || process.env.DD_METRICS_SITE || DD_SITE;
|
|
36
|
+
// Remove https:// prefix if it exists to prevent double prefix issues
|
|
37
|
+
const cleanupUrl = (url) => url.startsWith("https://") ? url.substring(8) : url;
|
|
38
|
+
// Store clean values in process.env for backwards compatibility
|
|
39
|
+
process.env.DD_API_KEY = DD_API_KEY;
|
|
40
|
+
process.env.DD_APP_KEY = DD_APP_KEY;
|
|
41
|
+
process.env.DD_SITE = cleanupUrl(DD_SITE);
|
|
42
|
+
process.env.DD_LOGS_SITE = cleanupUrl(DD_LOGS_SITE);
|
|
43
|
+
process.env.DD_METRICS_SITE = cleanupUrl(DD_METRICS_SITE);
|
|
44
|
+
// Validate required environment variables
|
|
45
|
+
if (!DD_API_KEY) {
|
|
46
|
+
console.error("Error: DD_API_KEY is required.");
|
|
47
|
+
console.error("Please provide it via command line argument or .env file.");
|
|
48
|
+
console.error(" Command line: --apiKey=your_api_key");
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
if (!DD_APP_KEY) {
|
|
52
|
+
console.error("Error: DD_APP_KEY is required.");
|
|
53
|
+
console.error("Please provide it via command line argument or .env file.");
|
|
54
|
+
console.error(" Command line: --appKey=your_app_key");
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
// Initialize Datadog client tools
|
|
58
|
+
// We initialize each tool which will use the appropriate site configuration
|
|
59
|
+
getMonitors_js_1.getMonitors.initialize();
|
|
60
|
+
getMonitor_js_1.getMonitor.initialize();
|
|
61
|
+
getDashboards_js_1.getDashboards.initialize();
|
|
62
|
+
getDashboard_js_1.getDashboard.initialize();
|
|
63
|
+
getMetrics_js_1.getMetrics.initialize();
|
|
64
|
+
getMetricMetadata_js_1.getMetricMetadata.initialize();
|
|
65
|
+
getEvents_js_1.getEvents.initialize();
|
|
66
|
+
getIncidents_js_1.getIncidents.initialize();
|
|
67
|
+
searchLogs_js_1.searchLogs.initialize();
|
|
68
|
+
aggregateLogs_js_1.aggregateLogs.initialize();
|
|
69
|
+
// Set up MCP server
|
|
70
|
+
const server = new mcp_js_1.McpServer({
|
|
71
|
+
name: "datadog",
|
|
72
|
+
version: "1.0.0",
|
|
73
|
+
description: "MCP Server for Datadog API, enabling interaction with Datadog resources"
|
|
74
|
+
});
|
|
75
|
+
// Add tools individually, using their schemas directly
|
|
76
|
+
server.tool("get-monitors", "Fetch monitors from Datadog with optional filtering. Use groupStates to filter by monitor status (e.g., 'alert', 'warn', 'no data'), tags or monitorTags to filter by tag criteria, and limit to control result size.", {
|
|
77
|
+
groupStates: zod_1.z.array(zod_1.z.string()).optional(),
|
|
78
|
+
tags: zod_1.z.string().optional(),
|
|
79
|
+
monitorTags: zod_1.z.string().optional(),
|
|
80
|
+
limit: zod_1.z.number().default(100)
|
|
81
|
+
}, async (args) => {
|
|
82
|
+
const result = await getMonitors_js_1.getMonitors.execute(args);
|
|
83
|
+
return {
|
|
84
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
server.tool("get-monitor", "Get detailed information about a specific Datadog monitor by its ID. Use this to retrieve the complete configuration, status, and other details of a single monitor.", {
|
|
88
|
+
monitorId: zod_1.z.number()
|
|
89
|
+
}, async (args) => {
|
|
90
|
+
const result = await getMonitor_js_1.getMonitor.execute(args);
|
|
91
|
+
return {
|
|
92
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
server.tool("get-dashboards", "Retrieve a list of all dashboards from Datadog. Useful for discovering available dashboards and their IDs for further exploration.", {
|
|
96
|
+
filterConfigured: zod_1.z.boolean().optional(),
|
|
97
|
+
limit: zod_1.z.number().default(100)
|
|
98
|
+
}, async (args) => {
|
|
99
|
+
const result = await getDashboards_js_1.getDashboards.execute(args);
|
|
100
|
+
return {
|
|
101
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
server.tool("get-dashboard", "Get the complete definition of a specific Datadog dashboard by its ID. Returns all widgets, layout, and configuration details.", {
|
|
105
|
+
dashboardId: zod_1.z.string()
|
|
106
|
+
}, async (args) => {
|
|
107
|
+
const result = await getDashboard_js_1.getDashboard.execute(args);
|
|
108
|
+
return {
|
|
109
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
server.tool("get-metrics", "List available metrics from Datadog. Optionally use the q parameter to search for specific metrics matching a pattern. Helpful for discovering metrics to use in monitors or dashboards.", {
|
|
113
|
+
q: zod_1.z.string().optional()
|
|
114
|
+
}, async (args) => {
|
|
115
|
+
const result = await getMetrics_js_1.getMetrics.execute(args);
|
|
116
|
+
return {
|
|
117
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
server.tool("get-metric-metadata", "Retrieve detailed metadata about a specific metric, including its type, description, unit, and other attributes. Use this to understand a metric's meaning and proper usage.", {
|
|
121
|
+
metricName: zod_1.z.string()
|
|
122
|
+
}, async (args) => {
|
|
123
|
+
const result = await getMetricMetadata_js_1.getMetricMetadata.execute(args);
|
|
124
|
+
return {
|
|
125
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
server.tool("get-events", "Search for events in Datadog within a specified time range. Events include deployments, alerts, comments, and other activities. Useful for correlating system behaviors with specific events.", {
|
|
129
|
+
start: zod_1.z.number(),
|
|
130
|
+
end: zod_1.z.number(),
|
|
131
|
+
priority: zod_1.z.enum(["normal", "low"]).optional(),
|
|
132
|
+
sources: zod_1.z.string().optional(),
|
|
133
|
+
tags: zod_1.z.string().optional(),
|
|
134
|
+
unaggregated: zod_1.z.boolean().optional(),
|
|
135
|
+
excludeAggregation: zod_1.z.boolean().optional(),
|
|
136
|
+
limit: zod_1.z.number().default(100)
|
|
137
|
+
}, async (args) => {
|
|
138
|
+
const result = await getEvents_js_1.getEvents.execute(args);
|
|
139
|
+
return {
|
|
140
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
server.tool("get-incidents", "List incidents from Datadog's incident management system. Can filter by active/archived status and use query strings to find specific incidents. Helpful for reviewing current or past incidents.", {
|
|
144
|
+
includeArchived: zod_1.z.boolean().optional(),
|
|
145
|
+
pageSize: zod_1.z.number().optional(),
|
|
146
|
+
pageOffset: zod_1.z.number().optional(),
|
|
147
|
+
query: zod_1.z.string().optional(),
|
|
148
|
+
limit: zod_1.z.number().default(100)
|
|
149
|
+
}, async (args) => {
|
|
150
|
+
const result = await getIncidents_js_1.getIncidents.execute(args);
|
|
151
|
+
return {
|
|
152
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
server.tool("search-logs", "Search logs in Datadog with advanced filtering options. Use filter.query for search terms (e.g., 'service:web-app status:error'), from/to for time ranges (e.g., 'now-15m', 'now'), and sort to order results. Essential for investigating application issues.", {
|
|
156
|
+
filter: zod_1.z
|
|
157
|
+
.object({
|
|
158
|
+
query: zod_1.z.string().optional(),
|
|
159
|
+
from: zod_1.z.string().optional(),
|
|
160
|
+
to: zod_1.z.string().optional(),
|
|
161
|
+
indexes: zod_1.z.array(zod_1.z.string()).optional()
|
|
162
|
+
})
|
|
163
|
+
.optional(),
|
|
164
|
+
sort: zod_1.z.string().optional(),
|
|
165
|
+
page: zod_1.z
|
|
166
|
+
.object({
|
|
167
|
+
limit: zod_1.z.number().optional(),
|
|
168
|
+
cursor: zod_1.z.string().optional()
|
|
169
|
+
})
|
|
170
|
+
.optional(),
|
|
171
|
+
limit: zod_1.z.number().default(100)
|
|
172
|
+
}, async (args) => {
|
|
173
|
+
const result = await searchLogs_js_1.searchLogs.execute(args);
|
|
174
|
+
return {
|
|
175
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
server.tool("aggregate-logs", "Perform analytical queries and aggregations on log data. Essential for calculating metrics (count, avg, sum, etc.), grouping data by fields, and creating statistical summaries from logs. Use this when you need to analyze patterns or extract metrics from log data.", {
|
|
179
|
+
filter: zod_1.z
|
|
180
|
+
.object({
|
|
181
|
+
query: zod_1.z.string().optional(),
|
|
182
|
+
from: zod_1.z.string().optional(),
|
|
183
|
+
to: zod_1.z.string().optional(),
|
|
184
|
+
indexes: zod_1.z.array(zod_1.z.string()).optional()
|
|
185
|
+
})
|
|
186
|
+
.optional(),
|
|
187
|
+
compute: zod_1.z
|
|
188
|
+
.array(zod_1.z.object({
|
|
189
|
+
aggregation: zod_1.z.string(),
|
|
190
|
+
metric: zod_1.z.string().optional(),
|
|
191
|
+
type: zod_1.z.string().optional()
|
|
192
|
+
}))
|
|
193
|
+
.optional(),
|
|
194
|
+
groupBy: zod_1.z
|
|
195
|
+
.array(zod_1.z.object({
|
|
196
|
+
facet: zod_1.z.string(),
|
|
197
|
+
limit: zod_1.z.number().optional(),
|
|
198
|
+
sort: zod_1.z
|
|
199
|
+
.object({
|
|
200
|
+
aggregation: zod_1.z.string(),
|
|
201
|
+
order: zod_1.z.string()
|
|
202
|
+
})
|
|
203
|
+
.optional()
|
|
204
|
+
}))
|
|
205
|
+
.optional(),
|
|
206
|
+
options: zod_1.z
|
|
207
|
+
.object({
|
|
208
|
+
timezone: zod_1.z.string().optional()
|
|
209
|
+
})
|
|
210
|
+
.optional()
|
|
211
|
+
}, async (args) => {
|
|
212
|
+
const result = await aggregateLogs_js_1.aggregateLogs.execute(args);
|
|
213
|
+
return {
|
|
214
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
// Start the server
|
|
218
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
219
|
+
server
|
|
220
|
+
.connect(transport)
|
|
221
|
+
.then(() => { })
|
|
222
|
+
.catch((error) => {
|
|
223
|
+
console.error("Failed to start Datadog MCP Server:", error);
|
|
224
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aggregateLogs = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.aggregateLogs = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_LOGS_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_LOGS_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// Enable any unstable operations
|
|
21
|
+
configuration.unstableOperations["v2.aggregateLogs"] = true;
|
|
22
|
+
},
|
|
23
|
+
execute: async (params) => {
|
|
24
|
+
try {
|
|
25
|
+
const { filter, compute, groupBy, options } = params;
|
|
26
|
+
// Directly call with fetch to use the documented aggregation endpoint
|
|
27
|
+
const apiUrl = `https://${process.env.DD_LOGS_SITE || "datadoghq.com"}/api/v2/logs/analytics/aggregate`;
|
|
28
|
+
const headers = {
|
|
29
|
+
"Content-Type": "application/json",
|
|
30
|
+
"DD-API-KEY": process.env.DD_API_KEY || "",
|
|
31
|
+
"DD-APPLICATION-KEY": process.env.DD_APP_KEY || ""
|
|
32
|
+
};
|
|
33
|
+
const body = {
|
|
34
|
+
filter: filter,
|
|
35
|
+
compute: compute,
|
|
36
|
+
group_by: groupBy,
|
|
37
|
+
options: options
|
|
38
|
+
};
|
|
39
|
+
const response = await fetch(apiUrl, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: headers,
|
|
42
|
+
body: JSON.stringify(body)
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
throw {
|
|
46
|
+
status: response.status,
|
|
47
|
+
message: await response.text()
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
return data;
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (error.status === 403) {
|
|
55
|
+
console.error("Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access log analytics.");
|
|
56
|
+
throw new Error("Datadog API authorization failed. Please verify your API and Application keys have the correct permissions.");
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.error("Error aggregating logs:", error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDashboard = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getDashboard = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { dashboardId } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.DashboardsApi(configuration);
|
|
25
|
+
const apiParams = {
|
|
26
|
+
dashboardId: dashboardId
|
|
27
|
+
};
|
|
28
|
+
const response = await apiInstance.getDashboard(apiParams);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`Error fetching dashboard ${params.dashboardId}:`, error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDashboards = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getDashboards = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { filterConfigured, limit } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.DashboardsApi(configuration);
|
|
25
|
+
// No parameters needed for listDashboards
|
|
26
|
+
const response = await apiInstance.listDashboards();
|
|
27
|
+
// Apply client-side filtering if specified
|
|
28
|
+
let filteredDashboards = response.dashboards || [];
|
|
29
|
+
// Apply client-side limit if specified
|
|
30
|
+
if (limit && filteredDashboards.length > limit) {
|
|
31
|
+
filteredDashboards = filteredDashboards.slice(0, limit);
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
...response,
|
|
35
|
+
dashboards: filteredDashboards
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error("Error fetching dashboards:", error);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEvents = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getEvents = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { start, end, priority, sources, tags, unaggregated, excludeAggregation, limit } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.EventsApi(configuration);
|
|
25
|
+
const apiParams = {
|
|
26
|
+
start: start,
|
|
27
|
+
end: end,
|
|
28
|
+
priority: priority,
|
|
29
|
+
sources: sources,
|
|
30
|
+
tags: tags,
|
|
31
|
+
unaggregated: unaggregated,
|
|
32
|
+
excludeAggregate: excludeAggregation
|
|
33
|
+
};
|
|
34
|
+
const response = await apiInstance.listEvents(apiParams);
|
|
35
|
+
// Apply client-side limit if specified
|
|
36
|
+
if (limit && response.events && response.events.length > limit) {
|
|
37
|
+
response.events = response.events.slice(0, limit);
|
|
38
|
+
}
|
|
39
|
+
return response;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error("Error fetching events:", error);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIncidents = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getIncidents = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// Enable the unstable operation
|
|
21
|
+
configuration.unstableOperations["v2.listIncidents"] = true;
|
|
22
|
+
},
|
|
23
|
+
execute: async (params) => {
|
|
24
|
+
try {
|
|
25
|
+
const { includeArchived, pageSize, pageOffset, query, limit } = params;
|
|
26
|
+
const apiInstance = new datadog_api_client_1.v2.IncidentsApi(configuration);
|
|
27
|
+
const apiParams = {};
|
|
28
|
+
if (includeArchived !== undefined) {
|
|
29
|
+
apiParams.include_archived = includeArchived;
|
|
30
|
+
}
|
|
31
|
+
if (pageSize !== undefined) {
|
|
32
|
+
apiParams.page_size = pageSize;
|
|
33
|
+
}
|
|
34
|
+
if (pageOffset !== undefined) {
|
|
35
|
+
apiParams.page_offset = pageOffset;
|
|
36
|
+
}
|
|
37
|
+
if (query !== undefined) {
|
|
38
|
+
apiParams.query = query;
|
|
39
|
+
}
|
|
40
|
+
const response = await apiInstance.listIncidents(apiParams);
|
|
41
|
+
// Apply client-side limit if specified
|
|
42
|
+
if (limit && response.data && response.data.length > limit) {
|
|
43
|
+
response.data = response.data.slice(0, limit);
|
|
44
|
+
}
|
|
45
|
+
return response;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error.status === 403) {
|
|
49
|
+
console.error("Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access incidents.");
|
|
50
|
+
throw new Error("Datadog API authorization failed. Please verify your API and Application keys have the correct permissions.");
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.error("Error fetching incidents:", error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetricMetadata = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getMetricMetadata = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_METRICS_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_METRICS_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { metricName } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.MetricsApi(configuration);
|
|
25
|
+
const apiParams = {
|
|
26
|
+
metricName: metricName
|
|
27
|
+
};
|
|
28
|
+
const response = await apiInstance.getMetricMetadata(apiParams);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`Error fetching metadata for metric ${params.metricName}:`, error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMetrics = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getMetrics = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_METRICS_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_METRICS_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { q } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.MetricsApi(configuration);
|
|
25
|
+
const queryStr = q || "*";
|
|
26
|
+
const apiParams = {
|
|
27
|
+
q: queryStr
|
|
28
|
+
};
|
|
29
|
+
const response = await apiInstance.listMetrics(apiParams);
|
|
30
|
+
return response;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error("Error fetching metrics:", error);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMonitor = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getMonitor = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_METRICS_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_METRICS_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { monitorId } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.MonitorsApi(configuration);
|
|
25
|
+
const apiParams = {
|
|
26
|
+
monitorId: monitorId
|
|
27
|
+
};
|
|
28
|
+
const response = await apiInstance.getMonitor(apiParams);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error(`Error fetching monitor ${params.monitorId}:`, error);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMonitors = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.getMonitors = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_METRICS_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_METRICS_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
execute: async (params) => {
|
|
22
|
+
try {
|
|
23
|
+
const { groupStates, tags, monitorTags, limit } = params;
|
|
24
|
+
const apiInstance = new datadog_api_client_1.v1.MonitorsApi(configuration);
|
|
25
|
+
const groupStatesStr = groupStates ? groupStates.join(",") : undefined;
|
|
26
|
+
const apiParams = {
|
|
27
|
+
groupStates: groupStatesStr,
|
|
28
|
+
tags: tags,
|
|
29
|
+
monitorTags: monitorTags
|
|
30
|
+
};
|
|
31
|
+
const response = await apiInstance.listMonitors(apiParams);
|
|
32
|
+
if (limit && response.length > limit) {
|
|
33
|
+
return response.slice(0, limit);
|
|
34
|
+
}
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error.status === 403) {
|
|
39
|
+
console.error("Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access monitors.");
|
|
40
|
+
throw new Error("Datadog API authorization failed. Please verify your API and Application keys have the correct permissions.");
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error("Error fetching monitors:", error);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchLogs = void 0;
|
|
4
|
+
const datadog_api_client_1 = require("@datadog/datadog-api-client");
|
|
5
|
+
let configuration;
|
|
6
|
+
exports.searchLogs = {
|
|
7
|
+
initialize: () => {
|
|
8
|
+
const configOpts = {
|
|
9
|
+
authMethods: {
|
|
10
|
+
apiKeyAuth: process.env.DD_API_KEY,
|
|
11
|
+
appKeyAuth: process.env.DD_APP_KEY
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
configuration = datadog_api_client_1.client.createConfiguration(configOpts);
|
|
15
|
+
if (process.env.DD_LOGS_SITE) {
|
|
16
|
+
configuration.setServerVariables({
|
|
17
|
+
site: process.env.DD_LOGS_SITE
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// Enable any unstable operations
|
|
21
|
+
configuration.unstableOperations["v2.listLogsGet"] = true;
|
|
22
|
+
},
|
|
23
|
+
execute: async (params) => {
|
|
24
|
+
try {
|
|
25
|
+
const { apiKey = process.env.DD_API_KEY, appKey = process.env.DD_APP_KEY, filter, sort, page, limit } = params;
|
|
26
|
+
if (!apiKey || !appKey) {
|
|
27
|
+
throw new Error("API Key and App Key are required");
|
|
28
|
+
}
|
|
29
|
+
const apiInstance = new datadog_api_client_1.v2.LogsApi(configuration);
|
|
30
|
+
// Use a more flexible approach with POST
|
|
31
|
+
// Create the search request based on API docs
|
|
32
|
+
const body = {
|
|
33
|
+
filter: filter,
|
|
34
|
+
sort: sort,
|
|
35
|
+
page: page
|
|
36
|
+
};
|
|
37
|
+
// Use DD_LOGS_SITE environment variable instead of DD_SITE
|
|
38
|
+
const apiUrl = `https://${process.env.DD_LOGS_SITE || "datadoghq.com"}/api/v2/logs/events/search`;
|
|
39
|
+
const headers = {
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
"DD-API-KEY": apiKey,
|
|
42
|
+
"DD-APPLICATION-KEY": appKey
|
|
43
|
+
};
|
|
44
|
+
const response = await fetch(apiUrl, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: headers,
|
|
47
|
+
body: JSON.stringify(body)
|
|
48
|
+
});
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
throw {
|
|
51
|
+
status: response.status,
|
|
52
|
+
message: await response.text()
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const data = await response.json();
|
|
56
|
+
// Apply client-side limit if specified
|
|
57
|
+
if (limit && data.data && data.data.length > limit) {
|
|
58
|
+
data.data = data.data.slice(0, limit);
|
|
59
|
+
}
|
|
60
|
+
return data;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error.status === 403) {
|
|
64
|
+
console.error("Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access logs.");
|
|
65
|
+
throw new Error("Datadog API authorization failed. Please verify your API and Application keys have the correct permissions.");
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.error("Error searching logs:", error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@braxtonbooth/datadog-mcp-server",
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "MCP Server for Datadog API (Audited fork of GeLi2001/datadog-mcp-server)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"type": "commonjs",
|
|
7
|
+
"bin": {
|
|
8
|
+
"@braxtonbooth/datadog-mcp-server": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"start": "node dist/index.js",
|
|
13
|
+
"dev": "tsc && node dist/index.js",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"publish:dry-run": "npm pack --dry-run"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"datadog",
|
|
20
|
+
"mcp",
|
|
21
|
+
"model-context-protocol",
|
|
22
|
+
"observability",
|
|
23
|
+
"api"
|
|
24
|
+
],
|
|
25
|
+
"author": "GeLi2001",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@datadog/datadog-api-client": "^1.33.1",
|
|
29
|
+
"@modelcontextprotocol/sdk": "^1.8.0",
|
|
30
|
+
"dotenv": "^16.4.7",
|
|
31
|
+
"minimist": "^1.2.8",
|
|
32
|
+
"typescript": "^5.8.2",
|
|
33
|
+
"zod": "^3.24.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/minimist": "^1.2.5"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "git+https://github.com/braxtonbooth/datadog-mcp-server.git"
|
|
46
|
+
},
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/braxtonbooth/datadog-mcp-server/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/braxtonbooth/datadog-mcp-server#readme"
|
|
51
|
+
}
|