Skip to main content
Glama
CubeAPM MCP Server

CubeAPM MCP Server

CubeAPM MCP Server

npm version License: MIT MCP Server

A Model Context Protocol (MCP) server for CubeAPM - enabling AI assistants like Claude to query your observability data including traces, metrics, and logs.

What is this?

This MCP server connects AI assistants (like Claude) to your CubeAPM instance, allowing you to:

  • Query logs using natural language that gets translated to LogsQL

  • Analyze metrics with PromQL-compatible queries

  • Search and inspect traces to debug distributed systems

  • Monitor your services through conversational interfaces

Related MCP server: Cube.js MCP Server

Installation

npm install -g cubeapm-mcp

From Source

git clone https://github.com/TechnicalRhino/cubeapm-mcp.git
cd cubeapm-mcp
npm install
npm run build

Quick Start

1. Configure Claude Code

Add to your Claude Code settings (~/.claude/settings.json):

{
  "mcpServers": {
    "cubeapm": {
      "command": "npx",
      "args": ["-y", "cubeapm-mcp"],
      "env": {
        "CUBEAPM_HOST": "your-cubeapm-server.com"
      }
    }
  }
}

2. Restart Claude Code

After updating the settings, restart Claude Code to load the MCP server.

3. Start Querying

You can now ask Claude questions like:

  • "Show me error logs from the payment-service in the last hour"

  • "What's the p99 latency for the checkout API?"

  • "Find traces where duration > 5s in production"

  • "Get the full trace for trace ID abc123def456"

Configuration

Environment Variable

Default

Description

CUBEAPM_URL

-

Full URL to CubeAPM (e.g., https://cube.example.com). Takes precedence over HOST/PORT settings.

CUBEAPM_HOST

localhost

CubeAPM server hostname or IP (used if CUBEAPM_URL not set)

CUBEAPM_QUERY_PORT

3140

Port for querying APIs (traces, metrics, logs)

CUBEAPM_INGEST_PORT

3130

Port for ingestion APIs

Example Configurations

Local Development:

{
  "mcpServers": {
    "cubeapm": {
      "command": "npx",
      "args": ["-y", "cubeapm-mcp"],
      "env": {
        "CUBEAPM_HOST": "localhost"
      }
    }
  }
}

Production (with full URL):

{
  "mcpServers": {
    "cubeapm": {
      "command": "npx",
      "args": ["-y", "cubeapm-mcp"],
      "env": {
        "CUBEAPM_URL": "https://cubeapm.internal.company.com"
      }
    }
  }
}

Production (with host/port):

{
  "mcpServers": {
    "cubeapm": {
      "command": "npx",
      "args": ["-y", "cubeapm-mcp"],
      "env": {
        "CUBEAPM_HOST": "cubeapm.internal.company.com",
        "CUBEAPM_QUERY_PORT": "3140"
      }
    }
  }
}

Available Tools

Logs

Tool

Description

query_logs

Query logs using LogsQL syntax with time range and limit

Parameters:

  • query - LogsQL query string (e.g., {service="api"} error)

  • start - Start time (RFC3339 or Unix timestamp)

  • end - End time (RFC3339 or Unix timestamp)

  • limit - Maximum entries to return (default: 100)

Metrics

Tool

Description

query_metrics_instant

Execute a PromQL query at a single point in time

query_metrics_range

Execute a PromQL query over a time range

Instant Query Parameters:

  • query - PromQL expression

  • time - Evaluation timestamp

  • step - Optional time window in seconds

Range Query Parameters:

  • query - PromQL expression

  • start / end - Time range

  • step - Resolution in seconds

Traces

Tool

Description

search_traces

Search traces by service, environment, or custom query

get_trace

Fetch complete trace details by trace ID

Search Parameters (Required):

  • query - Search query (default: * for wildcard)

  • env - Environment filter (default: UNSET)

  • service - Service name filter (required, case-sensitive)

  • start / end - Time range (RFC3339 or Unix timestamp)

Search Parameters (Optional):

  • limit - Maximum results (default: 20)

  • spanKind - Filter by span type: server, client, consumer, producer

  • sortBy - Sort by: duration (useful for finding slow traces)

Get Trace Parameters:

  • trace_id - Hex-encoded trace ID

  • start / end - Time range to search within

Ingestion

Tool

Description

ingest_metrics_prometheus

Send metrics in Prometheus text exposition format

Prompts

Pre-defined templates for common observability tasks:

Prompt

Description

investigate-service

Comprehensive service investigation - checks errors, latency, and traces

check-latency

Get P50, P95, P99 latency percentiles for a service

find-slow-traces

Find slowest traces to identify performance bottlenecks

Usage Example:

Use the investigate-service prompt for Kratos-Prod

Resources

Readable resources exposing CubeAPM data and configuration:

Resource URI

Description

cubeapm://config

Current CubeAPM connection configuration

cubeapm://query-patterns

Query patterns and naming conventions reference

CubeAPM Query Patterns

Metrics (PromQL / MetricsQL)

CubeAPM uses specific naming conventions that differ from standard OpenTelemetry:

What

CubeAPM Convention

Metric prefix

cube_apm_* (e.g., cube_apm_calls_total, cube_apm_latency_bucket)

Service label

service (NOT server or service_name)

Common labels

env, service, span_kind, status_code, http_code

Histogram Queries (P50, P90, P95, P99)

CubeAPM uses VictoriaMetrics-style histograms with vmrange labels instead of Prometheus le buckets:

# ✅ Correct - Use histogram_quantiles() with vmrange
histogram_quantiles("phi", 0.95, sum by (vmrange, service) (
  increase(cube_apm_latency_bucket{service="MyService", span_kind="server"}[5m])
))

# ❌ Wrong - Standard Prometheus syntax won't work
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_bucket[5m])))

