hyperdx/MCP.md

90 lines
3.2 KiB
Markdown
Raw Permalink Normal View History

feat: integrate Model Context Protocol (MCP) server for dashboards & investigations (#2030) ## 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
2026-04-14 14:39:07 +00:00
# HyperDX MCP Server
HyperDX exposes a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that lets AI assistants query your observability
data, manage dashboards, and explore data sources directly.
## Prerequisites
- A running HyperDX instance (see [CONTRIBUTING.md](/CONTRIBUTING.md) for local development setup, or [DEPLOY.md](/DEPLOY.md) for
self-hosted deployment)
- A **Personal API Access Key** — find yours in the HyperDX UI under **Team Settings > API Keys > Personal API Access Key**
## Endpoint
The MCP server is available at the `/api/mcp` path on your HyperDX instance. For local development this is:
```
http://localhost:8080/api/mcp
```
Replace `localhost:8080` with your instance's host and port if you've customized the defaults.
## Connecting an MCP Client
The MCP server uses the **Streamable HTTP** transport with Bearer token authentication. In the examples below, replace `<your-hyperdx-url>`
with your instance URL (e.g. `http://localhost:8080`).
### Claude Code
```bash
claude mcp add --transport http hyperdx <your-hyperdx-url>/api/mcp \
--header "Authorization: Bearer <your-personal-access-key>"
```
### OpenCode
```bash
opencode mcp add --transport http hyperdx <your-hyperdx-url>/api/mcp \
--header "Authorization: Bearer <your-personal-access-key>"
```
### Cursor
Add the following to `.cursor/mcp.json` in your project (or your global Cursor settings):
```json
{
"mcpServers": {
"hyperdx": {
"url": "<your-hyperdx-url>/api/mcp",
"headers": {
"Authorization": "Bearer <your-personal-access-key>"
}
}
}
}
```
### MCP Inspector
The MCP Inspector is useful for interactively testing and debugging the server.
```bash
cd packages/api && yarn dev:mcp
```
Then configure the inspector:
1. **Transport Type:** Streamable HTTP
2. **URL:** `<your-hyperdx-url>/api/mcp`
3. **Authentication:** Header `Authorization` with value `Bearer <your-personal-access-key>`
4. Click **Connect**
### Other Clients
Any MCP client that supports Streamable HTTP transport can connect. Configure it with:
- **URL:** `<your-hyperdx-url>/api/mcp`
- **Header:** `Authorization: Bearer <your-personal-access-key>`
## Available Tools
| Tool | Description |
| -------------------------- | -------------------------------------------------------------------------------------------- |
| `hyperdx_list_sources` | List all data sources and database connections, including column schemas and attribute keys |
| `hyperdx_query` | Query observability data (logs, metrics, traces) using builder mode, search mode, or raw SQL |
| `hyperdx_get_dashboard` | List all dashboards or get full detail for a specific dashboard |
| `hyperdx_save_dashboard` | Create or update a dashboard with tiles (charts, tables, numbers, search, markdown) |
| `hyperdx_delete_dashboard` | Permanently delete a dashboard and its attached alerts |
| `hyperdx_query_tile` | Execute the query for a specific dashboard tile to validate results |