New Relic Logs MCP server

Bridges New Relic's log querying capabilities with a Python-based server, enabling execution of NRQL queries for performance monitoring and log analysis.
Back to servers
Provider
Ivlad003
Release date
Jan 15, 2025
Language
Python
Stats
10 stars

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.

Installation

Prerequisites

  • Python 3.10 or higher
  • New Relic account and API key
  • Claude Desktop application

Setup Process

  1. Install uv package manager:
# 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"
  1. Create and setup project:
# 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
  1. Create server file newrelic_logs_server.py with the provided code.

  2. 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"

Claude Desktop Integration

Configure Claude Desktop by editing your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %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"
            }
        }
    }
}

Usage

Example NRQL Queries

  • Basic Transaction Query:
SELECT * FROM Transaction SINCE 1 hour ago
  • Error Analysis:
SELECT * FROM Transaction WHERE error IS TRUE SINCE 1 hour ago LIMIT 10
  • Performance Analysis:
SELECT average(duration) FROM Transaction FACET name ORDER BY average(duration) DESC LIMIT 5

Example Claude Prompts

You can ask Claude questions like:

  • "Show me all transactions from the last hour"
  • "Are there any errors in our application?"
  • "What are our slowest endpoints?"

Debugging

Viewing Logs

# On macOS/Linux
tail -f ~/Library/Logs/Claude/mcp-server-newrelic.log

# On Windows
type %APPDATA%\Claude\logs\mcp-server-newrelic.log

Testing with MCP Inspector

Test your server functionality using:

npx @modelcontextprotocol/inspector uv run newrelic_logs_server.py

Common Issues

  • Authentication Errors:

    • Check if NEW_RELIC_API_KEY is set correctly
    • Verify API key has correct permissions
    • Ensure API key is valid
  • Query Errors:

    • Verify NRQL syntax
    • Check account ID in code matches your account
    • Ensure queried data exists in the time range
  • Connection Issues:

    • Check network connectivity
    • Verify GraphQL endpoint is accessible
    • Ensure no firewalls are blocking connections

Troubleshooting

  • Server Not Starting:

    • Check Python version
    • Verify all dependencies are installed
    • Ensure virtual environment is activated
  • Query Not Working:

    • Check logs for detailed error messages
    • Verify NRQL syntax
    • Ensure data exists in queried time range
  • Claude Not Connecting:

    • Verify configuration file syntax
    • Check paths are absolute
    • Restart Claude Desktop

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later