# MCP and coding agents

Visibling runs a remote Model Context Protocol server so a coding agent can do the whole onboarding workflow — resolve your organization, create a project, mint ingest keys, and read the integration guides — without manual browser clicks after sign-in. The guides cover the proxy, the browser client from `@visibling/sdk/browser`, error capture, and source map upload.

```text
https://visibling.com/mcp
```

The transport is stateless Streamable HTTP over `POST /mcp`. Discovery methods work unauthenticated; every `tools/call` requires a credential.

## Authenticate

Two credentials are accepted, both as `Authorization: Bearer <token>`:

1. **Personal API token** — starts with `vis_usr_` and is created per user at `/app/<org-slug>/settings/tokens`. It grants control-plane access only over `/mcp`; cookie-authenticated web routes never accept it.
2. **OAuth 2.1 access token** — obtained by an MCP host through the OAuth flow described below.

Ingest keys (`vis_srv_`, `vis_pub_`, `vis_map_`) are telemetry credentials and cannot call MCP tools.

### OAuth 2.1 with CIMD

Modern MCP hosts discover OAuth metadata and sign in with PKCE. Visibling uses **Client ID Metadata Documents (CIMD)** and deliberately does not offer Dynamic Client Registration.

- Protected resource metadata: `GET /.well-known/oauth-protected-resource/mcp`
- Authorization server metadata: `GET /.well-known/oauth-authorization-server` (and `/api/auth`)
- OpenID configuration: `GET /.well-known/openid-configuration` (and `/api/auth`)
- Audience: `https://visibling.com/mcp`
- Refresh tokens are supported; access tokens are RFC 9068 `at+jwt` tokens.

A request without a credential, or with an invalid one, answers `401` with:

```text
WWW-Authenticate: Bearer resource_metadata="https://visibling.com/.well-known/oauth-protected-resource/mcp"
```

### Device flow for CLIs

An agent with no browser session can use RFC 8628 and hand the human a one-click approval URL.

**1. Request a code**

```sh
curl -sS -X POST https://visibling.com/api/device/code \
  -H 'content-type: application/json' \
  -d '{"client_name":"Claude Code"}'
```

```json
{
  "device_code": "opaque-device-code",
  "user_code": "ABCD-EFGH",
  "verification_uri": "https://visibling.com/device",
  "verification_uri_complete": "https://visibling.com/device?user_code=ABCD-EFGH",
  "expires_in": 600,
  "interval": 5
}
```

**2. Ask the human to approve**

Open `verification_uri_complete`, sign in or create an account, and approve the client. The client name is self-asserted, so the approval page shows it without treating it as verified.

**3. Poll for the token**

```sh
curl -sS -X POST https://visibling.com/api/device/token \
  -H 'content-type: application/json' \
  -d '{"device_code":"opaque-device-code"}'
```

Poll no faster than `interval`. While the human has not approved, the endpoint answers with the RFC 8628 error `authorization_pending`; polling too fast returns `slow_down`; a denied request returns `access_denied`; an expired code returns `expired_token`. On success:

```json
{
  "access_token": "vis_usr_...",
  "token_type": "Bearer",
  "mcp_url": "https://visibling.com/mcp"
}
```

The code is single-use: concurrent polls can mint at most one token. Store the token in the agent's secret store, not in a repository.

## Client setup

### Claude Code

```sh
claude mcp add --transport http visibling https://visibling.com/mcp \
  --header "Authorization: Bearer $VISIBLING_USER_TOKEN"
```

### Cursor

`.cursor/mcp.json`:

```json
{
  "mcpServers": {
    "visibling": {
      "url": "https://visibling.com/mcp",
      "headers": {
        "Authorization": "Bearer vis_usr_your_token"
      }
    }
  }
}
```

### VS Code

`.vscode/mcp.json`:

```json
{
  "servers": {
    "visibling": {
      "type": "http",
      "url": "https://visibling.com/mcp",
      "headers": {
        "Authorization": "Bearer ${input:visibling-token}"
      }
    }
  },
  "inputs": [
    {
      "id": "visibling-token",
      "type": "promptString",
      "description": "Visibling personal API token",
      "password": true
    }
  ]
}
```

### Antigravity

`~/.gemini/antigravity/mcp_config.json`:

```json
{
  "mcpServers": {
    "visibling": {
      "serverUrl": "https://visibling.com/mcp",
      "headers": {
        "Authorization": "Bearer vis_usr_your_token"
      }
    }
  }
}
```

Hosts that support remote MCP with OAuth can omit the header and complete the browser sign-in instead.

## Tools

### Onboarding

