Skip to content

feat(mcp): an MCP server for each namespace - #401

Merged
adeelahmad merged 7 commits into
mainfrom
claude/project-thread-iq6ke4
Oct 15, 2026
Merged

adeelahmad merged 7 commits into
mainfrom
claude/project-thread-iq6ke4

Conversation

@adeelahmad

Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: Lens had one MCP server, /mcp. An agent connected there saw every namespace the person who signed it in could read.

After: each namespace can have its own MCP server at /mcp/<namespace>. Its owner turns it on under Admin → Namespaces → the namespace → Connect apps, where the address is ready to copy. It can also be turned on with PATCH /api/v1/namespaces/<ns>/integrations or the set_namespace_integrations MCP tool. An agent connected there has the same tools but sees that namespace alone, whatever else the person can read.

How:

  • deps.within narrows the person's roles, permissions and collection roles to the one namespace, with no administration (an admin counts as an owner there). Every tool reads through that narrowed Access.
  • Tools that take a namespace default to this one, and it isn't a required argument there. The tools about the server itself (file_storage, monitoring, install_settings and the tools that change them) are left out, even for admins.
  • OAuth discovery names the namespace's own resource (/.well-known/oauth-protected-resource/mcp/<ns>). The consent page says the app asks for that namespace alone. A token issued for it (its RFC 8707 resource) opens that server and nothing else: not /mcp, not another namespace's server, not the API. A token for Lens or /mcp, or an API token, works on every namespace's server and sees only that namespace there.
  • Off by default (space.integrations.mcp). While it's off, the server answers 403; people with no role in the namespace get 404.

This is PR 1 of 3 for the thread. Next: an OpenAI-compatible /chat/completions per namespace, then API keys that open one namespace only.

Motivation and Context

Adeel asked for per-namespace scoped MCP servers, so an agent can be given one part of the archive.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests (tests/api/test_mcp_namespace.py, __tests__/connect-apps.test.tsx, consent test).
  • My change requires documentation updates, and I have updated docs/ accordingly (docs/mcp.md, "One namespace's MCP server").
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

Done questions (AGENTS.md)

  • Goal: the per-namespace MCP part of the ask. The chat endpoint follows in the next PR. I'll merge this one on green.
  • Agents: namespace_integrations / set_namespace_integrations MCP tools, plus the API route.
  • Zero setup: nothing new to install or configure.
  • Fewest clicks: one switch, then Copy.
  • Configurable: the switch is in the web app (namespace page), off by default, and not in the setup wizard.
  • Light: no new dependency or process.
  • Private and secure: it only narrows what an agent sees. A token issued for it is bound to it. Threat model updated (§1.7 entry row, P-OAUTH).
  • Cost: n/a, no model calls.
  • User decides: off until an owner turns it on; existing defaults unchanged.
  • Upgrades: a new optional field on space (integrations). Its absence means off, so no upgrade step is needed.
  • Honest: docs describe only what's merged here.
  • Tests, docs and generated files: make openapi regenerated the client; full backend suite passes locally (1088 passed).
  • Open standards: MCP, OAuth 2.1 with RFC 8707/9728; no new dependencies.
  • Reported in the thread. Refine later: show an app's namespace under Apps with access.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LB2qrE7CENSd3G5h4FxFra


Generated by Claude Code

A namespace's owner can turn on its own MCP server, /mcp/<namespace>
(Admin > Namespaces > the namespace > Connect apps, PATCH
/namespaces/{name}/integrations, or the set_namespace_integrations tool).
It has the same tools but sees that namespace alone: the person's roles
are narrowed to it, admins count as owners there, and the tools about the
server itself are left out. Tools that take a namespace default to it.

OAuth discovery names the namespace's own resource, the consent page says
the app asks for that namespace alone, and a token issued for it opens
that server and nothing else (not /mcp, other namespaces or the API).
Off by default; docs, threat model and changelog updated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LB2qrE7CENSd3G5h4FxFra
@adeelahmad adeelahmad self-assigned this Oct 15, 2026
@adeelahmad
adeelahmad merged commit 613d15e into main Oct 15, 2026
11 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-iq6ke4 branch October 15, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants