fix(mcp): MCP server cards per tenant, not shared by all #454

Merged
sharang merged 1 commits from fix/mcp-servers-per-tenant into main 2026-10-05 18:19:05 +00:00
Owner

Closes #432: the dashboard's MCP server cards were shared by all tenants.

Before

The dashboard kept mcp_servers in its own database and read it with find({}):

  • Every tenant saw the same cards, could delete them and regenerate their tokens.
  • A card one tenant added, including its mongodb_uri, showed to every tenant.

Now

  • Agent: new /api/v1/mcp-servers endpoints in the tenant's database: GET list, POST create, DELETE /{id}, POST /{id}/token. They work like /api/v1/mcp-tokens:
    • tenant resolution from the JWT;
    • the role gate from #431 (writes only for writing roles);
    • support access with X-Pruefwerk-Tenant.
    • Access tokens go only to roles that may change things.
  • Default cards per tenant: a tenant without cards gets the three defaults (Findings, SBOM, DAST) on its first listing, for the dashboard's MCP_ENDPOINT_URL (?default_endpoint=). They are upserted by name, so two parallel first listings don't create duplicates.
  • Dashboard: the server functions call the agent (fetch, add, delete, regenerate).
    • The health status is now probed live on each listing (in parallel, 3 s timeout) instead of being written back to Mongo.
    • So a read-only role no longer writes, and refresh_mcp_status is gone.
  • Migration: at startup the dashboard drops its old shared mcp_servers collection, with a log line. Its cards can't be attributed to a tenant. Each tenant gets its defaults on its first listing.

Test

New tests/mcp_servers.rs, against a real Mongo:

  • A tenant gets exactly 3 default cards, and still 3 on the second listing.
  • Tenant A adds a card. Tenant B doesn't see it, and gets 404 both deleting it and regenerating its token. A's token stays unchanged.
  • A read-only role (CXO) sees the cards without tokens.
  • A deletes its own card (204).

Checks

  • fmt, plus clippy with the CI flags on the agent and both dashboard feature sets.
  • Agent lib tests: 571.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

Closes #432: the dashboard's MCP server cards were shared by **all tenants**. ## Before The dashboard kept `mcp_servers` in its own database and read it with `find({})`: - Every tenant saw the same cards, could delete them and regenerate their tokens. - A card one tenant added, including its `mongodb_uri`, showed to every tenant. ## Now - **Agent:** new `/api/v1/mcp-servers` endpoints in the **tenant's database**: `GET` list, `POST` create, `DELETE /{id}`, `POST /{id}/token`. They work like `/api/v1/mcp-tokens`: - tenant resolution from the JWT; - the role gate from #431 (writes only for writing roles); - support access with `X-Pruefwerk-Tenant`. - Access tokens go only to roles that may change things. - **Default cards per tenant:** a tenant without cards gets the three defaults (Findings, SBOM, DAST) on its first listing, for the dashboard's `MCP_ENDPOINT_URL` (`?default_endpoint=`). They are upserted by name, so two parallel first listings don't create duplicates. - **Dashboard:** the server functions call the agent (`fetch`, `add`, `delete`, `regenerate`). - The health status is now probed live on each listing (in parallel, 3 s timeout) instead of being written back to Mongo. - So a read-only role no longer writes, and `refresh_mcp_status` is gone. - **Migration:** at startup the dashboard drops its old shared `mcp_servers` collection, with a log line. Its cards can't be attributed to a tenant. Each tenant gets its defaults on its first listing. ## Test New `tests/mcp_servers.rs`, against a real Mongo: - A tenant gets exactly 3 default cards, and still 3 on the second listing. - Tenant A adds a card. Tenant B doesn't see it, and gets **404** both deleting it and regenerating its token. A's token stays unchanged. - A read-only role (CXO) sees the cards **without tokens**. - A deletes its own card (204). ## Checks - fmt, plus clippy with the CI flags on the agent and both dashboard feature sets. - Agent lib tests: 571. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-05 17:48:43 +00:00
fix(mcp): MCP server cards per tenant, not shared by all
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 8m44s
36a64e4349
The dashboard kept its MCP server cards in its own database, read with
find({}): every tenant saw, deleted and re-keyed the same cards, and a card
added by one tenant (with its mongodb_uri) showed to all (#432).

The cards now live in each tenant's database at the agent, behind
/api/v1/mcp-servers (list, create, delete, regenerate token), like the MCP
tokens. Tenant resolution, the role gate and support access apply as for
every agent route; the access tokens go only to roles that may change
things. A tenant without cards gets the three default cards on its first
listing (by name, so two listings at once do not create them twice), for
the dashboard's MCP_ENDPOINT_URL.

The dashboard's server functions call the agent; the health status is
probed live on each listing (concurrently, 3 s) instead of being written
back, so a read-only role no longer writes. At start the dashboard drops
its old shared collection, whose cards cannot be attributed to a tenant.

Closes #432.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 808b6ab3aa into main 2026-10-05 18:19:05 +00:00
Sign in to join this conversation.