Note: Latency values are returned in seconds (0.05 = 50ms)

Logs (LogsQL)

Stream Selectors

Log labels vary by source. Use * query first to discover available labels:

Source

Common Labels

Lambda functions

faas.name, faas.arn, env, aws.lambda_request_id

Services

service_name, level, host

# Discover all labels
*

# Lambda function logs
{faas.name="my-lambda-prod"}

# Regex match
{faas.name=~".*-prod"}

# Text filter with boolean operators
{faas.name=~".*"} AND "error" AND NOT "retry"

Pipe Operators

Chain after any query with |:

Pipe

Syntax

Description

copy

| copy src AS dst

Copy field value

drop

| drop field1, field2

Remove fields from output

extract_regexp

| extract_regexp "(?P<name>re)"

Extract via named capture groups

join

| join by (field) (...subquery...)

Join with subquery results

keep

| keep field1, field2

Keep only specified fields

limit

| limit N

Return at most N results

math

| math result = f1 + f2

Arithmetic (+, -, *, /, %)

rename

| rename src AS dst

Rename a field

replace

| replace (field, "old", "new")

Substring replacement

replace_regexp

| replace_regexp (field, "re", "repl")

Regex replacement

sort

| sort by (field) [asc|desc]

Sort results

stats

| stats <func> as alias [by (fields)]

Aggregate results

unpack_json

| unpack_json

Extract fields from JSON body

Stats Functions

Used with the | stats pipe:

Function

Description

avg(field)

Arithmetic mean

count()

Total matching entries

count_empty(field)

Entries where field is empty

count_uniq(field)

Distinct values

max(field)

Maximum value

median(field)

Median (50th percentile)

min(field)

Minimum value

quantile(p, field)

p-th quantile (e.g., quantile(0.95, duration))

sum(field)

Sum of values

Example Log Queries

# Count errors per Lambda function
{faas.name=~".*"} AND "error" | stats count() as errors by (faas.name)

