Skip to content

adjohn/newrelic-mcp-app

Repository files navigation

New Relic MCP App

Disclaimer: This is a personal project and is not an official New Relic product. It is not supported, endorsed, or maintained by New Relic, Inc. Use at your own risk.

An MCP (Model Context Protocol) server that gives Claude structured access to New Relic observability data with interactive chart visualizations, plus an AI-powered error inbox triage agent. Built for AI-driven incident investigation — tools are organized around investigation workflows, not data types.

Features

MCP Tools (17 tools)

Core Observability

Tool Type Description
nrql-query View Execute custom NRQL with auto-detected charts (line, bar, area, table, funnel, raw JSON)
entity-health View Fleet-wide health overview across APM, Browser, Infrastructure, and Synthetics
alert-incidents View Active alert incidents and AI-grouped issues timeline
dashboard View List user-defined NR dashboards or render a specific dashboard inline (executes every widget's NRQL on the server)
describe-event Text Schema discovery for any event type — attributes, types, sample values

APM

Tool Type Description
apm-dashboard View Curated performance dashboard (response time percentiles, throughput, errors, Apdex, slowest txns)
deployment-impact View Deploy analysis — single deploy deep dive OR list recent deploys across all services with error rate correlation
service-dependencies View Upstream/downstream service topology with call counts, latency, and per-caller error rates

Error Investigation (workflow tools)

Tool Type Description
error-inbox Text Grouped errors with frequency, 7-day trend with change-point detection, and NEW error flagging
error-trace Text One-call root cause: error → distributed trace → correlated logs → request attributes → replay link
browser-error-trace Text JS error / AJAX analysis → backend trace → logs (also works as standalone AJAX failure analysis)
trace-detail View Full distributed trace waterfall with span timing, browser/APM origin tags, and auto-discovery

Digital Experience Monitoring (DEM)

Tool Type Description
browser-funnel View Conversion funnel with per-step performance, segmentation, auto-correlated errors, auto-detected steps
session-timeline View Session journey with replay link — PageView, BrowserInteraction, AjaxRequest, UserAction, PageAction, JavaScriptError

Logs

Tool Type Description
log-search Text Search logs with fuzzy entity matching, around timestamp parameter (±5min), and agent log filtering

Compound Workflow Tools

Tool Type Description
investigation-summary Text Fleet-wide triage in one call — find unhealthy services, top errors, recent deploys, trace root cause, pull logs
observability-audit Text Maturity scorecard across 10 dimensions — DT coverage, log correlation, alert noise, browser DT, deploy markers, ingest cost

Tools with "View" type return interactive React chart widgets rendered inline in the chat. "Text" tools return structured text optimized for Claude's reasoning.

Key Capabilities

  • Fuzzy entity resolution — all tools accept approximate app names (shippingserviceShipping Service) with automatic case-insensitive, normalized, and substring matching
  • Cross-service error propagationbrowser-error-trace walks from a JS error through AJAX failures to backend distributed traces automatically
  • TraceId sampling fallback — when TransactionError traceIds don't have corresponding Span data (agent sampling), tools automatically fall back to Span-sourced traceIds
  • Synthetic traffic filtering — browser tools exclude synthetic monitor traffic by default (monitorId IS NULL)
  • Session replay detectionerror-trace, session-timeline, and browser-error-trace check for replay availability and surface links
  • SPA detectionbrowser-funnel detects single-page apps via BrowserInteraction route changes and surfaces guidance

Error Inbox Triage Agent

A standalone CLI tool that uses Claude to automatically triage New Relic Error Inbox errors. It:

  • Prioritizes error groups by business impact (P0 / P1 / P2)
  • Identifies noise — duplicate root causes, transient errors, mute candidates
  • Flags regressions — recently introduced errors that need immediate attention
  • Suggests verification steps — concrete NRQL queries, logs, and dashboards to investigate
  • Finds cross-cutting patterns — systemic issues spanning multiple services

The output is a structured markdown report ready for engineers or downstream AI agents (bug fixers).

Prerequisites

Setup

git clone git@github.com:adjohn/newrelic-mcp-app.git
cd newrelic-mcp-app
npm install
npm run build

Adding to Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "newrelic": {
      "command": "npx",
      "args": ["tsx", "/path/to/newrelic-mcp-app/server.ts"],
      "env": {
        "NEW_RELIC_API_KEY": "NRAK-your-key-here",
        "NEW_RELIC_ACCOUNT_ID": "12345",
        "NEW_RELIC_REGION": "US"
      }
    }
  }
}

Each user provides their own NR API key in the config. The key never leaves the local machine.

Adding to Claude.ai (Custom Connector)

  1. Start the server with a tunnel (e.g., cloudflared):
    npm run serve
    cloudflared tunnel --url http://localhost:3001
  2. In Claude.ai → Settings → Connectors → Add Custom Connector
  3. Set the endpoint URL to your tunnel URL + /mcp
  4. Add auth headers with your NR credentials:
    • x-nr-api-key: Your NR User API key
    • x-nr-account-id: Your account ID
    • x-nr-region: US or EU (optional, defaults to US)

