# Last9 MCP

> Connect your AI agent to production observability data for intelligent debugging and issue resolution.

Source: https://last9.io/docs/integrations/mcp/

Last9's MCP server transforms your development workflow by bringing production observability directly into your IDE. Ask your AI assistant questions like "What's causing the recent spike in errors?" or "Show me the slowest endpoints from the last hour" and get instant insights with suggested fixes.

## What is Model Context Protocol?

[MCP](https://modelcontextprotocol.io/introduction) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a universal adapter for AI applications — it provides a standardized way to connect AI models to different data sources and tools.

Using MCP, AI agents in your IDE (Cursor, Windsurf, VS Code, Claude Code) or Claude Desktop can access your observability data in Last9's Telemetry Data Platform to provide intelligent assistance based on real production context.

## Why use Last9 MCP?

**Turn production issues into local solutions.** The Last9 MCP server brings real-time production context directly to your development environment, enabling AI agents to deliver _conversational observability_ through:

- **Debug with production context**: Analyze exceptions, performance issues, and service dependencies using actual production data
- **Suggest intelligent fixes**: Get code suggestions based on real observability signals, not just theoretical best practices
- **Eliminate "works on my machine"**: Bridge the gap between local development and production reality with agentic dx

Gone are the days of switching between multiple tools to understand production issues. This represents the shift from traditional monitoring to an AI-native approach. Read more in our [launch blog post](/blog/launching-last9-mcp-server/) and our thoughts on [why your observability stack needs to speak agent](/blog/from-cloud-native-to-ai-native-why-your-observability-stack-needs-to-speak-agent/).

## Example Use Cases

### Debug Production Exceptions

```
"I'm seeing errors in production. Can you help me understand what's happening?"
```

_Agent uses `get_exceptions` and `get_service_performance_details` to analyze the issue_

### Performance Investigation

```
"My API response times seem slow. What's causing the latency?"
```

_Agent uses `get_service_dependency_graph` and `prometheus_range_query` to identify bottlenecks_

### Trace Waterfall Analysis

```
"I have a slow trace ID — show me where the time is going."
```

_Agent uses `get_trace_waterfall` to return a bounded parent/child waterfall with millisecond timing, self-time, and the slowest spans_

### Compare Slow vs Fast Spans

```
"What attributes differ between slow and fast requests on checkout-service?"
```

_Agent uses `get_trace_attribute_deviations` with `comparison_mode: latency` to rank attribute values that correlate with slow spans_

### Detect Performance Regressions

```
"What services regressed in the last hour compared to the previous hour?"
```

_Agent uses `get_apm_service_deviations` to compare the current window against an equal-duration baseline and return regressions/improvements leaderboards_

### Log Analysis for Issues

```
"Find error logs from the user-service in the last 30 minutes"
```

_Agent uses `get_logs` with service and severity filters to surface relevant logs_

### Correlate Incidents with Deployments

```
"We had performance issues around 2pm. Were there any deployments around that time?"
```

_Agent uses `get_change_events` to check for recent deployments and `get_service_performance_details` to analyze the correlation_

### Database Performance Investigation

```
"Which databases are my services hitting, and what are the slowest PostgreSQL queries in prod right now?"
```

_Agent uses `get_databases`, `get_database_queries`, `get_database_slow_queries`, and `get_database_server_metrics` to connect database load, slow queries, and exporter-backed server health_

### Auto-Correcting Typos in Entity Names

```
"Can you look up last9-apiii logs"
```

_Agent uses `did_you_mean` to detect the typo and surface the closest match ("last9-api", 74%), then confirms before fetching logs_

![did_you_mean in action — agent detects "last9-apiii" as a typo and suggests "last9-api" (74% match)](../../../../../assets/content/docs/integrations/ai/mcp/did-you-mean.png)

## Prerequisites

Before setting up Last9 MCP, ensure you have:

- Observability data flowing to Last9 via [OpenTelemetry integration](https://app.last9.io/integrations?integration=OpenTelemetry)
- One of the supported clients: Claude Code, Cursor, VS Code, Windsurf, Claude.ai / Claude Desktop, Codex CLI, or ChatGPT
- A Last9 account (any role — no admin access required)

## Setup

:::tip[Recommended: use the hosted MCP server]
No binary to install, no token to manage. The hosted MCP server at `https://app.last9.io/api/v4/organizations/<org_slug>/mcp` authenticates via OAuth — each developer connects with their own Last9 account. Self-hosting is only needed for air-gapped or custom deployments.
:::

1.  **Find your organization slug**

    Your org slug is in your Last9 URL when logged in:

    ```
    https://app.last9.io/<org_slug>/...
    ```

    For example, if your URL is `https://app.last9.io/acme/...`, your slug is `acme`.

2.  **Configure your IDE**

    No local binary needed — connect directly to Last9's hosted MCP server. Authentication happens via OAuth — see the IDE-specific steps below to connect and authorize.

**Claude Code**

          1. Run the following command to add the Last9 MCP server:

             ```bash
             claude mcp add --transport http last9 https://app.last9.io/api/v4/organizations/<org_slug>/mcp

             ```

          2. Replace `<org_slug>` with your organization slug
          3. Type `/mcp` in Claude Code, select the **last9** server, and authenticate
          4. After authorizing, all Last9 tools become available in your session

**Cursor**

          1. Open Cursor → **Settings** → **Cursor Settings** → **MCP**
          2. Click **Add New MCP Server**
          3. Add the configuration:

             ```json
             {
               "mcpServers": {
                 "last9": {
                   "type": "http",
                   "url": "https://app.last9.io/api/v4/organizations/<org_slug>/mcp"
                 }
               }
             }

             ```

          4. Replace `<org_slug>` with your organization slug
          5. Save — Cursor will show a **Connect** button next to the server
          6. Click **Connect** → a browser window opens → authorize with your Last9 account

**VS Code**

          > **Note:** MCP support in VS Code is available from v1.99+ and currently in preview. For advanced configuration options, see the [VS Code MCP documentation](https://code.visualstudio.com/docs/copilot/chat/mcp-servers).

          1. Open the Command Palette (`cmd+shift+P` on macOS / `ctrl+shift+P` on Windows/Linux)
          2. Select **MCP: Add Server** → choose **HTTP** as the type
          3. Paste the server URL with your organization slug:

             ```
             https://app.last9.io/api/v4/organizations/<org_slug>/mcp

             ```

          4. Enter `last9` as the server name
          5. Choose **Global** or **Workspace** scope
          6. VS Code will prompt you to authenticate — complete the OAuth flow in your browser

**Windsurf**

          1. Open Windsurf → **Settings** → **Cascade** → click **Open MCP Marketplace**
          2. Click the gear icon (⚙) to open `mcp_config.json`
          3. Add the Last9 MCP server configuration:

             ```json
             {
               "mcpServers": {
                 "last9": {
                   "serverUrl": "https://app.last9.io/api/v4/organizations/<org_slug>/mcp"
                 }
               }
             }

             ```

          4. Replace `<org_slug>` with your organization slug
          5. Save the file — Windsurf will prompt you to authenticate
          6. Complete the OAuth flow in your browser to authorize Last9 access

**Claude.ai / Claude Desktop**

          > **Note:** Admin access to your Claude organization is required to add custom connectors. For more details, see the [Claude custom connectors guide](https://support.claude.com/en/articles/11175166-get-started-with-custom-connectors-using-remote-mcp).

          1. Go to **Settings** → **Connectors** → click **Add custom connector**
          2. Enter `last9` as the **Name**
          3. Paste the **Remote MCP server URL** with your organization slug:

             ```
             https://app.last9.io/api/v4/organizations/<org_slug>/mcp

             ```

          4. Click **Add**
          5. Go to **Customize** → **Connectors** → select **last9** under "Not connected"
          6. Click **Connect** and complete the OAuth flow in your browser

**Codex CLI**

          **Option A — CLI command (recommended):**

          ```bash
          codex mcp add last9 --url https://app.last9.io/api/v4/organizations/<org_slug>/mcp
          ```

          **Option B — manual config** in `~/.codex/config.toml`:

          ```toml
          [[mcp_servers]]
          name = "last9"
          type = "http"
          url = "https://app.last9.io/api/v4/organizations/<org_slug>/mcp"
          ```

          Replace `<org_slug>` with your organization slug, then start a session — Codex will prompt you to authenticate via browser OAuth and handles token management automatically.

**ChatGPT**

          > **Note:** Requires a paid ChatGPT plan (Plus, Pro, Team, Enterprise, or Edu). Free plans do not support custom MCP connectors.

          1. **Enable Developer Mode**

             Go to **Settings** → **Connectors** → **Advanced settings** → toggle on **Developer Mode**.

          2. **Create a connector**

             Go to **Settings** → **Connectors** → click **Create**.

          3. Fill in the connector details:

             - **Name:** `Last9`
             - **Description:** `Query Last9 production observability data — logs, traces, metrics, alerts, and deployments`
             - **Connector URL:**

               ```
               https://app.last9.io/api/v4/organizations/<org_slug>/mcp

               ```

             Replace `<org_slug>` with your organization slug.

          4. Click **Create** → ChatGPT will open an OAuth authorization window → log in with your Last9 account and authorize access.

          5. In any ChatGPT conversation, Last9 tools will now be available. Try: _"What exceptions occurred in the last hour?"_

3.  **Verify the connection**

    Once configured, your AI agent will have access to Last9 tools. Try asking: _"What exceptions occurred in the last hour?"_ or _"Show me the performance summary for my services."_

## Using Last9 MCP with OpenAI's Responses API

If you are building an AI application on top of OpenAI's **Responses API** or **Agents SDK**, you can connect it to Last9's MCP server to give your agent access to live production data.

```python
from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-4o",
    tools=[
        {
            "type": "mcp",
            "server_label": "last9",
            "server_url": "https://app.last9.io/api/v4/organizations/<org_slug>/mcp",
            "headers": {
                "Authorization": "Bearer <your_api_key>"
            },
        }
    ],
    input="Why is payment-service throwing 500s right now?",
)

print(response.output_text)
```

Replace `<org_slug>` with your organization slug and `<your_api_key>` with an MCP token from [Query Tokens](https://app.last9.io/control-plane/query-tokens) (Token Type: **Client** → Client Type: **MCP**).

The agent can then call any of Last9's tools (`get_service_performance_details`, `get_exceptions`, `get_alerts`, etc.) automatically as part of answering the question.

:::tip
This is useful for building internal SRE copilots, incident bots, or on-call assistants that need real production context alongside OpenAI's reasoning capabilities.
:::

## Advanced: Self-hosting the MCP Server

If you need to run the MCP server locally (e.g., for air-gapped environments or custom deployments), use the open-source binary instead.

**Install:**

```bash
# Homebrew (macOS/Linux)
brew tap last9/tap && brew install last9-mcp

# NPM (cross-platform, including Windows)
npm install -g @last9/mcp-server@latest
```

You can also download platform-specific binaries from [GitHub Releases](https://github.com/last9/last9-mcp-server/releases/latest).

**Get a Refresh Token** (admin required) from [API Access](https://app.last9.io/settings/api-access).

:::tip
**One token per developer.** Create a separate refresh token for each individual developer rather than sharing one token across the team. This gives you a clear audit trail and lets you revoke access for a specific person without affecting others.
:::

**Configure your IDE** using the local binary path and `LAST9_REFRESH_TOKEN`:

```json
{
  "mcpServers": {
    "last9": {
      "command": "/opt/homebrew/bin/last9-mcp",
      "env": {
        "LAST9_REFRESH_TOKEN": "<your_refresh_token>"
      }
    }
  }
}
```

For VS Code, wrap in `"mcp": { "servers": { ... } }` and add `"type": "stdio"`. See the [last9-mcp-server README](https://github.com/last9/last9-mcp-server) for full configuration options.

**Toolsets (optional).** By default the server exposes every tool. For automation hosts that only need investigation workflows, set `LAST9_TOOLSETS` (alias `LAST9_MCP_TOOLSETS`) or pass `--toolsets` to limit what appears in `tools/list`:

```json
{
  "mcpServers": {
    "last9": {
      "command": "/opt/homebrew/bin/last9-mcp",
      "env": {
        "LAST9_REFRESH_TOKEN": "<your_refresh_token>",
        "LAST9_TOOLSETS": "investigate"
      }
    }
  }
}
```

Valid toolset names: `logs`, `traces`, `metrics`, `alerts`, `dashboards`, `investigate`, and `all`. The value is comma-separated; unset, empty, or `all` serves the full surface. Unknown names fail fast at startup. The `metrics` pack alone does not include `list_datasources` or `did_you_mean` — use `investigate` or combine toolsets when you need those discovery helpers.

**Reference resources.** Long query manuals for `get_logs`, `get_traces`, `get_service_logs`, and `prometheus_range_query` are served as MCP resources under `last9://reference/*` (`logjson`, `tracejson`, `service_logs`, `metrics`). Tool descriptions carry the critical query-construction rules; clients that need the full DSL reference should fetch these via `resources/list` and `resources/read`. Discover org-specific attribute names with `get_log_attributes_for_pipeline` and `get_trace_attributes_for_pipeline` — they are no longer injected into tool descriptions.

## Available Tools

Your AI agent can now access these Last9 capabilities:

{/* prettier-ignore-start */}

### Observability & APM

1. **`get_exceptions`**: Get server-side exceptions over a specified time range. For log-heavy services, the tool may continue to logs via aggregate-then-read: aggregate to isolate the hot logger, then read that logger's lines with a `limit` to reach the error text.

   <details>
      <summary>View parameters</summary>
      - `limit` (integer, optional): Maximum number of exceptions to return. Default: 20
      - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
      - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to use lookback_minutes
      - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to default to current time
      - `service_name` (string, optional): Filter by service name
      - `span_name` (string, optional): Name of the span to filter by
      - `env` (string, optional): Filter by environment
   </details>

2. **`get_service_summary`**: Get service summary over a given time range. Includes service name, environment, throughput, error rate, and response time. All values are p95 quantiles over the time range.

   <details>
      <summary>View parameters</summary>
      - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: end_time_iso - 1 hour
      - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
      - `env` (string, optional): Environment to filter by. Default: 'prod'
   </details>

3. **`get_service_environments`**: Get available service environments within a specified time range.

   <details>
      <summary>View parameters</summary>
      - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: now - 60 minutes
      - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time

      Note: Returns an array of environments that can be used with other APM tools. If the array is empty, use an empty string `""` for environment parameters.
   </details>

4. **`get_service_performance_details`**: Get detailed performance metrics for a specific service.

   <details>
     <summary>View parameters</summary>
     - `service_name` (string, required): Service name
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Now - 60 minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
     - `env` (string, optional): Environment. Default: 'prod'
   </details>

5. **`get_service_operations_summary`**: Get operations summary for a service like HTTP endpoints, database queries, messaging producer, and HTTP client calls.

   <details>
     <summary>View parameters</summary>
     - `service_name` (string, required): Service name
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Now - 60 minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
     - `env` (string, optional): Environment. Default: 'prod'
   </details>

6. **`get_service_dependency_graph`**: Get service dependency graph showing incoming and outgoing dependencies, including infra. Includes throughput, response times and error rates.

   <details>
     <summary>View parameters</summary>
     - `service_name` (string, optional): Name of the service
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: now - 60 minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
     - `env` (string, optional): Environment. Default: 'prod'
   </details>

7. **`get_change_events`**: Retrieves change events from the `last9_change_events` Prometheus metric to help correlate deployments and system modifications with performance issues or incidents.

   <details>
     <summary>View parameters</summary>
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Defaults to now - lookback_minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Defaults to current time
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `service_name` (string, optional): Filter by service name
     - `env` (string, optional): Environment filter
     - `event_name` (string, optional): Specific event type filter (use available_event_names to see valid values)

     **Returns**:
     - `available_event_names`: List of all available event types that can be used for filtering
     - `change_events`: Array of timeseries data with metric labels and timestamp-value pairs
     - `count`: Total number of change events returned
     - `time_range`: Start and end time of the query window

     **Common event types**: deployment, config_change, rollback, scale_up/scale_down, restart, upgrade/downgrade, maintenance, backup/restore, health_check, certificate, database

     **Best practices**:
     1. First call without event_name to get available_event_names
     2. Use exact event name from available_event_names for the event_name parameter
     3. Combine with other filters (service_name, env, time) for precise results
   </details>

8. **`get_apm_service_deviations`**: Compare APM performance across a current window and an equal-duration baseline. Use for regressions/improvements, incident-vs-prior-period comparisons, and fleet deviation discovery.

   <details>
     <summary>View parameters</summary>
     - `service_name` (string, optional): Omit for fleet scope; provide for one service and its operation correlations
     - `env` (string, optional): Filter to one deployment environment
     - `lookback_minutes` (integer, optional): Current window length ending now. Default: 60
     - `start_time_iso` / `end_time_iso` (string, optional): Explicit current window
     - `baseline_start_time_iso` / `baseline_end_time_iso` (string, optional): Equal-duration baseline window; defaults to the immediately preceding period
     - `datasource` (string, optional): Select one datasource for the comparison
     - `max_services` / `max_operations` (integer, optional): Default: 10, maximum: 10

     **Returns**: `regressions` and `improvements` leaderboards, `evidence_quality`, Apdex reconciliation, and a terminal `outcome`. Treat `stable`, `no_data`, and `unsupported_workload_shape` as terminal — answer from the result without automatic follow-up tool calls. V1 supports server-request workloads.
   </details>

### Database Investigation

1. **`get_databases`**: Discover databases observed in trace data across your infrastructure. Returns database type, host, throughput, p95 latency, error rate, and how many services are using each database.

   <details>
     <summary>View parameters</summary>
     - `env` (string, optional): Deployment environment to filter by
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `start_time_iso` (string, optional): Start time in RFC3339 format. Overrides lookback_minutes
     - `end_time_iso` (string, optional): End time in RFC3339 format

     **Useful for**:
     - Discovering which databases your services are talking to
     - Ranking database backends by throughput, latency, and error rate
     - Identifying shared databases used by many services
   </details>

2. **`get_database_slow_queries`**: Find the slowest database operations from traces and, when available, slow-query logs. Results are sorted by duration descending.

   <details>
     <summary>View parameters</summary>
     - `db_system` (string, optional): Database system filter such as `postgresql`, `mysql`, `mongodb`, or `redis`
     - `host` (string, optional): Database host filter using `net_peer_name`
     - `service_name` (string, optional): Calling service name filter
     - `env` (string, optional): Deployment environment filter
     - `min_duration_ms` (number, optional): Minimum query duration in milliseconds
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `start_time_iso` (string, optional): Start time in RFC3339 format
     - `end_time_iso` (string, optional): End time in RFC3339 format
     - `limit` (integer, optional): Maximum number of slow queries to return. Default: 20

     **Returns**:
     - Query source (`trace` or `log`)
     - Trace and span IDs when available
     - Service name, database system, query pattern or statement, duration, status, and timestamp
     - Slow-query metadata from logs such as plan summaries or rows examined when present
   </details>

3. **`get_database_queries`**: Get the top query patterns for a specific database, aggregated by operation. Helps identify hot, slow, or error-prone query shapes.

   <details>
     <summary>View parameters</summary>
     - `db_system` (string, required): Database system such as `postgresql`, `mysql`, `mongodb`, or `redis`
     - `host` (string, optional): Database host filter using `net_peer_name`
     - `env` (string, optional): Deployment environment filter
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `start_time_iso` (string, optional): Start time in RFC3339 format
     - `end_time_iso` (string, optional): End time in RFC3339 format
     - `sort_by` (string, optional): Sort by `throughput` (default), `latency`, or `errors`

     **Returns**:
     - `span_name`
     - `calls_per_min`
     - `avg_latency_ms`
     - `p95_latency_ms`
     - `error_rate_pct`
   </details>

4. **`get_database_server_metrics`**: Discover server-side database metrics from exporters and query key health signals such as connection utilization, cache hit ratios, replication lag, and throughput.

   <details>
     <summary>View parameters</summary>
     - `db_system` (string, optional): Focus on a specific database type. Supported values: `postgresql`, `mysql`, `oracle`, `redis`, `mongodb`, `mssql`, `elasticsearch`
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `start_time_iso` (string, optional): Start time in RFC3339 format
     - `end_time_iso` (string, optional): End time in RFC3339 format

     **Notes**:
     - If `db_system` is omitted, the tool auto-discovers available exporters
     - Requires database exporters such as `postgres_exporter`, `mysqld_exporter`, `redis_exporter`, or `mongodb_exporter` to be scraped into Prometheus or Levitate
     - Complements client-side trace data with server-side health metrics
   </details>

### Prometheus Integration

1. **`list_datasources`**: List all available datasources configured for your organization. Use this before Prometheus queries to discover valid datasource names.

   <details>
     <summary>Returns</summary>
     - Array of datasource objects, each with:
       - `name`: datasource identifier to pass via the `datasource` parameter in Prometheus tools
       - `is_default`: `true` for the datasource used when no `datasource` is specified
   </details>

2. **`prometheus_range_query`**: Execute Prometheus range queries for metrics over a time period.

   <details>
     <summary>View parameters</summary>
     - `query` (string, required): Range query to execute
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: now - 60 minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
   </details>

3. **`prometheus_instant_query`**: Execute Prometheus instant queries for metrics at a specific point in time.

   <details>
     <summary>View parameters</summary>
     - `query` (string, required): Instant query to execute
     - `time_iso` (string, optional): Time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
   </details>

4. **`prometheus_label_values`**: Get all label values for a specific label name.

   <details>
     <summary>View parameters</summary>
     - `match_query` (string, required): Valid PromQL filter query
     - `label` (string, required): Label to get values for
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: now - 60 minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
   </details>

5. **`prometheus_labels`**: Get all available label names.

   <details>
     <summary>View parameters</summary>
     - `match_query` (string, required): Valid PromQL filter query
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Default: now - 60 minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Default: Current time
   </details>

### Log Management

1. **`get_logs`**: Retrieves filtered log entries by service name and/or severity. Uses advanced v2 logs API with physical index optimization for better performance.

   <details>
     <summary>View parameters</summary>
     - `service_name` (string, required): Name of the target service to get logs for
     - `severity` (string, optional): Severity level of the logs to get (automatically converted to severity_filters format)
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to use lookback_minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to default to current time
     - `limit` (integer, optional): Maximum logs to return. Default: 20
     - `env` (string, optional): Environment filter. Use `get_service_environments` to get available environments
   </details>

2. **`get_service_logs`**: Retrieves raw log entries for a specific service with advanced filtering capabilities. Useful for debugging issues, monitoring service behavior, and analyzing specific log patterns.

   <details>
     <summary>View parameters</summary>
     - `service_name` (string, required): Name of the service to get logs for
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `limit` (integer, optional): Maximum log entries to return. Default: 20
     - `env` (string, optional): Environment to filter by. Use `get_service_environments` to get available environments
     - `severity_filters` (array, optional): Filter by log severity levels (e.g., `["error", "warn"]`). Uses OR logic
     - `body_filters` (array, optional): Filter by log message content (e.g., `["timeout", "failed"]`). Uses OR logic
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS)
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS)

     **Filtering behavior:**
     - Multiple filter types are combined with AND logic (service AND severity AND body)
     - Each filter array uses OR logic (matches any pattern in the array)
   </details>

3. **`get_drop_rules`**: Gets drop rules for logs, which determine what logs get filtered out from reaching Last9.

4. **`add_drop_rule`**: Adds a new drop rule to filter out specific logs at Last9 Control Plane

   <details>
     <summary>View parameters</summary>
     - `name` (string, required): Name of the drop rule
     - `filters` (array, required): List of filter conditions to apply. Each filter has:
       - `key` (string, required): The key to filter on. Only attributes and resource.attributes keys are supported. For resource attributes, use format: `resource.attributes[key_name]` and for log attributes, use format: `attributes[key_name]`. Double quotes in key names must be escaped
       - `value` (string, required): The value to filter against
       - `operator` (string, required): The operator used for filtering. Valid values: "equals", "not_equals"
     - `conjunction` (string, required): The logical conjunction between filters. Valid values: "and"
   </details>

5. **`get_log_attributes`**: Returns available log attribute names existing during the specified time window, grouped by category. Useful for discovering what attributes can be used for filtering and querying logs.

   <details>
     <summary>View parameters</summary>
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now for the time window. Default: 15
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to use lookback_minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to default to current time
     - `region` (string, optional): AWS region to query. Leave empty to use default from configuration

     **Returns**: Log attributes grouped into two categories:
     - Log Attributes: Standard log fields like service, severity, body, level, etc.
     - Resource Attributes: Resource-related fields prefixed with "resource_" like resource_k8s.pod.name, resource_service.name, etc.
   </details>

6. **`get_log_attributes_for_pipeline`**: Returns log fields present after applying a pipeline, each with the exact `filter_field` for `get_logs` conditions. Scoped to your pipeline — use after a filter stage and before building `get_logs` queries.

   <details>
     <summary>View parameters</summary>
     - `logjson_query` (array, required): In-progress pipeline (e.g. a `ServiceName` filter stage)
     - `lookback_minutes` (integer, optional): Default: 15
     - `start_time_iso` / `end_time_iso` (string, optional): RFC3339 time bounds

     **Returns**: Each entry includes `name`, `filter_field` (use directly in `get_logs`), `hint`, and optional `source`/`sample_coverage`. Body-derived fields (`source: body`) require a parse stage before filtering.
   </details>

### Traces Management

1. **`get_traces`**: Execute advanced trace queries using JSON pipeline syntax for complex filtering and aggregation. This tool provides powerful querying capabilities for traces using a pipeline-based approach with filters, aggregations, and transformations.

   <details>
     <summary>View parameters</summary>
     - `tracejson_query` (array, required): JSON pipeline query for traces. Fetch the full DSL from the `last9://reference/tracejson` resource or discover fields with `get_trace_attributes_for_pipeline` first
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS)
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS)
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `limit` (integer, optional): Maximum number of traces to return. Default: 20. Range: 1-100

     **Notes:**
     - Existence checks use `{"$neq": [field, ""]}` — `$exists` and `$notnull` are not supported
     - `aggregate` and `window_aggregate` pipelines run as a single request (not chunked)
     - A `408` response means the window is too wide — narrow the time range and retry
   </details>

2. **`get_service_traces`**: Retrieve traces from Last9 by trace ID or service name. Get specific traces either by providing a trace ID for a single trace, or by providing a service name to get all traces for that service within a time range.

   <details>
     <summary>View parameters</summary>
     - `trace_id` (string, optional): Specific trace ID to retrieve. Cannot be used with service_name
     - `service_name` (string, optional): Name of service to get traces for. Cannot be used with trace_id
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now. Default: 60
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to use lookback_minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to default to current time
     - `limit` (integer, optional): Maximum number of traces to return. Default: 10. Range: 1-100
     - `env` (string, optional): Environment filter. Use `get_service_environments` to get available environments

     **Usage rules:**
     - Exactly one of `trace_id` or `service_name` must be provided (not both, not neither)
     - Time range filtering only applies when using `service_name`

     Returns trace data including trace IDs, spans, duration, timestamps, and status information.
   </details>

3. **`get_trace_attributes`**: Identify all available trace attributes within a specified time window for use in filtering and querying. Returns the global tag catalog.

   <details>
     <summary>View parameters</summary>
     - `lookback_minutes` (integer, optional): Number of minutes to look back from now for the time window. Default: 15
     - `start_time_iso` (string, optional): Start time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to use lookback_minutes
     - `end_time_iso` (string, optional): End time in ISO format (YYYY-MM-DD HH:MM:SS). Leave empty to default to current time
     - `region` (string, optional): AWS region to query. Leave empty to use default from configuration
   </details>

4. **`get_trace_attributes_for_pipeline`**: Returns trace attributes present after applying a pipeline, each with the exact `filter_field` for `get_traces` conditions. Scoped to your pipeline — use after a filter stage and before filtering on attribute keys.

   <details>
     <summary>View parameters</summary>
     - `tracejson_query` (array, required): In-progress pipeline (e.g. a `ServiceName` filter stage)
     - `lookback_minutes` (integer, optional): Default: 15
     - `start_time_iso` / `end_time_iso` (string, optional): RFC3339 time bounds

     **Returns**: Each entry includes `name`, `semantic_name`, `type`, and `filter_field` ready to use in `get_traces` conditions.
   </details>

5. **`get_trace_attribute_values`**: Fetch distinct values for a single trace attribute. Use after `get_trace_attributes` or `get_trace_attributes_for_pipeline` to see what values exist (environments, HTTP methods, team names, etc.).

   <details>
     <summary>View parameters</summary>
     - `attribute` (string, required): Tag name in raw API form (`resource_department`), filter syntax (`resources['department']`), or semantic form
     - `tracejson_query` (array, optional): Pipeline to scope values to a filtered slice of spans; omit for global values
     - `lookback_minutes` (integer, optional): Default: 15
     - `start_time_iso` / `end_time_iso` (string, optional): RFC3339 time bounds

     **Returns**: Canonical `filter_field` plus example condition for use in `get_traces`.
   </details>

6. **`get_trace_waterfall`**: Retrieve one exact trace as a bounded parent/child waterfall with millisecond timing, interval-correct self-time, slowest spans, and largest self-time contributors. Does not compute a critical path or claim root cause.

   <details>
     <summary>View parameters</summary>
     - `trace_id` (string, required): Exact trace ID
     - `environment` (string, optional): Exact deployment environment
     - `start_time_iso` / `end_time_iso` (string, optional): RFC3339 time bounds
     - `lookback_minutes` (integer, optional): Default: 4320 (for exact trace lookup)
     - `selected_span_id` (string, optional): Include attributes, events, and links for this span only
     - `max_spans` (integer, optional): Default: 500, maximum: 1000

     **Returns**: An `investigation-evidence/v1` envelope with the waterfall under `data`, plus `evidence_quality`, truncation warnings, and graph integrity warnings (cycles, orphans, duplicate spans). An empty result has `evidence_quality: insufficient` — widen the window or verify the trace ID before concluding the trace does not exist.
   </details>

7. **`get_trace_attribute_deviations`**: Compare attribute-value distributions between two bounded span cohorts and rank supported differences. Use for slow vs fast, error vs non-error, or two equal-duration time windows. Results describe correlation, not cause.

   <details>
     <summary>View parameters</summary>
     - `comparison_mode` (string, required): `latency`, `errors`, or `time`
     - `service_name` (string, required): Exact service name
     - `environment` (string, required): Exact `deployment.environment` value
     - `operation` (string, optional): Exact operation/span name
     - `filters` (array, optional): Trace JSON filter conditions — discover valid fields with `get_trace_attributes_for_pipeline` first
     - `candidate_attributes` (array, optional): Up to 8 attribute names; omit for bounded auto-discovery
     - `latency_threshold_ms` (number, required for `latency` mode): Positive threshold in milliseconds
     - `start_time_iso` / `end_time_iso` (string, optional): Target window in RFC3339
     - `lookback_minutes` (integer, optional): Alternative target lookback ending now. Default: 15, maximum: 15
     - `baseline_start_time_iso` / `baseline_end_time_iso` (string, required for `time` mode): Non-overlapping baseline window equal in duration to the target window
     - `minimum_cohort_size` (integer, optional): Default: 100, minimum: 20
     - `limit` (integer, optional): Default: 10, maximum: 10

     **Returns**: Full-denominator shares, percentage-point deltas, representative trace IDs, and `evidence_quality`. Requires the trace-analysis capability to be enabled for your tenant.
   </details>

### Alert Management

1. **`get_alert_config`**: Get all configured alert rules from Last9. Supports typed filters and free-text search.

   <details>
      <summary>View parameters and returns</summary>

      **Optional filters:**
      - `rule_id`, `search_term`, `rule_name`, `severity`, `rule_type` (`static` or `anomaly`)
      - `alert_group_name`, `alert_group_type`, `data_source_name`, `tags`
      - `only_without_notification_channel`: Rules whose alert group has no per-entity channel binding (Alert Studio "Not configured")
      - `notification_channel_types`: Rules with a per-entity channel of any listed type (e.g. `slack`, `email`, `pagerduty`)
      - `notification_channel_names`: Rules with a per-entity channel matching any listed name (AND-combined with other `notification_channel_*` filters on the same binding row)
      - `notification_channel_severities`: Rules with a per-entity channel matching any listed severity (`breach` or `threat`)

      **Returns per rule:**
      - Alert rule ID, name, primary indicator, entity ID, state, severity, algorithm
      - Alert group `name`, `data_source`, and `tags` when resolved
      - **Notification Channels**: configured types in dashboard order, or "Not configured"
      - **Notification Channel Bindings**: each binding row (type, name, severity) with snooze/in_use flags
      - Timestamps for creation/updates
   </details>

2. **`get_alerts`**: Get currently active alerts from the Last9 monitoring system.

   <details>
   <summary>View parameters and returns</summary>

   Parameters:
   - `timestamp` (integer, optional): Unix timestamp. Default: current time
   - `window` (integer, optional): Time window in seconds. Default: 900 seconds, range: 60-3600

   Returns:
   - Alert rule details
   - Alert state and severity
   - Firing timestamps
   - Rule configurations
   - Metric degradation information
   - Group labels and annotations
   </details>

3. **`get_notification_channels`**: Get all notification channel configurations from Last9.

   <details>
      <summary>Returns</summary>
      Returns all notification channels as a table with the following columns:
      - `id`, `name`, `type`
      - `service_fqid`: per-entity alert-group binding ID
      - `global`: whether the channel applies to all services
      - `in_use`: whether the channel is actively used in an alert rule
      - `send_resolved`: whether resolved alerts trigger a notification (`true` / `false` / `null` if not set)
      - `snoozed_until`: UTC timestamp if the channel is snoozed, `-` otherwise
      - `severity`, `priority`
      - `services`: comma-separated `namespace/name` pairs, `-` if the channel is global
   </details>

4. **`get_alert_rule_state`**: Get historical firing state (1/0) per alert rule over a time range, grouped by `rule_id`.

   <details>
      <summary>View parameters</summary>
      - `start_time` (integer, required): Unix epoch start of the range (inclusive)
      - `end_time` (integer, required): Unix epoch end of the range (inclusive)
      - `step` (integer, required): Resolution in seconds between samples
      - `alert_group_id` (string, optional): Filter by alert group ID
      - `rule_name` (string, optional): Regex filter on rule name
      - `alert_group_name` (string, optional): Regex filter on alert group name
      - `label_filters` (string, optional): Comma-separated `key=value` label filters
      - `state` (string, optional): Filter by state (e.g. `firing`)

      **Returns**: JSON map of `rule_id` → `[{timestamp, is_firing}]`. Sample count is capped at 100.
   </details>

### Custom Dashboards

1. **`list_dashboards`**: List all custom dashboards in your Last9 organization.

   <details>
     <summary>Returns</summary>
     - JSON array of dashboard summaries: `id`, `name`, and metadata
     - `reference_url` in MCP metadata linking to the dashboards index in the Last9 UI
   </details>

2. **`get_dashboard`**: Get the full definition of a custom dashboard by ID.

   <details>
     <summary>View parameters and returns</summary>

     Parameters:
     - `id` (string, required): Dashboard UUID
     - `region` (string, optional): Region for panel query population. Defaults to configured datasource region

     Returns:
     - Full dashboard JSON including `name`, `panels[]`, and `metadata`
     - Each panel includes `layout`, `visualization.type`, and `queries[]`
     - `reference_url` in MCP metadata linking directly to the dashboard
   </details>

3. **`create_dashboard`**: Create a new custom dashboard with panels and queries.

   <details>
     <summary>View parameters</summary>
     - `dashboard` (object, required): Dashboard definition with `name` and `panels[]`. Each panel requires `name`, `version`, `layout` (`x`, `y`, `w`, `h`), `visualization.type`, and `queries[]`
     - `metadata` (object, optional): Dashboard metadata — `_category` and `_type` fields (e.g. `{"_category":"custom","_type":"metrics"}`)

     Returns the created dashboard JSON with its assigned `id` and a `reference_url` to open it in the Last9 UI.
   </details>

4. **`update_dashboard`**: Update an existing custom dashboard by ID.

   <details>
     <summary>View parameters</summary>
     - `id` (string, required): Dashboard UUID to update
     - `dashboard` (object, required): Full replacement dashboard body (same shape as `create_dashboard`)
     - `metadata` (object, optional): Replacement metadata

     Readonly system dashboards return a 403 error. Returns updated dashboard JSON with `reference_url`.
   </details>

5. **`delete_dashboard`**: Delete a custom dashboard by ID.

   <details>
     <summary>View parameters</summary>
     - `id` (string, required): Dashboard UUID to delete

     Readonly system dashboards cannot be deleted. Returns a `reference_url` to the dashboards index.
   </details>

6. **`list_dashboard_snapshots`**: List frozen point-in-time snapshots for a dashboard.

   <details>
     <summary>View parameters</summary>
     - `dashboard_id` (string, required): Dashboard UUID

     **Returns**: Snapshot metadata (`id`, `name`, `expires_at`). Use `get_dashboard_snapshot` for full panel data.
   </details>

7. **`get_dashboard_snapshot`**: Get a frozen dashboard snapshot by ID, including panel data at capture time.

   <details>
     <summary>View parameters</summary>
     - `id` (string, required): Snapshot UUID

     **Returns**: Full frozen snapshot with `dashboard_definition`, `panel_data`, `time_range`, and `variables`.
   </details>

8. **`delete_dashboard_snapshot`**: Delete a frozen dashboard snapshot by ID.

   <details>
     <summary>View parameters</summary>
     - `id` (string, required): Snapshot UUID to delete
   </details>

### Entity Discovery

1. **`did_you_mean`**: Suggests correct entity names when you're unsure of the exact spelling. Use this proactively before querying with a name that might be a typo, abbreviation, or partial match.

   <details>
     <summary>View parameters</summary>
     - `query` (string, required): The name to search for — can be a partial name, misspelling, or abbreviation
     - `type` (string, optional): Restrict suggestions to a specific entity type. Supported values: `service`, `environment`, `host`, `database`, `k8s_deployment`, `k8s_namespace`, `job`

     Returns up to 3 closest matches with similarity scores (0–100%) from the Last9 catalog, covering services, environments, hosts, databases, Kubernetes workloads, and more.

     **When to use:**
     - Before calling `get_service_logs`, `get_service_traces`, `get_service_performance_details`, etc. with a service name that might be misspelled (e.g. `"paymnt-svc"`, `"prod-srvice"`)
     - When a previous tool call returned empty results for a given entity name
     - When the user provides an ambiguous or abbreviated name (e.g. `"the payment thing"` or `"prod env"`)

     **Example results:**
     - `query="paymnt-svc"` → `payment-service (92%, service)`
     - `query="prod"` → `production (89%, environment)`, `prod-eu (82%, environment)`
   </details>

{/* prettier-ignore-end */}

## Demos

1. Fixing a recent exception

   <iframe
     width="100%"
     class="mb-4 aspect-video"
     src="https://www.youtube.com/embed/AQH5xq6qzjI?si=FTrs41Ph2PQkZ1Jq"
     title="YouTube video player"
     frameborder="0"
     allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
     referrerpolicy="strict-origin-when-cross-origin"
     allowfullscreen
   ></iframe>

2. Optimizing logs for a service

   <iframe
     width="100%"
     class="aspect-video"
     src="https://www.youtube.com/embed/0M-XG63ILXk?si=yHXYMugA7v94DIaK"
     title="YouTube video player"
     frameborder="0"
     allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
     referrerpolicy="strict-origin-when-cross-origin"
     allowfullscreen
   ></iframe>

3. Creating an RCA basis recent issues in the production environment

   <iframe
     width="100%"
     class="aspect-video"
     src="https://www.youtube.com/embed/Rcg-77GabAA?si=S_094pspCmmj3-B7"
     title="YouTube video player"
     frameborder="0"
     allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
     referrerpolicy="strict-origin-when-cross-origin"
     allowfullscreen
   ></iframe>

4. Analyze background worker processes

   <iframe
     width="100%"
     class="aspect-video"
     src="https://www.youtube.com/embed/aZxoK4b071g?si=inXxvqj3GBdKUMQ6"
     title="YouTube video player"
     frameborder="0"
     allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
     referrerpolicy="strict-origin-when-cross-origin"
     allowfullscreen
   ></iframe>

## Best Practices

- **Start broad, then narrow**: Ask about overall service health before diving into specific issues
- **Include time context**: Specify time ranges when investigating issues ("in the last hour", "during the outage yesterday")
- **Combine tools**: The agent can correlate data across metrics, logs, traces, and alerts for comprehensive analysis
- **Discover attributes before filtering**: Use `get_log_attributes_for_pipeline` and `get_trace_attributes_for_pipeline` to find valid field names for your scope before building log or trace queries
- **Use trace investigation tools for deep dives**: `get_trace_waterfall` for single-trace timing analysis; `get_trace_attribute_deviations` to compare slow vs fast or error vs non-error cohorts
- **Pin toolsets for automation**: Set `LAST9_TOOLSETS=investigate` on self-hosted deployments when your agent only needs logs, traces, and metrics — this keeps `tools/list` small and reduces description token cost

---

## Troubleshooting

- **"Last9 tools not available"**: Verify your IDE configuration and restart the application
- **OAuth flow not completing**: Ensure you are logged in to [app.last9.io](https://app.last9.io) before authorizing. If redirected to a 404, try logging in to the dashboard first and then re-initiating the OAuth flow from your IDE
- **"Authentication failed"** or **"401 Unauthorized"** (Claude Desktop): Ensure your token is a valid **Refresh Token** from [API Access](https://app.last9.io/settings/api-access)
- **"No data returned"**: Ensure your services are sending telemetry to Last9 and try broader time ranges
- **"Connection issues"**: Double-check:
  - Your org slug is correct (it's in your Last9 URL: `app.last9.io/<org_slug>/...`)
  - The URL format: `https://app.last9.io/api/v4/organizations/<org_slug>/mcp`

Please get in touch with us on [Discord](https://discord.com/invite/Q3p2EEucx9) or [Email](mailto:support@last9.io) if you have any questions.