# Top 10 slowest requests
{service_name="my-service"} | sort by (duration) desc | limit 10

# Extract and aggregate from JSON logs
{service_name="api"} | unpack_json | stats avg(response_time) as avg_rt by (endpoint)

Traces

Trace queries use the same pipe syntax as logs: {stream_selector} | pipe1 | pipe2

Important notes:

  • query, env, service are REQUIRED parameters

  • Duration is in milliseconds (not seconds like metrics)

  • p95 is NOT a valid stats function — use quantile(0.95, duration)

  • Service names are case-sensitive (e.g., "Kratos-Prod" not "kratos")

Example Trace Queries

# P95 latency for a service
{service="Kratos-Prod", span_kind="server"} | stats quantile(0.95, duration) as p95_ms

# Error count by endpoint
{service="Kratos-Prod", status_code="ERROR"} | stats count() as errors by (http_route)

# Slowest spans
{service="Kratos-Prod"} | sort by (duration) desc | limit 20

Example Natural Language Queries

Logs

"Show me logs from webhook-lambda-prod"
"Find all logs containing 'timeout' in the last hour"
"Count errors per Lambda function in the last 24h"

Metrics

"What's the P95 latency for Kratos-Prod service?"
"Show me error rate for all services"
"List all available services in CubeAPM"

Traces

"Find the P95 latency for Kratos-Prod using trace stats"
"Show me traces with errors in the production environment"
"Get the full waterfall for trace ID abc123"

Development

# Clone the repository
git clone https://github.com/TechnicalRhino/cubeapm-mcp.git
cd cubeapm-mcp

# Install dependencies
npm install

# Run in development mode (with hot reload)
npm run dev

# Build for production
npm run build

# Test the build
npm start

How It Works

┌─────────────────┐     MCP Protocol     ┌─────────────────┐     HTTP API     ┌─────────────────┐
│  Claude / AI    │◄───────────────────►│  cubeapm-mcp    │◄────────────────►│    CubeAPM      │
│   Assistant     │   (stdio transport)  │   MCP Server    │   (REST calls)   │    Server       │
└─────────────────┘                      └─────────────────┘                  └─────────────────┘

The MCP server:

  1. Receives tool calls from the AI assistant via stdio

  2. Translates them to CubeAPM HTTP API requests

  3. Returns formatted results back to the assistant

Requirements

  • Node.js 18+

  • CubeAPM instance (self-hosted or cloud)

  • Claude Code or any MCP-compatible client

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE file for details.

Available Tools

6 tools
get_traceA

Fetch a complete trace by its ID from CubeAPM. Returns all spans in the trace with full details.

Inputs: end (required), start (required), trace_id (required).

ingest_metrics_prometheusC

Send metrics to CubeAPM in Prometheus text exposition format.

Inputs: metrics (required).

query_logsA

Query logs from CubeAPM using LogsQL syntax (VictoriaLogs compatible). Returns log entries matching the query.

IMPORTANT - Log Label Discovery:

  • Labels vary by source! Use "*" query first to discover available labels

  • Lambda logs use: faas.name, faas.arn, env, aws.lambda_request_id

  • Service logs may use: service_name, level, host

  • NOT all sources have "service_name" - check the _stream field in results

LogsQL Query Syntax:

  • Wildcard (discover labels): *

  • Stream filters: {faas.name="my-lambda-prod"}

  • Text search: {faas.name="webhook-lambda-prod"} AND "error"

  • Regex match: {faas.name=~".*-prod"}

  • Negation: {faas.name!="unwanted-service"}

  • Combine filters: {env="UNSET", faas.name=~".-lambda."}