The server extracts credentials from these headers per-session, so each user can have their own key.

Running the Server Standalone

With environment variables:

NEW_RELIC_API_KEY=NRAK-... NEW_RELIC_ACCOUNT_ID=12345 npm run serve

Or with a .env file:

cp .env.example .env
# Edit .env with your keys
npm run dev
NEW_RELIC_API_KEY=NRAK-...        # New Relic User API key
NEW_RELIC_ACCOUNT_ID=12345        # Your account ID
NEW_RELIC_REGION=US               # US or EU
ANTHROPIC_API_KEY=sk-ant-...      # Anthropic API key (for triage agent only)

The server starts on http://localhost:3001 (configurable via PORT env var) with endpoints:

  • POST /mcp — MCP request handler
  • GET /mcp — Streamable HTTP transport (SSE)
  • DELETE /mcp — Session cleanup
  • GET /health — Health check

Credential Priority

The server resolves credentials in this order (first wins):

  1. HTTP headers (x-nr-api-key, x-nr-account-id) — for Claude.ai custom connectors
  2. Environment variables (NEW_RELIC_API_KEY, NEW_RELIC_ACCOUNT_ID) — for Claude Desktop / standalone
  3. Tool parameters (accountId on individual tool calls) — per-request override

Error Inbox Triage

Run against your New Relic account (last 24 hours):

npm run triage

Run with a wider time window:

npm run triage:week

Use mock data to test the full pipeline without New Relic:

npm run triage -- --mock

CLI Options

--account-id <id>      New Relic account ID (or set NEW_RELIC_ACCOUNT_ID)
--since <timerange>    NRQL time range (default: "24 hours ago")
--limit <n>            Max error groups to fetch (default: 50)
--output-dir <path>    Report output directory (default: "reports/")
--model <model>        Claude model for analysis
--mock                 Use realistic sample data instead of querying New Relic
--help                 Show help

Sample Report Output

The triage agent generates a markdown report in reports/ with:

  1. Executive Summary — high-level assessment of error inbox health
  2. Priority Errors — P0/P1/P2 ranked errors with business impact, reasoning, verification steps, and sample stack traces
  3. Regression Alerts — newly introduced errors with severity and evidence
  4. Noise Reduction — error groups to merge, mute, or reclassify
  5. Cross-Cutting Patterns — systemic issues spanning multiple services
  6. Appendix — full table of all error groups

Architecture

server.ts                      # MCP server + 15 tool definitions + fuzzy entity resolution
src/
├── nerdgraph.ts               # New Relic NerdGraph (GraphQL) API wrapper
├── triage/
│   ├── index.ts               # CLI entrypoint
│   ├── fetcher.ts             # Parallel NerdGraph/NRQL data fetching
│   ├── analyzer.ts            # Claude-powered error analysis
│   ├── reporter.ts            # Markdown report generation
│   ├── mock-data.ts           # 13 realistic sample error groups
│   └── types.ts               # TypeScript type definitions
└── views/
    ├── shared/                # Shared React components and theme
    │   ├── theme.ts           # Dark NR theme, global CSS
    │   └── components.tsx     # StatCard, ChartContainer, LoadingState, ErrorState
    ├── nrql-explorer/         # Interactive NRQL charts (line, bar, area, table, funnel, raw)
    ├── entity-health/         # Entity health dashboard
    ├── alert-timeline/        # Alert incident timeline
    ├── apm-dashboard/         # APM performance dashboard
    ├── deployment-impact/     # Deployment impact analysis
    ├── trace-waterfall/       # Distributed trace waterfall with span origin tags
    ├── service-dependencies/  # Service topology diagram + dependency tables
    ├── session-timeline/      # Per-session user journey timeline (6 event types)
    └── browser-funnel/        # Conversion funnel with perf metrics + segmentation

Design Principles

  • Workflow tools over data toolserror-trace and browser-error-trace encode investigation patterns (error → trace → logs → replay), collapsing 4-5 manual tool calls into one
  • Dual content — tools return text summaries for Claude's reasoning AND JSON payloads for interactive React chart views bundled as single-file HTML via vite-plugin-singlefile
  • Fuzzy resolution everywhere — entity names are resolved via a cached 4-phase matcher (exact → case-insensitive → normalized → substring) before any NRQL query runs
  • Sampling-aware — trace tools detect when TransactionError traceIds have no corresponding Spans (due to agent sampling) and automatically fall back to Span-sourced traceIds
  • Session-per-client — each MCP connection gets its own McpServer instance with all tools registered, managed via StreamableHTTPServerTransport with session IDs

The triage agent fetches error data via four parallel NerdGraph queries (counts, timings, user impact, sample details), sends the enriched data to Claude for analysis, and generates a structured markdown report.

License

MIT

About

Unofficial New Relic MCP server with interactive apps

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages