New Relic MCP Server
Enables AI agents to access New Relic logs and APM data through the NerdGraph API. It allows users to execute NRQL queries, retrieve application performance metrics, and analyze transaction traces using natural language.
README
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 IS true FACET appName SINCE 1 DAY AGO"
query-apm with query: "SELECT percentile(duration, 95) FROM Transaction WHERE transactionType = 'Web' SINCE 30 MINUTES AGO TIMESERIES"
5. get-apm-metrics
Get comprehensive application performance metrics including response time, throughput, error rate, and Apdex score.
Parameters:
appName(optional): Filter metrics for a specific application. If not provided, returns aggregated metrics across all applications.timeRange(default: "1 HOUR AGO"): Time range for metricsmetrics(default: ["responseTime", "throughput", "errorRate"]): Array of metrics to retrieve- Options: "responseTime", "throughput", "errorRate", "apdex"
Behavior:
- With
appName: Returns time-series metrics for the specified application - Without
appName: Returns aggregated metrics across all applications (not broken down by app)
Examples:
get-apm-metrics with appName: "MyApp", timeRange: "2 HOURS AGO"
get-apm-metrics with metrics: ["responseTime", "errorRate", "apdex"]
get-apm-metrics with appName: "EcommerceApp", metrics: ["throughput", "responseTime"], timeRange: "1 DAY AGO"
Note: To get metrics for multiple specific applications, call this tool separately for each application name.
6. get-transaction-traces
Retrieve transaction traces to identify performance bottlenecks and slow operations.
Parameters:
appName(optional): Filter transactions for a specific applicationminDuration(optional): Minimum transaction duration in seconds to filter slow transactionslimit(default: 10): Maximum number of transaction traces to returntimeRange(default: "1 HOUR AGO"): Time range to search
Examples:
get-transaction-traces with appName: "MyApp", minDuration: 2.0, limit: 20
get-transaction-traces with minDuration: 5.0, timeRange: "30 MINUTES AGO"
get-transaction-traces with appName: "APIService", limit: 50
Development
Run tests:
npm test
Run tests with coverage:
npm run test:coverage
Run tests in watch mode:
npm run test:watch
Run in development mode (builds and starts):
npm run dev
Watch mode for auto-rebuilding:
npm run watch
Build the project:
npm run build
Example Interactions
Once configured, you can ask Claude (in Claude Desktop or Claude Code):
Log Queries
- "Show me recent errors from New Relic logs"
- "Search for logs containing 'payment failed' in the last 2 hours"
- "Query New Relic for all logs from the api-gateway service with 500 status codes"
- "Get the last 100 log entries from New Relic"
- "Find all logs with response time > 5000ms in the last hour"
- "Show me error logs grouped by service name"
APM Queries
- "Show me the response time and throughput for MyApp in the last hour"
- "Get APM metrics for all applications including error rates"
- "Find slow transactions that took longer than 3 seconds"
- "What's the error rate for MyApp over the past 2 hours?"
- "Show me the slowest 20 transactions from the EcommerceApp"
- "Get the Apdex score and response time for all my applications"
- "Find all transactions that resulted in errors in the last 30 minutes"
Troubleshooting
MCP Server Connection Issues
Server not showing in Claude Desktop:
- Verify the config file path is correct for your OS
- Check that the JSON syntax is valid (no trailing commas, proper quotes)
- Ensure the path to
dist/index.jsis absolute, not relative - Restart Claude Desktop completely (Quit, not just close window)
- Check Claude Desktop logs:
View > Developer > Show Logs
"Cannot find module" errors:
- Make sure you ran
npm installin the project directory - Verify you ran
npm run buildto compile TypeScript - Check that the
dist/folder exists and contains the compiled files
New Relic API Issues
"Configuration error" on startup:
- Ensure
NEW_RELIC_API_KEYandNEW_RELIC_ACCOUNT_IDare set correctly - Verify your API key has the necessary permissions (User key, not Ingest key)
- Get your User API key from: https://one.newrelic.com/api-keys
"Failed to query New Relic":
- Check your API key is valid and not expired
- Verify your account ID is correct (find it at https://one.newrelic.com/admin-portal)
- Ensure you have access to the Logs product in New Relic
- Test your credentials using the NerdGraph API Explorer
No results returned:
- Verify you have log data in New Relic for the specified time range
- Check your NRQL syntax is valid
- Try a broader time range (e.g., "1 DAY AGO" instead of "1 HOUR AGO")
- Use the New Relic UI to confirm logs exist for your query
NRQL Resources
- New Relic NRQL Documentation
- Log Query Examples
- APM Data and NRQL
- Query APM Metric Data
- Transaction Event Attributes
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。