PIPE OPERATORS — chain after query with "|": | copy src_field AS dst_field — copy field value | drop field1, field2 — remove fields from output | extract_regexp "(?Pregex)" — extract fields via named capture groups | join by (field) (...subquery...) — join with subquery results | keep field1, field2 — keep only specified fields | limit N — return at most N results | math result = field1 + field2 — compute derived fields (+, -, *, /, %) | rename src AS dst — rename a field | replace (field, "old", "new") — replace substring in field | replace_regexp (field, "re", "replacement") — regex replacement | sort by (field) [asc|desc] — sort results | stats as alias [by (group_fields)] — aggregate results | unpack_json — extract fields from JSON log body

STATS FUNCTIONS (use with | stats pipe): avg(field) — arithmetic mean count() — total number of matching entries count_empty(field) — count entries where field is empty count_uniq(field) — count distinct values max(field) — maximum value median(field) — median (50th percentile) min(field) — minimum value quantile(p, field) — p-th quantile (e.g., quantile(0.95, duration)) sum(field) — sum of values

Example queries:

  • All logs (discover structure): *

  • Lambda logs: {faas.name="webhook-lambda-prod"}

  • Search errors: {faas.name=~".*"} AND "error"

  • By environment: {env="production"}

  • Count errors per function: {faas.name=~".*"} AND "error" | stats count() as error_count by (faas.name)

  • Top 10 slowest: {service_name="my-service"} | sort by (duration) desc | limit 10

Inputs: end (required), query (required), start (required), limit.

query_metrics_instantA

Execute an instant query against CubeAPM metrics at a single point in time. Uses PromQL-compatible syntax (VictoriaMetrics flavor).

IMPORTANT - CubeAPM Metric Naming Conventions:

  • Metrics use "cube_apm_" prefix (e.g., cube_apm_calls_total, cube_apm_latency_bucket)

  • Service label is "service" (NOT "server" or "service_name")

  • Common labels: env, service, span_kind (server|client|consumer|producer), status_code, http_code

HISTOGRAM QUERIES (P50, P90, P95, P99):

  • CubeAPM uses VictoriaMetrics-style histograms with "vmrange" label (NOT Prometheus "le" buckets)

  • Use histogram_quantiles() function instead of histogram_quantile()

  • Syntax: histogram_quantiles("phi", 0.95, sum by (vmrange) (increase(cube_apm_latency_bucket{...}[5m])))

  • Latency values are returned in SECONDS (0.05 = 50ms)

Example queries:

  • P95 latency: histogram_quantiles("phi", 0.95, sum by (vmrange, service) (increase(cube_apm_latency_bucket{service="MyService", span_kind="server"}[5m])))

  • Error rate: sum by (service) (increase(cube_apm_calls_total{status_code="ERROR"}[1h])) / sum by (service) (increase(cube_apm_calls_total[1h])) * 100

  • List services: count by (service) (cube_apm_calls_total{env="UNSET"})

  • Request count: sum by (service) (increase(cube_apm_calls_total{span_kind=~"server|consumer"}[1h]))

Inputs: time (required), query (required), step.

query_metrics_rangeA

Execute a range query against CubeAPM metrics over a time range. Returns time series data. Uses PromQL-compatible syntax (VictoriaMetrics flavor).

IMPORTANT - CubeAPM Metric Naming Conventions:

  • Metrics use "cube_apm_" prefix (e.g., cube_apm_calls_total, cube_apm_latency_bucket)

  • Service label is "service" (NOT "server" or "service_name")

  • Common labels: env, service, span_kind (server|client|consumer|producer), status_code, http_code

HISTOGRAM QUERIES (P50, P90, P95, P99):

  • CubeAPM uses VictoriaMetrics-style histograms with "vmrange" label (NOT Prometheus "le" buckets)

  • Use histogram_quantiles() function instead of histogram_quantile()

  • Syntax: histogram_quantiles("phi", 0.95, sum by (vmrange, service) (increase(cube_apm_latency_bucket{...}[5m])))

  • Latency values are returned in SECONDS (0.05 = 50ms)

