MCP Integration
Connect AI agents and IDEs to Neatlogs via the Model Context Protocol. Query traces, manage fixes, and integrate observability into your workflows.
The Model Context Protocol (MCP) is a standard that allows AI agents and IDEs to interact with external systems through a unified tool interface. Neatlogs exposes a complete MCP server that lets Claude, coding agents, and IDE plugins access observability data, search traces, and manage fixes directly from your agent workflows.
What You Can Do
With Neatlogs MCP, your agents can:
- Search production traces — Free-text query with filters for framework, model, detection, duration, token count, and cost
- Get full trace context — Fetch complete span trees with inputs, outputs, code locations
- List detections — See which detections (Hallucination, Jailbreak, Task Failure, …) are active
- Track detection trends — Analyze hourly/daily/weekly occurrence rates
- Read fixes — List all fix suggestions with root cause and recommended actions
- Manage fixes — Accept, dismiss, update status, and edit fix fields
- Review fix history — List, fetch, and restore saved content versions of a fix
- Log agent work — Push traces back to Neatlogs from your agent's execution
- Investigate fixes — Reload the investigation trail that produced a fix
Getting Started
Step 1: Get Your API Key
Each Neatlogs project has its own API key. Go to Settings → API Keys in the dashboard, pick your project, and copy its key.
Your API key grants full access to your project's data and tools. Treat it like a password and never commit it to version control. Store it in environment variables or a secrets manager.
Step 2: Connect Your Agent or IDE
The fastest path is the wizard, which wires the MCP server into Claude Code or Cursor for you:
npx @neatlogs/wizard mcp --api-key YOUR_PROJECT_KEYTo connect manually, add a neatlogs entry to your client's MCP config (.mcp.json for Claude Code, .cursor/mcp.json for Cursor):
{
"mcpServers": {
"neatlogs": {
"type": "http",
"url": "https://ingest.neatlogs.com/mcp",
"headers": {
"Authorization": "Bearer YOUR_PROJECT_KEY"
}
}
}
}The MCP server lives at /mcp on the same host as your SDK endpoint — https://ingest.neatlogs.com/mcp on hosted Neatlogs, or your own host's /mcp if you self-host.
Authentication: Include the key in either header:
Authorization: Bearer <your-api-key>(preferred — what most MCP clients send)x-api-key: <your-api-key>(legacy, still accepted)
Step 3: Verify and Start Using Tools
Restart your editor and the Neatlogs tools appear in your agent's tool list. Ask the agent to call ping to verify the connection, and whoami to confirm which project the session is bound to. From there it can call any tool — for example, search traces for a specific error.
Connection Methods
Best for: Claude Code, Cursor, agents, IDE plugins
Stateful sessions that you can reuse for multiple requests. The first initialize request creates a session; the server returns its id in the mcp-session-id response header.
POST https://ingest.neatlogs.com/mcp
Authorization: Bearer <your-api-key>
Content-Type: application/json
Accept: application/json, text/event-stream
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": { "name": "my-agent", "version": "1.0" }
}
}Then call tools on the session, passing the id back in the mcp-session-id header:
POST https://ingest.neatlogs.com/mcp
Authorization: Bearer <your-api-key>
Content-Type: application/json
Accept: application/json, text/event-stream
mcp-session-id: <session-id-from-initialize>
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "search_traces",
"arguments": {
"query": "timeout"
}
}
}Features:
- Stateful sessions (reuse connections)
- Include
mcp-session-idheader to resume - GET, POST, DELETE supported
- Rate limited: 60 requests/minute
- Best for agents and IDEs
Best for: Legacy clients that don't speak streamable HTTP
Event-based streaming with persistent connections.
GET https://ingest.neatlogs.com/mcp/sse
Authorization: Bearer <your-api-key>
# Connection opens, receives events
# Then POST messages to:
POST https://ingest.neatlogs.com/mcp/messages?sessionId=<session-id>Features:
- Server-sent events (SSE)
- Keep connection alive for streaming
- The GET stream is not rate-limited (won't break long-lived connections)
Authentication Patterns
Bearer Token (Standard)
Authorization: Bearer <your-project-api-key>Preferred by MCP clients. Works with any integration.
Legacy Header (x-api-key)
x-api-key: <your-project-api-key>Older integrations. Still supported for backward compatibility.
Scope
API keys are unique per project. Each key grants access to one project only — the session sees only that project's traces, detections, and fixes.
Session Management
Creating a Session
The initialize request creates a new session:
POST https://ingest.neatlogs.com/mcp
Authorization: Bearer <your-api-key>The server returns the session id in the mcp-session-id response header. Store this for subsequent calls.
Resuming a Session
Reuse an existing session by including the header:
POST https://ingest.neatlogs.com/mcp
Authorization: Bearer <your-api-key>
mcp-session-id: a1b2c3d4-e5f6-7890-abcd-ef1234567890Same session, same tools advertised, same context. Sessions are bound to the project that created them — reusing a session id with a different project's key returns 403.
Cleaning Up
Send DELETE to tear down a session:
DELETE https://ingest.neatlogs.com/mcp
Authorization: Bearer <your-api-key>
mcp-session-id: a1b2c3d4-e5f6-7890-abcd-ef1234567890Sessions are also cleaned up when the underlying connection closes. If a session id stops resolving, just initialize a new one.
Rate Limiting
- Limit: 60 requests per 60 seconds
- Applies to: POST and DELETE only
- Excludes: GET (SSE streaming) to avoid breaking long-lived connections
- Response: 429 Too Many Requests if exceeded
Retry with exponential backoff. Most tools complete in under 1 second so 60 req/min is generous for typical workflows.
Tool Overview
| Tool | Purpose | Use Case |
|---|---|---|
| ping | Health check | Verify connection |
| whoami | Get project ID | Confirm authentication |
| search_traces | Keyword or semantic search | Find errors, slow or expensive traces |
| get_trace_context | Fetch span tree | View execution details |
| list_detections | List active detections | See what's being monitored |
| get_detection_trend | Trend analysis | Track detection frequency |
| log_trace | Push traces | Agent reports its work |
| triage_list | List fixes | See all suggestions |
| triage_get | Fix details | Review root cause + action |
| triage_get_investigation | Investigation context | Read investigation thread |
| triage_list_steps | Investigation steps | See agent's analysis steps |
| triage_list_versions | List fix versions | Browse saved content versions of a fix |
| triage_get_version | Fetch fix version | Read one version snapshot by number |
| triage_restore_version | Restore fix version | Roll a fix's content back to an older version |
| triage_accept | Accept fix | Move to Kanban board |
| triage_dismiss | Reject fix | Mark as false positive |
| triage_update_status | Change status | Move across in_progress / resolved / archived |
| triage_update | Edit fix fields | Update title, severity, label, action |
See the MCP Tools Reference for detailed schemas and examples.
Common Workflows
Workflow 1: Agent Debugging Its Own Output
1. Agent completes a task
2. Calls log_trace() to push execution trace
3. Calls search_traces("timeout", min_duration: 5000) to find similar slow traces
4. Calls get_trace_context(trace_id) to compare
5. Uses context to improve next attemptWorkflow 2: IDE Plugin Finding Root Causes
1. Developer sees error in IDE
2. Plugin calls search_traces(error_message)
3. Fetches matching production traces
4. Shows top detections via list_detections()
5. Links to Neatlogs fixes panelWorkflow 3: Agent Managing Fixes
1. Agent sees triage_list() shows 5 draft fixes
2. Calls triage_get(fix_id) to review root cause
3. Dispatches fix to Claude Code
4. Calls triage_update_status(fix_id, "in_progress")
5. After deployment, calls triage_update_status(fix_id, "resolved")Workflow 4: Monitoring Regressions
1. Agent calls list_detections()
2. Picks a detection to watch, e.g. "Hallucination"
3. Calls get_detection_trend(detection_name: "hallucination", period: "7d", granularity: "day")
4. If trending up, digs into matching traces via search_tracesError Handling
Authentication Errors
| Status | Reason | Fix |
|---|---|---|
| 401 | Missing API key | Include Authorization header |
| 401 | Invalid API key | Check the key against Settings → API Keys |
| 403 | Session belongs to different project | Use the same project's API key for the session |
Validation Errors
| Status | Reason | Fix |
|---|---|---|
| 400 | Missing required parameter | Check tool schema in the reference |
| 400 | Missing mcp-session-id on DELETE | Include the session header |
| 404 | Unknown session id | Initialize a new session |
Server Errors
| Status | Reason | Fix |
|---|---|---|
| 429 | Rate limit exceeded | Wait before retrying |
| 500 | Internal server error | Retry with backoff; contact support if persistent |
All error responses include an error field with details. Calling a tool that isn't enabled returns a JSON-RPC error — disabled tools are never advertised in tools/list, so a well-behaved client won't hit this.
Best Practices
Do's:
- Store API keys securely (env vars, secrets manager)
- Reuse sessions when making multiple calls
- Verify the connection with
ping/whoamibefore relying on it - Set reasonable timeouts (15-30 seconds)
- Log tool calls for debugging
Don'ts:
- Hardcode API keys in code
- Create a new session for each request
- Assume a tool is available — check the advertised
tools/listfor the session - Make synchronous requests that block your workflow
- Share API keys across teams (each key exposes its whole project)
Troubleshooting
"API key required"
Missing or malformed Authorization header. Ensure the header is present and the format is correct.
"Invalid API key"
Key doesn't match any project. Copy it again from Settings → API Keys.
"Too many requests"
Hit rate limit (60/min). Implement exponential backoff or reduce call frequency.
"Session not found" / "Unknown sessionId"
Session was torn down or the connection closed. Initialize a new session (omit the mcp-session-id header on the next initialize).
"Session belongs to a different project"
Using an API key from one project to access another project's session. Create a new session with the correct key.
A tool is missing from tools/list
On self-hosted deployments, tools are enabled per-deployment in the backend tools.yaml. On hosted Neatlogs, all current tools are enabled — update your client if it's pinned to an old tool list.
Next Steps
- Read the MCP Tools Reference for detailed tool schemas
- Check Span Kinds for MCP_TOOL documentation
- See Long-Running Sessions for session monitoring from agents
Long Running Sessions Integration
Monitor long-running AI sessions in real-time — track progress, events, and status across Claude Code and other tools.
llms.txt File
Machine-readable discovery file for AI agents. Helps Claude, LLMs, and AI applications understand Neatlogs capabilities, APIs, and integration options.