| Tool | Purpose |
| --- | --- |
| `whoami` | The signed-in user and every organization they belong to, with plan and role. Creates the user's personal organization on first use. |
| `list_projects` | Projects in one organization. |
| `create_project` | Create a project. Owner or admin only; plan limits apply. |
| `update_project` | Rename a project or change allowed origins or timezone. Owner or admin only. |
| `list_ingest_keys` | Key metadata only — never hashes or plaintext. |
| `create_ingest_key` | Mint a `server`, `public`, or `sourcemap` key. Returns the plaintext exactly once. Owner or admin only. |
| `revoke_ingest_key` | Revoke a key. Owner or admin only. |

There is deliberately no MCP tool to delete a project.

### Analytics and verification

| Tool | Purpose |
| --- | --- |
| `get_overview` | KPIs, daily points, top pages, top events, and open issues. The primary way to verify a fresh integration is receiving events. |
| `list_funnels` | Saved funnels, compact rows. |
| `create_funnel` | Save an ordered funnel definition. |
| `run_funnel` | Run a funnel over a bounded window. |
| `get_flows` | User-flow paths around an anchor event. |
| `get_retention` | Weekly retention cohorts. |
| `get_usage` | Current UTC month usage against plan limits. |
| `get_agent_analytics` | AI-agent and MCP KPIs, where agents stopped, and recent daily agent nicknames. Default 20 recent agents, maximum 50. |
| `get_agent_trail` | One daily agent's chronological request trail, with the terminal request highlighted. Default 50 steps, maximum 100. |

### Errors and customer support

| Tool | Purpose |
| --- | --- |
| `list_issues` | Compact issue rows, filterable by status, source, release, or text. Default 20 rows, maximum 50. |
| `get_issue` | Issue summary, symbolicated frames, breadcrumbs, recent occurrences, and affected users. |
| `update_issue_status` | Set an issue to `open`, `resolved`, or `ignored`. |
| `search_users` | Search the end-user directory. Default 20 rows, maximum 50. |
| `get_user_timeline` | Traits, open issues, and a bounded chronological timeline for one user. |

### Alerts and Cloudflare Observability

| Tool | Purpose |
| --- | --- |
| `list_alert_rules` | Alert rules; webhook targets are masked for non-managers. |
| `create_alert_rule` | Add an email or webhook rule. Owner or admin only; SSRF validation and plan checks apply. |
| `update_alert_rule` | Update a rule. Owner or admin only. |
| `delete_alert_rule` | Remove a rule. Owner or admin only. |
| `get_cf_observability` | The project's Cloudflare Observability connection; never returns the stored token. |
| `configure_cf_observability` | Save an account id, Worker name, and API token. Owner or admin only; the token is encrypted at rest. |
| `query_cf_trace` | Look up a `cf-ray` or trace id in Workers Logs and Traces, subject to the plan and rate limits. |

Organization members can read. Owner and admin roles also mutate projects, keys, alert rules, and Cloudflare connections.

## Resources

Every public guide is exposed as an MCP resource at the same URL as its HTTP markdown twin:

```text
https://visibling.com/docs/getting-started.md
https://visibling.com/docs/proxy.md
https://visibling.com/docs/browser-sdk.md
https://visibling.com/docs/server-sdk.md
https://visibling.com/docs/agent-analytics.md
https://visibling.com/docs/errors-and-sourcemaps.md
https://visibling.com/docs/api.md
https://visibling.com/docs/mcp.md
https://visibling.com/docs/self-hosting.md
```

`resources/list` and `resources/read` work without authentication, so an agent can read the setup recipe before asking anyone to approve a device code.

## Discovery

| Endpoint | Media type |
| --- | --- |
| `GET /mcp/server-card`, `GET /.well-known/mcp-server-card` | `application/mcp-server-card+json` |
| `GET /.well-known/mcp.json`, `GET /mcp.json` | `application/json` |
| `GET /.well-known/ard.json` | `application/ai-catalog+json` |
| `GET /.well-known/ai-catalog.json` | `application/ai-catalog+json` |
| `GET /.well-known/oauth-protected-resource/mcp` | `application/json` |

A browser `GET /mcp` returns a plain HTML setup page with `Cache-Control: no-store`. An `Accept: text/event-stream` GET returns `405` with `Allow: POST`, because the server is stateless and does not hold an SSE stream open.

## Suggested agent flow

1. Read `https://visibling.com/docs/getting-started.md` via `resources/read` or plain HTTP.
2. If you have no token, run the device flow and ask the human to open the approval URL.
3. Call `whoami`; if the user has no organization yet, it is provisioned automatically.
4. Call `create_project` (or reuse an existing project from `list_projects`).
5. Call `create_ingest_key` for the kind you need. Store the plaintext in the app's secret store immediately.
6. Follow the proxy and browser SDK guides, then call `get_overview` to confirm events are arriving.
7. When fixing production errors, call `list_issues` and `get_issue`, then `query_cf_trace` with the occurrence's `cf-ray` for more context.
