#!/usr/bin/env node
import 'dotenv/config';
import axios from 'axios';
async function testDatadogConnection() {
console.log('š Testing Datadog MCP Server Configuration...\n');
// Check environment variables
const apiKey = process.env.DD_API_KEY;
const appKey = process.env.DD_APP_KEY;
const site = process.env.DD_SITE || 'datadoghq.com';
console.log('š Environment Check:');
console.log(` DD_API_KEY: ${apiKey ? 'ā
Set' : 'ā Missing'}`);
console.log(` DD_APP_KEY: ${appKey ? 'ā
Set' : 'ā Missing'}`);
console.log(` DD_SITE: ${site}\n`);
if (!apiKey || !appKey) {
console.log('ā Missing required environment variables!');
console.log(' Please set DD_API_KEY and DD_APP_KEY in your .env file');
console.log(' See .env.template for the template\n');
process.exit(1);
}
// Test API connectivity
console.log('š Testing Datadog API connectivity...');
try {
const response = await axios.get(
`https://api.${site}/api/v1/validate`,
{
headers: {
'DD-API-KEY': apiKey,
'DD-APPLICATION-KEY': appKey,
'Content-Type': 'application/json'
},
timeout: 10000
}
);
if (response.status === 200) {
console.log('ā
Datadog API connection successful!');
console.log(` Response: ${JSON.stringify(response.data)}\n`);
}
} catch (error) {
console.log('ā Datadog API connection failed!');
console.log(` Error: ${error.message}`);
if (error.response) {
console.log(` Status: ${error.response.status}`);
console.log(` Data: ${JSON.stringify(error.response.data)}`);
}
console.log(' Please check your API keys and network connection\n');
process.exit(1);
}
// Test a simple monitors call
console.log('š§ Testing Monitors API...');
try {
const monitorsResponse = await axios.get(
`https://api.${site}/api/v1/monitor`,
{
headers: {
'DD-API-KEY': apiKey,
'DD-APPLICATION-KEY': appKey,
'Content-Type': 'application/json'
},
params: {
page_size: 1
},
timeout: 10000
}
);
if (monitorsResponse.status === 200) {
const monitors = monitorsResponse.data;
console.log(`ā
Successfully retrieved ${monitors.length} monitor(s)`);
if (monitors.length > 0) {
console.log(` Sample monitor: "${monitors[0].name}"`);
}
}
} catch (error) {
console.log('ā Monitors API test failed!');
console.log(` Error: ${error.message}`);
if (error.response) {
console.log(` Status: ${error.response.status}`);
console.log(` Data: ${JSON.stringify(error.response.data)}`);
}
process.exit(1);
}
console.log('\nš All tests passed! Your Datadog MCP server is ready to use.');
console.log(' You can now use it in VS Code or with the crew chat system.');
}
testDatadogConnection().catch((error) => {
console.error('š„ Unexpected error:', error);
process.exit(1);
});