mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
## Summary Adds an MCP (Model Context Protocol) server to the HyperDX API, enabling AI assistants (Claude, Cursor, OpenCode, etc.) to query observability data, manage dashboards, and explore data sources directly via standardized tool calls. Key changes: - **MCP server** (`packages/api/src/mcp/`) — Streamable HTTP transport at `/api/mcp`, authenticated via Personal API Access Key - **Tools** — `hyperdx_list_sources`, `hyperdx_query`, `hyperdx_get_dashboard`, `hyperdx_save_dashboard`, `hyperdx_delete_dashboard`, `hyperdx_query_tile` - **Dashboard prompts** — Detailed prompt templates that guide LLMs in generating valid, high-quality dashboards - **Shared logic** — Refactored dashboard validation/transformation out of the external API router into reusable utils (`packages/api/src/routers/external-api/v2/utils/dashboards.ts`) - **Documentation** — `MCP.md` with setup instructions for Claude Code, OpenCode, Cursor, MCP Inspector, and other clients - **Tests** — Unit tests for dashboard tools, query tools, tracing, and response trimming ### Screenshots https://github.com/user-attachments/assets/8c5aa582-c79e-47e0-8f75-e03feabdf8a6 ### How to test locally 1. Start the dev stack: `yarn dev` 2. Connect an MCP client (e.g. MCP Inspector): ```bash cd packages/api && yarn dev:mcp ``` Then configure the inspector: - **Transport Type:** Streamable HTTP - **URL:** `http://localhost:8080/api/mcp` - **Header:** `Authorization: Bearer <your-personal-access-key>` - Click **Connect** 3. Alternatively, connect via Claude Code or OpenCode: ```bash claude mcp add --transport http hyperdx http://localhost:8080/api/mcp \ --header "Authorization: Bearer <your-personal-access-key>" ``` 4. Try listing sources, querying data, or creating/updating a dashboard through the connected AI assistant. 5. Run unit tests: ```bash cd packages/api && yarn ci:unit ``` ### References - Linear Issue: HDX-3710
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
import mongoose from 'mongoose';
|
|
import { z } from 'zod';
|
|
|
|
import { deleteDashboard } from '@/controllers/dashboard';
|
|
import Dashboard from '@/models/dashboard';
|
|
|
|
import { withToolTracing } from '../../utils/tracing';
|
|
import type { McpContext } from '../types';
|
|
|
|
export function registerDeleteDashboard(
|
|
server: McpServer,
|
|
context: McpContext,
|
|
): void {
|
|
const { teamId } = context;
|
|
|
|
server.registerTool(
|
|
'hyperdx_delete_dashboard',
|
|
{
|
|
title: 'Delete Dashboard',
|
|
description:
|
|
'Permanently delete a dashboard by ID. Also removes any alerts attached to its tiles. ' +
|
|
'Use hyperdx_get_dashboard (without an ID) to list available dashboard IDs.',
|
|
inputSchema: z.object({
|
|
id: z.string().describe('Dashboard ID to delete.'),
|
|
}),
|
|
},
|
|
withToolTracing(
|
|
'hyperdx_delete_dashboard',
|
|
context,
|
|
async ({ id: dashboardId }) => {
|
|
if (!mongoose.Types.ObjectId.isValid(dashboardId)) {
|
|
return {
|
|
isError: true,
|
|
content: [{ type: 'text' as const, text: 'Invalid dashboard ID' }],
|
|
};
|
|
}
|
|
|
|
const existing = await Dashboard.findOne({
|
|
_id: dashboardId,
|
|
team: teamId,
|
|
}).lean();
|
|
if (!existing) {
|
|
return {
|
|
isError: true,
|
|
content: [{ type: 'text' as const, text: 'Dashboard not found' }],
|
|
};
|
|
}
|
|
|
|
await deleteDashboard(dashboardId, new mongoose.Types.ObjectId(teamId));
|
|
|
|
return {
|
|
content: [
|
|
{
|
|
type: 'text' as const,
|
|
text: JSON.stringify({ deleted: true, id: dashboardId }, null, 2),
|
|
},
|
|
],
|
|
};
|
|
},
|
|
),
|
|
);
|
|
}
|