Skip to content

Commit eb6f459

Browse files
Allow optional subdomain for Datadog enterprise accounts (#40)
Co-authored-by: katsumata(TK) <[email protected]>
1 parent fe05493 commit eb6f459

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,15 @@ You need valid Datadog API credentials to use this MCP server:
212212
- `DATADOG_API_KEY`: Your Datadog API key
213213
- `DATADOG_APP_KEY`: Your Datadog Application key
214214
- `DATADOG_SITE` (optional): The Datadog site (e.g. `datadoghq.eu`)
215+
- `DATADOG_SUBDOMAIN` (optional): The Datadog subdomain (e.g. `<your-subdomain>.datadoghq.com`)
215216

216217
Export them in your environment before running the server:
217218

218219
```bash
219220
export DATADOG_API_KEY="your_api_key"
220221
export DATADOG_APP_KEY="your_app_key"
221-
export DATADOG_SITE="your_datadog_site"
222+
export DATADOG_SITE="your_datadog_site" # Optional
223+
export DATADOG_SUBDOMAIN="your_datadog_subdomain" # Optional
222224
```
223225

224226
## Installation
@@ -243,7 +245,7 @@ pnpm watch # for development with auto-rebuild
243245

244246
To use this with Claude Desktop, add the following to your `claude_desktop_config.json`:
245247

246-
On MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
248+
On MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
247249
On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
248250

249251
```json
@@ -268,7 +270,8 @@ On Windows: `%APPDATA%/Claude/claude_desktop_config.json`
268270
"env": {
269271
"DATADOG_API_KEY": "<YOUR_API_KEY>",
270272
"DATADOG_APP_KEY": "<YOUR_APP_KEY>",
271-
"DATADOG_SITE": "<YOUR_SITE>" // Optional
273+
"DATADOG_SITE": "<YOUR_SITE>", // Optional
274+
"DATADOG_SUBDOMAIN": "<YOUR_SUBDOMAIN>" // Optional
272275
}
273276
}
274277
}
@@ -286,7 +289,8 @@ Or specify via `npx`:
286289
"env": {
287290
"DATADOG_API_KEY": "<YOUR_API_KEY>",
288291
"DATADOG_APP_KEY": "<YOUR_APP_KEY>",
289-
"DATADOG_SITE": "<YOUR_SITE>" // Optional
292+
"DATADOG_SITE": "<YOUR_SITE>", // Optional
293+
"DATADOG_SUBDOMAIN": "<YOUR_SUBDOMAIN>" // Optional
290294
}
291295
}
292296
}

smithery.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ startCommand:
1919
type: string
2020
default: ''
2121
description: Optional Datadog site (e.g. datadoghq.eu)
22+
datadogSubdomain:
23+
type: string
24+
default: ''
25+
description: Optional Datadog subdomain (e.g. <your-subdomain>.datadoghq.com)
2226
commandFunction:
2327
# A JS function that produces the CLI command based on the given config to start the MCP on stdio.
2428
|-
@@ -28,10 +32,12 @@ startCommand:
2832
env: Object.assign({}, process.env, {
2933
DATADOG_API_KEY: config.datadogApiKey,
3034
DATADOG_APP_KEY: config.datadogAppKey,
31-
...(config.datadogSite && { DATADOG_SITE: config.datadogSite })
35+
...(config.datadogSite && { DATADOG_SITE: config.datadogSite }),
36+
...(config.datadogSubdomain && { DATADOG_SUBDOMAIN: config.datadogSubdomain })
3237
})
3338
})
3439
exampleConfig:
3540
datadogApiKey: your_datadog_api_key_here
3641
datadogAppKey: your_datadog_app_key_here
3742
datadogSite: datadoghq.com
43+
datadogSubdomain: your-subdomain

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const datadogConfig = createDatadogConfig({
7474
apiKeyAuth: process.env.DATADOG_API_KEY,
7575
appKeyAuth: process.env.DATADOG_APP_KEY,
7676
site: process.env.DATADOG_SITE,
77+
subdomain: process.env.DATADOG_SUBDOMAIN,
7778
})
7879

7980
const TOOL_HANDLERS: ToolHandlers = {

src/utils/datadog.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ interface CreateDatadogConfigParams {
44
apiKeyAuth: string
55
appKeyAuth: string
66
site?: string
7+
subdomain?: string
78
}
89

910
export function createDatadogConfig(
@@ -25,6 +26,12 @@ export function createDatadogConfig(
2526
})
2627
}
2728

29+
if (config.subdomain != null) {
30+
datadogConfig.setServerVariables({
31+
subdomain: config.subdomain,
32+
})
33+
}
34+
2835
datadogConfig.unstableOperations = {
2936
'v2.listIncidents': true,
3037
'v2.getIncident': true,

tests/utils/datadog.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@ describe('createDatadogConfig', () => {
3434
'datadoghq.com',
3535
)
3636
})
37+
})
38+
39+
describe('createDatadogConfig', () => {
40+
it('should create a datadog config with custom subdomain when DATADOG_SUBDOMAIN is configured', () => {
41+
const datadogConfig = createDatadogConfig({
42+
apiKeyAuth: 'test-api-key',
43+
appKeyAuth: 'test-app-key',
44+
subdomain: 'youryour-subdomain',
45+
})
46+
expect(datadogConfig.authMethods).toEqual({
47+
apiKeyAuth: new ApiKeyAuthAuthentication('test-api-key'),
48+
appKeyAuth: new AppKeyAuthAuthentication('test-app-key'),
49+
})
50+
expect(datadogConfig.servers[0]?.getConfiguration()?.subdomain).toBe(
51+
'youryour-subdomain',
52+
)
53+
})
54+
55+
it('should create a datadog config with default subdomain when DATADOG_SUBDOMAIN is not configured', () => {
56+
const datadogConfig = createDatadogConfig({
57+
apiKeyAuth: 'test-api-key',
58+
appKeyAuth: 'test-app-key',
59+
})
60+
expect(datadogConfig.authMethods).toEqual({
61+
apiKeyAuth: new ApiKeyAuthAuthentication('test-api-key'),
62+
appKeyAuth: new AppKeyAuthAuthentication('test-app-key'),
63+
})
64+
expect(datadogConfig.servers[0]?.getConfiguration()?.subdomain).toBe('api')
65+
})
3766

3867
it('should throw an error when DATADOG_API_KEY are not configured', () => {
3968
expect(() =>

0 commit comments

Comments
 (0)