Example range query for P95 over time: histogram_quantiles("phi", 0.95, sum by (vmrange, service) (increase(cube_apm_latency_bucket{service="MyService", span_kind="server"}[5m])))

Inputs: end (required), step (required), query (required), start (required).

search_tracesA

Search for traces in CubeAPM matching the specified criteria. Returns trace snippets with key spans.

IMPORTANT - Required Parameters:

  • query, env, service, start, end are ALL REQUIRED by CubeAPM API

  • Use query="*" for wildcard search

  • Use env="UNSET" if environment is not configured

  • Service names are case-sensitive (e.g., "Kratos-Prod" not "kratos")

TRACE QUERY SYNTAX: The query parameter supports pipe syntax similar to LogsQL: {stream_selector} | pipe1 | pipe2

Stream selectors filter spans: {service="Kratos-Prod"} {service="Kratos-Prod", span_kind="server"} {http_code=~"5.."}

PIPE OPERATORS — same as LogsQL pipes: | copy, | drop, | extract_regexp, | join, | keep, | limit, | math, | rename, | replace, | replace_regexp, | sort, | stats as alias [by (group_fields)], | unpack_json

STATS FUNCTIONS (for aggregate trace analysis): avg(field) — arithmetic mean count() — total matching spans count_uniq(field) — distinct values max(field) — maximum value median(field) — median value min(field) — minimum value quantile(p, field) — p-th quantile (e.g., quantile(0.95, duration)) sum(field) — sum of values

IMPORTANT: Duration in traces is in MILLISECONDS. IMPORTANT: "p95" is NOT a valid function — use quantile(0.95, duration).

Example queries: Wildcard: query="*" P95 latency: query='{service="Kratos-Prod", span_kind="server"} | stats quantile(0.95, duration) as p95_latency' Error count by endpoint: query='{service="Kratos-Prod", status_code="ERROR"} | stats count() as errors by (http_route)' Slow spans: query='{service="Kratos-Prod"} | sort by (duration) desc | limit 20'

Optional filters (applied in addition to query):

  • spanKind: server, client, consumer, producer

  • sortBy: duration (to find slow traces)

To discover available service names, first query metrics: count by (service) (cube_apm_calls_total{env="UNSET"})

Inputs: end (required), start (required), service (required), env, +4 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 6 tools

    Disambiguation4/5

    Each tool targets a distinct telemetry type or operation: logs, trace search, trace fetch, instant metrics, range metrics, and metric ingestion. The only mild overlap is between query_metrics_instant and query_metrics_range, but the temporal distinction is standard and clearly described. search_traces versus get_trace is also well separated by search-vs-fetch semantics.

    Naming Consistency4/5

    All names use snake_case and are verb-first, which is highly consistent. The minor deviation is using both 'query_' and 'search_' verbs for similar read operations, plus multi-word qualifiers like '_instant', '_range', and '_prometheus', but the pattern remains easy to predict and read.

    Tool Count5/5

    Six tools is well-scoped for an APM server covering logs, traces, metrics, and metric ingestion. Each tool has a clear purpose and the surface does not feel bloated or excessively thin.

    Completeness4/5

    The core observability workflows are covered: querying logs, searching and fetching traces, querying metrics, and ingesting metrics. Minor gaps include no explicit service/environment discovery tool or log/trace ingestion endpoint, but agents can work around these using wildcard queries and metric label counts as described.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      D
      maintenance
      Enables AI agents to query Prometheus metrics and Loki logs for intelligent alert investigation and troubleshooting. Provides service discovery, metric querying, log searching, and correlation tools to help identify root causes of issues.
      9
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to query and analyze data from Cube.js analytics platforms, allowing natural language access to cubes, measures, dimensions, and complex analytics queries.
      9
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants and LLMs to query SigNoz observability data (metrics, traces, logs, alerts, dashboards) using natural language.
      132
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to interact directly with Cube's API, allowing them to list cubes/views and metadata, run queries, and retrieve generated SQL.
      MIT