mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

Support slug-based virtual server MCP endpoints (/servers/<slug>/mcp)

Open mrchi opened this issue 3 months ago • 2 comments

🧭 Type of Feature

  • [x] Enhancement to existing functionality

🧭 Epic

Title: Human-readable virtual server endpoint URLs Goal: Allow MCP clients to connect to a virtual server via its slug (e.g. /servers/network-tools/mcp) in addition to its UUID (/servers/3f8a.../mcp). Why now: The UUID-based endpoint URL is effectively unmemorable and leaks into every MCP client config (.mcp.json, Claude Code, Cursor, VS Code, CI jobs). Operators currently work around it with reverse-proxy path rewrites. Slugs already exist on virtual servers and are shown in the Admin UI — they just aren't wired into the transport routing.


🧑🏻‍💻 User Story 1

As a: platform operator I want: to give each virtual server a stable, readable endpoint URL derived from its slug So that: MCP client configs are self-documenting, reviewable in diffs, and don't need to change when a server is re-created (new UUID, same slug)

✅ Acceptance Criteria

Scenario: Connect via slug
  Given a virtual server with slug "network-tools"
  When an MCP client connects to /servers/network-tools/mcp with valid auth
  Then the session is established against that server, same as the UUID URL

Scenario: UUID keeps working
  Given a virtual server with id "3f8a..." and slug "network-tools"
  When a client connects to /servers/3f8a.../mcp
  Then the connection works exactly as before (no breaking change)

Scenario: Ambiguous or unknown slug
  Given a slug that matches no server (or matches multiple, if slug uniqueness is scoped)
  When a client connects to /servers/<slug>/mcp
  Then the gateway returns 404 (or an explicit ambiguity error), never silently picks one

🧑🏻‍💻 User Story 2

As a: MCP client user behind OAuth I want: the RFC 9728 protected-resource metadata URL to reflect the slug-based path I connected to So that: OAuth discovery works identically regardless of which URL form I used

✅ Acceptance Criteria

Scenario: OAuth challenge on slug URL
  Given an oauth_enabled virtual server with slug "network-tools"
  When an unauthenticated client hits /servers/network-tools/mcp
  Then the 401 WWW-Authenticate resource_metadata points at the matching
       .well-known/oauth-protected-resource/servers/network-tools/mcp

📐 Design Sketch (optional)

  • Resolution order in the streamable-HTTP transport: exact DbServer.id match first, then DbServer.slug match; fail closed on ambiguity (relevant if slug uniqueness is per-team rather than global — see #5146 for prior art on slug uniqueness scoping).
  • Touches _SERVER_ID_RE consumers in mcpgateway/transports/streamablehttp_transport.py (server lookup, _build_resource_metadata_url, OAuth issuer routing) and SSE equivalents.
  • Related: #4685 (configurable canonical resource URL) — slug support should compose with it.

🔗 MCP Standards Check

  • [x] Change adheres to current MCP specifications
  • [x] No breaking changes to existing MCP-compliant integrations

🔄 Alternatives Considered

  • Reverse-proxy path rewrites (Caddy/nginx mapping /network/mcp → /servers/<uuid>/mcp): works but adds infra per server and drifts when servers are recreated.
  • Root /mcp aggregate endpoint: fine when isolation isn't needed, but doesn't cover per-server scoping, per-server OAuth, or per-server rate limits.
  • Status quo (UUID everywhere): functional but hostile to config readability and review.

📓 Additional Context

  • Slug uniqueness semantics need a decision: if slugs are only unique within a team, routing must either require an unambiguous match or support a <team-slug>/<server-slug> form.
  • All auth/RBAC/token-scoping behaviour should be identical to the UUID path — slug is purely an alias at routing time.

mrchi avatar Aug 31 '26 11:08 mrchi

We would like to implement this and open a PR. Two notes from reading the code (v1.1.0 and main):

  1. Virtual servers have no slug today: the servers table has no such column (slugs exist on gateways, A2A agents and teams). So the change needs a new nullable servers.slug with an Alembic migration, plus create and update in the API.
  2. Uniqueness: we propose globally unique slugs. /servers/<slug>/mcp and the RFC 9728 well-known path carry no team context, so a per-team rule would need an ambiguity error. This differs from #5146, which was about name-derived values.

Plan: resolve the ID first, then the slug, before token scoping, so auth, RBAC and token scoping see the server ID as today. UUID-shaped slugs are refused. The 401 resource_metadata and the well-known resource use the URL form the client used.

Is global uniqueness acceptable? Despite the possible Admin UI deprecation, we would add the field also in the current Admin UI.

vgunjic avatar Nov 10 '26 13:11 vgunjic

@mrchi, thanks for proposing this work! 🙌 @vgunjic, for your question about uniqueness: #5146 addresses this as a bug. Instead, a team-qualified path may be better instead: /servers/<team-slug>/<server-slug>/mcp

@brian-hussey / @Lang-Akshay / @jonpspri , thoughts?

a-effort avatar Nov 13 '26 20:11 a-effort