Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/unreleased/1081-mcp-events-unavailable-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MCP server keeps the unavailable-cluster warning on long event lists

When `list_events` runs across clusters with a personal MCP token and returns more than 100 events, the result now still says which clusters could not be read, after the truncation notice. Before, the truncation notice replaced that warning. [PR #1081](https://github.com/GameplanePanel/Gameplane/pull/1081)
2 changes: 1 addition & 1 deletion docs/agent-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ This document is the **first stop** for AI agents modifying or extending Gamepla
| Change the website | `website/AGENTS.md` (submodule) |
| Add a DB migration | `api/specs.md`, `api/internal/db/migrations/README.md` |
| Change CI or a workflow | `docs/contributing.md` ("CI and workflows", "How CI picks tests") |
| Change personal MCP tokens or the MCP read routes (`api/internal/auth/mcptokens.go`, `api/internal/handlers/mcp_tokens.go`, `api/internal/handlers/pods.go`) | `api/specs.md`, `docs/security.md` ("mcp-server (optional)") |
| Change personal MCP tokens or the MCP read routes (`api/internal/auth/mcptokens.go`, `api/internal/handlers/mcp_tokens.go`, `api/internal/handlers/pods.go`, `web/src/routes/McpTokens.tsx`, the MCP tokens dialog in `web/src/routes/Users.tsx`) | `api/specs.md`, `web/specs.md`, `docs/security.md` ("mcp-server (optional)") |
| Change MCP server RBAC or namespace scope (`charts/gameplane/templates/mcp-server.yaml`, `charts/gameplane/tests/mcp-server-rbac.sh`) | `docs/security.md` ("mcp-server (optional)"), `mcp-server/specs.md` |
| Decide where new code goes | `docs/layout.md` |

Expand Down
2 changes: 1 addition & 1 deletion mcp-server
Submodule mcp-server updated 2 files
+34 −0 main_test.go
+12 −1 tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Only a decision valgul answers is written here as settled. OD-1 to OD-3 were ask

Today a session has no Gameplane user: it reads with the pod's Kubernetes identity.

- A. Personal MCP token: the user creates a read-only, expiring, revocable token in the dashboard (their profile) and puts it in their MCP client config. The token never grants more than the user's current permissions. Needs a small dashboard screen (Pencil design first). (Recommended: works for local and SSO users alike, revocable per token, no browser needed in the MCP client.)
- A. Personal MCP token: the user creates a read-only, expiring, revocable token in the dashboard (their profile) and puts it in their MCP client config. The token never grants more than the user's current permissions. Needs a small dashboard screen (design.fig design first). (Recommended: works for local and SSO users alike, revocable per token, no browser needed in the MCP client.)
- B. Sign in from the MCP client with the user's normal login (password or SSO in a browser window, like `kubectl` OIDC plugins). No new token screen, but each client must handle a browser login and SSO-only installs need a device-login flow.
- C. Map the Kubernetes identity that opens `kubectl exec` to a Gameplane user. No Gameplane login at all, but only works for users who already have Kubernetes access, which most Gameplane users do not.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ All mutating routes keep the CSRF check. RBAC rules: new self rules next to `/us
- Invalid, expired, revoked, epoch-mismatched or unknown tokens all get the same `401 server.common.unauthenticated` body as a missing session (FR-014). Store failures get `503 server.generic.503`, as for sessions.
- Rate limit: token requests count against the existing per-user limiter; failed token lookups count against the per-IP auth limiter, like failed logins.

## Token guard (`mcpTokenGuard`, runs after `Authenticate`, before `rbac.Middleware`)
## Token guard (`MCPTokenGuard`, runs after `Authenticate`, before `rbac.Middleware`)

A token-authenticated request passes only when the method is GET or HEAD, it is not a WebSocket upgrade, and its route pattern is on this allow-list:

Expand All @@ -33,11 +33,11 @@ A token-authenticated request passes only when the method is GET or HEAD, it is
/backups /backups/{name}
/schedules /schedules/{name}
/restores /restores/{name}
/modules /modules/{name} /modules/sources
/modules /modules/{name} /modules/sources (/modules/catalog is refused)
/users/me/servers
/pods /pods/{name}
/kube-events
/admin/system-logs/{component}
/admin/system-logs/{api|operator}
```

Everything else → `403 server.forbidden`, audited with reason `mcp-refused`. The list is a Go slice next to the guard, and a unit test fails if a route on it is not GET-only in the router.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| `get_pod_logs` | `/servers/{server}/logs/pod/tail` (new `server` argument required in this mode), or `/admin/system-logs/{component}` for API/operator pods | as today, within the allow-list |
| `propose_fix` | reads through the same calls, so it never sees more than the user | as today |

- No `cluster` → per-user mode calls `/clusters`, runs the call on each, and returns `{cluster: [...]}` groups plus `unavailable: [clusterIDs]`. Break-glass ignores `cluster` other than the local one and says so.
- No `cluster` → per-user mode calls `/clusters`, runs the call on each, and merges the results with each item labelled by its cluster (`clusterAnnotation`); clusters that fail (other than 403/404) are reported in the merged list's resource version as `unavailable clusters: <ids>` (`mcp-server/internal/panel/fanout.go`). Break-glass ignores `cluster` other than the local one and says so.
Comment thread
ValgulNecron marked this conversation as resolved.
Resolved
- No `namespace` → per-user mode uses the namespaces the user may read on that cluster (from `/namespaces`); break-glass loops over its allow-list.
- Refusals are returned as tool errors with the API's message (`not authenticated`, `permission denied`, `namespace not in scope`, `cluster not found or not permitted`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Portable SQL per `api/internal/db/migrations/README.md` (no dialect functions; t
|---|---|---|
| `GAMEPLANE_PANEL_URL` / `--panel-url` | env or flag | Per-user mode when set. HTTPS required except loopback. |
| `GAMEPLANE_MCP_TOKEN` | env only | Required in per-user mode; `serve` refuses to start without it. |
| `--panel-ca` | flag | Optional PEM bundle for a private CA. |
| `GAMEPLANE_PANEL_CA` / `--panel-ca` | env or flag | Optional PEM bundle for a private CA. |
| `GAMEPLANE_MCP_NAMESPACES` | env, rendered by the chart | Break-glass mode namespace allow-list (release namespace + managed game namespaces). Unset = unrestricted standalone kubeconfig run. |

## Chart RBAC objects (break-glass, replaces `<release>-mcp-server-read` ClusterRole + binding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Branch**: `spec-037/scope-mcp-server-permissions` | **Date**: 2026-11-22 | **Spec**: [spec.md](spec.md)

**Input**: Feature specification from `specs/037-scope-mcp-server-permissions/spec.md`
**Input**: Feature specification from `specs/done_037-scope-mcp-server-permissions/spec.md`

**Open decisions**: planning raised OD-4 (token lifetimes, settled: 7, 30, 90 or 365 days) and OD-5 (who may create tokens, settled: every signed-in user) in [OPEN-DECISIONS.md](OPEN-DECISIONS.md). Everything else in this plan follows the settled OD-1 to OD-3.

Expand All @@ -18,7 +18,7 @@ The MCP server gets two modes. The normal **per-user mode** runs on the user's m

**Storage**: SQLite / PostgreSQL through the API store; one new portable migration `common/023_mcp_tokens.sql` ([data-model.md](data-model.md)).

**Testing**: Go unit tests and API envtest (`api/internal/handlers/*_envtest_test.go`), mcp repo unit tests (`httptest` panel, fake clientset break-glass), web Vitest, chart `helm template` checks, E2E in `test/e2e/` buckets `api-rbac`, `multicluster`, `optional-components`. CI only (rule 8).
**Testing**: Go unit tests (API token routes and read routes in `api/internal/handlers/mcp_tokens_test.go` and `pods_test.go` with a fake clientset), mcp repo unit tests (`httptest` panel, fake clientset break-glass), web Vitest, chart `helm template` checks, E2E in `test/e2e/` buckets `api-rbac`, `multicluster`, `optional-components`. CI only (rule 8).

**Target Platform**: Kubernetes (k3s to multi-node), standalone panel; MCP server per-user mode on Linux/macOS/Windows hosts via the published container image.

Expand Down Expand Up @@ -50,7 +50,7 @@ Re-checked after Phase 1 design: no new violations.
### Documentation (this feature)

```text
specs/037-scope-mcp-server-permissions/
specs/done_037-scope-mcp-server-permissions/
├── spec.md
├── OPEN-DECISIONS.md
├── plan.md # this file
Expand Down Expand Up @@ -98,7 +98,7 @@ GameplanePanel/Gameplane

**Structure Decision**: work splits by repository and by reviewable unit, delivered as stacked PRs (one thread, valgul's multi-PR rule for specs):

1. **Gameplane PR A, API** (`feat/037-mcp-token-api`): migration, token auth + guard, token routes, read routes, RBAC rules, audit, envtests, E2E `api-rbac`, changelog.
1. **Gameplane PR A, API** (`feat/037-mcp-token-api`): migration, token auth + guard, token routes, read routes, RBAC rules, audit, unit tests, E2E `api-rbac`, changelog.
2. **Design** (`design/037-mcp-tokens`, merged into PR B): `design.fig` screens + export.
3. **Gameplane PR B, dashboard** (on A): MCP tokens page, admin dialog, i18n, Vitest.
4. **mcp PR** (`feat/per-user-mode` in GameplanePanel/mcp): Reader, panel client, break-glass allow-list, tools, docs, tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Then in a break-glass session, `list_pods` with no namespace returns only those

## 3. Multicluster (Story 3)

Give `ops-a` a supplemental grant on the remote cluster for `gameplane-games`. `list_gameplane_resources kind=GameServer` with no cluster returns groups for both clusters; with `cluster=<unknown>` it returns "cluster not found or not permitted". Stop the remote cluster's gateway: the call still answers, listing it under `unavailable`.
Give `ops-a` a supplemental grant on the remote cluster for `gameplane-games`. `list_gameplane_resources kind=GameServer` with no cluster returns groups for both clusters; with `cluster=<unknown>` it returns "cluster not found or not permitted". Stop the remote cluster's gateway: the call still answers, reporting it as `unavailable clusters: <id>` in the result.

## 4. Docs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Facts below were read from `master` at `73389d7a` (2026-11-22) and from the `mcp

### R2. How the API accepts a token

- **Decision:** `Authenticate` keeps the cookie path unchanged. When there is no session cookie and the request carries `Authorization: Bearer gpmcp_…`, it looks the token up (digest, not expired, not revoked, `session_epoch` still matches the user), loads permissions with `LoadPerms`, marks the request context as token-authenticated, and sets the audit actor to `<username> (mcp)`. A new `mcpTokenGuard` middleware, mounted right after `Authenticate`, rejects every token-authenticated request whose method is not GET/HEAD or whose route is not in the allow-list (contracts/api-mcp-token-auth.md). WebSocket upgrades are never on the list.
- **Decision:** `Authenticate` keeps the cookie path unchanged. When there is no session cookie and the request carries `Authorization: Bearer gpmcp_…`, it looks the token up (digest, not expired, not revoked, `session_epoch` still matches the user), loads permissions with `LoadPerms`, marks the request context as token-authenticated, and sets the audit actor to `<username> (mcp)`. A new `MCPTokenGuard` middleware, mounted right after `Authenticate`, rejects every token-authenticated request whose method is not GET/HEAD or whose route is not in the allow-list (contracts/api-mcp-token-auth.md). WebSocket upgrades are never on the list.
- **Rationale:** permissions come from the same `rbac.Middleware`, owner fallback and handlers as the dashboard (FR-011, FR-020). The allow-list makes "read-only" a property of the API, not of the MCP client. Loading permissions per request gives FR-013 for free.
- **Alternatives:** method-only guard (some GETs are sensitive, such as capture file downloads or console WebSocket upgrades; rejected); a separate `/mcp/*` API surface (duplicates every permission rule; rejected by OD-2).

Expand Down Expand Up @@ -63,4 +63,4 @@ Facts below were read from `master` at `73389d7a` (2026-11-22) and from the `mcp

### R8. Testing

- API: unit tests for token parse/lookup/guard; `handlers/*_envtest_test.go` for the new reads (namespace scoping, owner fallback, admin-only main namespace, remote cluster deny). MCP repo: `panel.Client` tests against `httptest`, tripwire for GET-only, namespace allow-list tests. E2E (constitution I): new tests in the `api-rbac` bucket (token user sees only its namespace; revoked token refused) and `multicluster` bucket (remote grant). Chart: `helm template` checks in the existing chart test job that no ClusterRole grants pods/events/logs.
- API: unit tests for token parse/lookup/guard; `handlers/mcp_tokens_test.go` and `handlers/pods_test.go` (fake clientset) for the token routes and new reads (namespace scoping, owner fallback, admin-only main namespace, remote cluster deny). MCP repo: `panel.Client` tests against `httptest`, tripwire for GET-only, namespace allow-list tests. E2E (constitution I): new tests in the `api-rbac` bucket (token user sees only its namespace; revoked token refused) and `multicluster` bucket (remote grant). Chart: `helm template` checks in the existing chart test job that no ClusterRole grants pods/events/logs.
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ When the Gameplane API itself is broken, a cluster admin can still use the MCP s
- The Cluster and NetworkCapture kinds stay out of the MCP server's tools, as today.
- The dashboard's existing permission keys and per-cluster grants are the only source of user permissions. This spec adds no new permission key for managing personal MCP tokens beyond what is needed for users to manage their own (decided in planning).
- Code changes span the `GameplanePanel/mcp` repo (server) and `GameplanePanel/Gameplane` (chart, API, docs, and the `mcp-server` submodule pointer after mcp PRs merge). Gameplane PR #993, which makes `mcp-server/` a submodule, merges first.
- Any dashboard screen this needs (the personal MCP token screen) is designed in `design.pen` before code, per the design-first rule.
- Any dashboard screen this needs (the personal MCP token screen) is designed in `design.fig` before code, per the design-first rule.
Loading
Loading