npm package: @kivanio/mcp-new-relic
Description: MCP server for querying New Relic errors and metrics
Author: Kivanio
Latest version: 1.0.1

# MCP New Relic Server

A Model Context Protocol (MCP) server for querying New Relic errors and metrics. This server provides tools that Claude can use to monitor and analyze application performance and errors.

## Features

- **Error Querying**: Query application errors with customizable time ranges and filters
- **Custom NRQL Queries**: Execute any NRQL query directly
- **Performance Metrics**: Query response times, throughput, error rates, and Apdex scores
- **Easy Integration**: Works seamlessly with Claude Desktop and other MCP clients

## Installation

### Option 1: NPM Package (Recommended)

Install globally via npm:

```bash
npm install -g mcp-new-relic
```

Or install locally in a project:

```bash
npm install mcp-new-relic
```

### Option 2: Docker

Pull from Docker Hub:

```bash
docker pull kivanio/mcp-new-relic
```

Or build locally:

```bash
git clone https://github.com/kivanio/mcp-new-relic.git
cd mcp-new-relic
docker build -t mcp-new-relic .
```

### Option 3: From Source

1. Clone the repository:
   ```bash
   git clone https://github.com/kivanio/mcp-new-relic.git
   cd mcp-new-relic
   ```
2. Install dependencies:
   ```bash
   npm install
   ```
3. Build the TypeScript code:
   ```bash
   npm run build
   ```

## Configuration

1. Copy `.env.example` to `.env`:

   ```bash
   cp .env.example .env
   ```

2. Edit `.env` with your New Relic credentials:

   ```env
   NEW_RELIC_API_KEY=your-api-key-here
   NEW_RELIC_ACCOUNT_ID=your-account-id-here
   NEW_RELIC_REGION=US # or EU
   ```

   To get your New Relic API key:

   - Log in to New Relic
   - Go to Account Settings → API Keys
   - Create a new User Key (not an Ingest Key)

## Usage with Claude Desktop

Add the server to your Claude Desktop configuration. The configuration depends on how you installed the package:

### If installed via NPM globally:

1. Open Claude Desktop settings
2. Go to the "Developer" tab
3. Add to your MCP servers configuration:

```json
{
  "mcpServers": {
    "new-relic": {
      "command": "mcp-new-relic",
      "env": {
        "NEW_RELIC_API_KEY": "your-api-key",
        "NEW_RELIC_ACCOUNT_ID": "your-account-id",
        "NEW_RELIC_REGION": "US"
      }
    }
  }
}
```

### If installed locally or from source:

```json
{
  "mcpServers": {
    "new-relic": {
      "command": "node",
      "args": ["/path/to/mcp-new-relic/dist/index.js"],
      "env": {
        "NEW_RELIC_API_KEY": "your-api-key",
        "NEW_RELIC_ACCOUNT_ID": "your-account-id",
        "NEW_RELIC_REGION": "US"
      }
    }
  }
}
```

### If using Docker:

```json
{
  "mcpServers": {
    "new-relic": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "--env-file",
        "/path/to/.env",
        "kivanio/mcp-new-relic"
      ]
    }
  }
}
```

### Using environment file:

If you have a `.env` file configured, you can omit the `env` section:

```json
{
  "mcpServers": {
    "new-relic": {
      "command": "mcp-new-relic"
    }
  }
}
```

## Available Tools

### 1. `query_errors`

Query application errors from New Relic.

**Parameters:**

- `timeRange` (optional): Time range for the query (default: "4 hours ago")
  - Examples: "1 hour ago", "24 hours ago", "7 days ago"
- `appName` (optional): Application name pattern (default: "%kivanio%")
  - Supports SQL LIKE patterns
- `limit` (optional): Maximum number of error types to return (default: 20, max: 100)

**Example usage in Claude:**

```
Use the New Relic tool to check for errors in the last 24 hours
```

### 2. `query_custom`

Execute a custom NRQL query.

**Parameters:**

- `query` (required): The NRQL query to execute

**Example usage in Claude:**

```
Run this NRQL query: SELECT count(*) FROM Transaction WHERE appName = 'kivanio-production' SINCE 1 hour ago
```

### 3. `query_metrics`

Query application performance metrics.

**Parameters:**

- `timeRange` (optional): Time range for the query (default: "1 hour ago")
- `appName` (optional): Application name pattern (default: "%kivanio%")
- `metrics` (optional): Array of metrics to query (default: ["response_time", "throughput", "error_rate"])
  - Available metrics: "response_time", "throughput", "error_rate", "apdex"

**Example usage in Claude:**

```
Check the performance metrics for the last 6 hours
```

## Development

### Running in development mode:

```bash
npm run dev
```

### Building:

```bash
npm run build
```

### Project structure:

```
mcp-new-relic/
├── src/
│   └── index.ts      # Main server implementation
├── dist/             # Compiled JavaScript (generated)
├── package.json      # Dependencies and scripts
├── tsconfig.json     # TypeScript configuration
├── .env.example      # Example environment variables
└── README.md         # This file
```

## Troubleshooting

### Common Issues

1. **Authentication errors**: Ensure your API key is valid and has the necessary permissions
2. **No results returned**: Check that your application name pattern matches your New Relic app names
3. **Connection errors**: Verify your region setting (US vs EU) matches your New Relic account

### Debug Mode

To see detailed logs, run the server with debug output:

```bash
DEBUG=* node dist/index.js
```

## License

MIT