The New Relic MCP Server is a simple Model Context Protocol server that allows Large Language Models like Claude to query New Relic logs using NRQL queries. This integration enables AI assistants to access and analyze your New Relic data directly.
# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows (PowerShell)
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Create directory
mkdir newrelic-mcp
cd newrelic-mcp
# Create virtual environment
uv venv
# Activate virtual environment
source .venv/bin/activate # On Unix/macOS
.venv\Scripts\activate # On Windows
# Install dependencies
uv pip install "mcp[cli]" httpx
Create server file newrelic_logs_server.py
with the provided code.
Configure your environment variables:
# On Unix/macOS
export NEW_RELIC_API_KEY="your-api-key-here"
export NEW_RELIC_ACCOUNT_ID="your-account-id-here"
# On Windows (CMD)
set NEW_RELIC_API_KEY=your-api-key-here
set NEW_RELIC_ACCOUNT_ID=your-account-id-here
# On Windows (PowerShell)
$env:NEW_RELIC_API_KEY = "your-api-key-here"
$env:NEW_RELIC_ACCOUNT_ID = "your-account-id-here"
Configure Claude Desktop by editing your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Add the following configuration:
{
"mcpServers": {
"newrelic": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/newrelic-mcp",
"run",
"newrelic_logs_server.py"
],
"env": {
"NEW_RELIC_API_KEY": "your-api-key-here",
"NEW_RELIC_ACCOUNT_ID": "your-account-id-here"
}
}
}
}
SELECT * FROM Transaction SINCE 1 hour ago
SELECT * FROM Transaction WHERE error IS TRUE SINCE 1 hour ago LIMIT 10
SELECT average(duration) FROM Transaction FACET name ORDER BY average(duration) DESC LIMIT 5
You can ask Claude questions like:
# On macOS/Linux
tail -f ~/Library/Logs/Claude/mcp-server-newrelic.log
# On Windows
type %APPDATA%\Claude\logs\mcp-server-newrelic.log
Test your server functionality using:
npx @modelcontextprotocol/inspector uv run newrelic_logs_server.py
Authentication Errors:
Query Errors:
Connection Issues:
Server Not Starting:
Query Not Working:
Claude Not Connecting:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.