Access New Relic logs and APM data through the NerdGraph API
New Relic MCP Server
A Model Context Protocol (MCP) server that provides AI agents like Claude Code with access to New Relic logs and APM data through the NerdGraph API.
Features
Log Tools
- query-logs: Execute custom NRQL queries against New Relic logs
- search-logs: Search logs with keyword filtering and optional attributes
- get-recent-logs: Retrieve the most recent log entries
APM Tools
- query-apm: Execute custom NRQL queries against APM data (transactions, metrics, etc.)
- get-apm-metrics: Get application performance metrics (response time, throughput, error rate, Apdex)
- get-transaction-traces: Retrieve transaction traces with optional filtering for slow transactions
Prerequisites
- Node.js 18 or higher
- New Relic account with:
- User API Key (create one here)
- Account ID (find it here)
Installation
- Clone this repository:
git clone https://github.com/xelber/newrelic-mcp.git
cd newrelic-mcp
- Install dependencies:
npm install
- Build the project:
npm run build
Configuration
Set the following environment variables:
export NEW_RELIC_API_KEY="your-user-api-key"
export NEW_RELIC_ACCOUNT_ID="your-account-id"
Or create a .env file in the project root (not committed to git):
NEW_RELIC_API_KEY=your-user-api-key
NEW_RELIC_ACCOUNT_ID=your-account-id
Usage with Claude Desktop and Claude Code
Step 1: Configure in Claude Desktop
First, add this server to your Claude Desktop configuration file:
Configuration file location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"newrelic": {
"command": "node",
"args": ["/absolute/path/to/newrelic-mcp/dist/index.js"],
"env": {
"NEW_RELIC_API_KEY": "your-user-api-key",
"NEW_RELIC_ACCOUNT_ID": "your-account-id"
}
}
}
}
Important:
- Replace
/absolute/path/to/newrelic-mcpwith the actual path to this project - Replace
your-user-api-keywith your New Relic User API Key - Replace
your-account-idwith your New Relic Account ID
Example (macOS):
{
"mcpServers": {
"newrelic": {
"command": "node",
"args": ["/Users/yourusername/newrelic-mcp/dist/index.js"],
"env": {
"NEW_RELIC_API_KEY": "NRAK-XXXXXXXXXXXXXXXXXXXXX",
"NEW_RELIC_ACCOUNT_ID": "1234567"
}
}
}
}
After updating the configuration:
- Save the file
- Restart Claude Desktop completely (Quit and reopen)
- Look for the 🔌 icon in Claude Desktop to verify the MCP server is connected
Step 2: Import into Claude Code
Once configured in Claude Desktop, you can import the server into Claude Code:
- Open Claude Code in your terminal or IDE
- The MCP server will be automatically available if you have Claude Desktop configured
- Alternatively, you can add it directly to Claude Code's MCP settings
For Claude Code direct configuration, create/edit the file at:
- macOS/Linux:
~/.config/claude-code/mcp_settings.json
With the same configuration format as above.
Available Tools
1. query-logs
Execute custom NRQL queries for complex filtering and aggregations.
Example queries:
query-logs with query: "SELECT * FROM Log WHERE message LIKE '%error%' SINCE 1 HOUR AGO LIMIT 100"
query-logs with query: "SELECT count(*) FROM Log WHERE level = 'ERROR' FACET host SINCE 1 DAY AGO"
query-logs with query: "SELECT * FROM Log WHERE service.name = 'api-server' AND response.status >= 500 SINCE 30 MINUTES AGO"
2. search-logs
Simplified search with keyword and attribute filtering.
Parameters:
keywords(optional): Text to search for in log messagestimeRange(default: "1 HOUR AGO"): Time range for the searchlimit(default: 100): Maximum number of resultsattributes(optional): Key-value pairs for filtering
Example:
search-logs with keywords: "database timeout", timeRange: "2 HOURS AGO", limit: 50
search-logs with keywords: "authentication failed", attributes: { "service.name": "auth-service" }
3. get-recent-logs
Quick access to the most recent log entries.
Parameters:
limit(default: 50): Number of recent entriestimeRange(default: "1 HOUR AGO"): Time window to search
Example:
get-recent-logs with limit: 100
get-recent-logs with limit: 25, timeRange: "30 MINUTES AGO"
4. query-apm
Execute custom NRQL queries against APM data for advanced analysis.
Example queries:
query-apm with query: "SELECT average(duration) FROM Transaction WHERE appName = 'MyApp' SINCE 1 HOUR AGO"
query-apm with query: "SELECT count(*) FROM Transaction WHERE error
Tools (6)
query-logsExecute custom NRQL queries against New Relic logs.search-logsSearch logs with keyword filtering and optional attributes.get-recent-logsRetrieve the most recent log entries.query-apmExecute custom NRQL queries against APM data.get-apm-metricsGet application performance metrics like response time, throughput, and error rate.get-transaction-tracesRetrieve transaction traces with optional filtering for slow transactions.Environment Variables
NEW_RELIC_API_KEYrequiredYour New Relic User API KeyNEW_RELIC_ACCOUNT_IDrequiredYour New Relic Account IDConfiguration
{"mcpServers": {"newrelic": {"command": "node", "args": ["/absolute/path/to/newrelic-mcp/dist/index.js"], "env": {"NEW_RELIC_API_KEY": "your-user-api-key", "NEW_RELIC_ACCOUNT_ID": "your-account-id"}}}}