# LLM Sleuth MCP Server

LLM Sleuth runs as a remote MCP server, so Claude Code, Cursor, VS Code, Codex, Windsurf, and other MCP clients can compare AI search behavior without writing any HTTP code.

- **URL:** `https://llmsleuth.com/api/mcp`
- **Transport:** Streamable HTTP (stateless). Long comparisons stream progress over SSE.
- **Auth:** your LLM Sleuth API key as `Authorization: Bearer asc_...` (`x-api-key` also works). Get one at https://llmsleuth.com/dashboard.
- **Billing:** the same credits as the HTTP API. Only `run_comparison` spends credits.

## Install

### Claude (claude.ai, Claude Desktop, Claude mobile)

Open **Settings → Connectors → Add custom connector**, then:

- **URL:** https://llmsleuth.com/api/mcp
- **Authentication:** No sign-in. LLM Sleuth uses an API key, not OAuth. Picking a sign-in option fails with an OAuth error.
- **Request header name:** x-api-key
- **Request header value:** Your asc_ API key from llmsleuth.com/dashboard.

Use `x-api-key` rather than `Authorization` so the key never collides with Claude's own sign-in token.

### Claude Code

```bash
claude mcp add --transport http llm-sleuth https://llmsleuth.com/api/mcp \
  --header "Authorization: Bearer asc_your_api_key"
```

Comparisons can take several minutes. If your client times out, raise its tool timeout (for Claude Code, set `MCP_TOOL_TIMEOUT=660000`).

### Cursor (`~/.cursor/mcp.json`)

```json
{
  "mcpServers": {
    "llm-sleuth": {
      "url": "https://llmsleuth.com/api/mcp",
      "headers": {
        "Authorization": "Bearer asc_your_api_key"
      }
    }
  }
}
```

### VS Code (`.vscode/mcp.json`)

VS Code prompts for the key once and stores it securely.

```json
{
  "inputs": [
    {
      "type": "promptString",
      "id": "llm-sleuth-key",
      "description": "LLM Sleuth API key",
      "password": true
    }
  ],
  "servers": {
    "llm-sleuth": {
      "type": "http",
      "url": "https://llmsleuth.com/api/mcp",
      "headers": {
        "Authorization": "Bearer ${input:llm-sleuth-key}"
      }
    }
  }
}
```

### Codex (`~/.codex/config.toml`)

Set `LLM_SLEUTH_API_KEY` in your shell, then add:

```toml
[mcp_servers.llm-sleuth]
url = "https://llmsleuth.com/api/mcp"
bearer_token_env_var = "LLM_SLEUTH_API_KEY"
tool_timeout_sec = 660
```

### Windsurf (`~/.codeium/windsurf/mcp_config.json`)

```json
{
  "mcpServers": {
    "llm-sleuth": {
      "serverUrl": "https://llmsleuth.com/api/mcp",
      "headers": {
        "Authorization": "Bearer asc_your_api_key"
      }
    }
  }
}
```

### Other clients without header support

Bridge the remote server with `mcp-remote`:

```json
{
  "mcpServers": {
    "llm-sleuth": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://llmsleuth.com/api/mcp",
        "--header",
        "Authorization:${LLM_SLEUTH_AUTH}"
      ],
      "env": {
        "LLM_SLEUTH_AUTH": "Bearer asc_your_api_key"
      }
    }
  }
}
```

## Tools

- `list_models` (Free): Current model IDs, providers, display names, credit cost per run, and each provider's default.
- `run_comparison` (Credits): Runs one query through 1-16 models. Returns generated search queries, cited sources, source-page evidence, and each final answer.
- `get_execution` (Free): Fetches a saved comparison by execution_id, including models still running. Use it to recover after a client timeout.
- `list_executions` (Free): Lists your most recent comparisons with execution_id, query, status, models, and credits used.

### run_comparison arguments

- `query` (string): Required. The question or prompt, up to 4,000 characters.
- `runs` (array): Recommended. One to 16 { provider, model } targets from list_models.
- `providers` (array): Legacy shorthand that runs each provider's default model. Do not send with runs.
- `page_text_chars` (integer): Characters of extracted page text kept per source preview. Default 1,500, max 20,000.

Results use the same shape as `POST /api/v1/query`, plus a `history_url`. Raw HTML samples are dropped and page text is trimmed so results fit in an assistant's context.

## Workflow the server tells assistants to follow

1. Call `list_models` first. Model IDs and costs change.
2. Pick explicit runs across at least two providers, add up `credit_cost`, and state the cost before running.
3. Call `run_comparison`. If it times out, do not call it again (that charges twice). Use `list_executions` or `get_execution` to recover the saved result.
4. Check every `results[].ok` and report findings per provider: search strategy, source overlap, unique sources, evidence quality, answer differences, brand visibility, and failures.

## Test with curl

```bash
curl https://llmsleuth.com/api/mcp \
  -H "Authorization: Bearer asc_your_api_key" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

## Errors

- HTTP `401`: missing or invalid API key.
- Tool result with `isError: true`: the tool ran but failed. The JSON body carries `error`, the HTTP-equivalent `status` (`400` bad input, `402` not enough credits, `500` provider or save failure), and `details` such as `credits_required` or `execution_id`.
- `GET` returns `405`: the server has no server-initiated stream. Send JSON-RPC with `POST`.
