Repository navigation
0.41.0
The MCP server's tool seam: one tool list for chat, agent runs and MCP, filtered by toolsFor(surface, ctx), with Tool.surfaces, a Tool.mcp block, and ServerPlugin.tools replacing agentTools (still read, with a warning).
Tool(anddefineToolin@/plugins/api) gainssurfaces?: ('chat' | 'agents' | 'mcp')[](absent = all) andmcp?: { title?, annotations?, outputSchema?, scope? };@/plugins/apiexports the typesToolSurface,ToolMcpOptions,McpToolAnnotationsandMcpToolScope.toolsFor(surface, ctx)inservices/agents/toolsis the one filter; chat, the chat inspector, agent runs and replay call it.buildAgentTools(ctx)still builds the unfiltered list and is still where an app appends a kit-wide tool.- On
mcp, a terminal tool (no handler) and an approval-gated tool (requiresApproval[When]) are never offered;mcpToolProfile(tool)derives a tool's MCP scope (mcp:read, ormcp:writeforsideEffects) and annotations (docs/CONCEPTS.md§9 "Chat"). ServerPlugin.agentToolsis renamedServerPlugin.tools, same signature.agentToolsis still read whentoolsis absent and is marked deprecated;pnpm plugin checkwarns on it, naming the replacement.example-featuredeclarestools, andlist_example_notescarries the referencemcpblock (a title,openWorldHint: false).- Tool names are one rule for every surface,
MCP_TOOL_NAME_PATTERNin@rocketflare/shared/mcp: 1–64 ofA–Z a–z 0–9 _ -(no., which the chat models refuse).admittedPluginToolsinservices/agents/toolsdrops and logs a plugin tool whose name breaks it, is a core tool's (CORE_TOOL_NAMES) or an earlier plugin's. pnpm plugin checkfails a plugin tool name that breaks the rule or collides (read fromdefineTool({ name })literals andconsts), fails a reserved-pathapiPrefixesentry or['/mcp', …]mount tuple, and warns on "Rocketflare" in a tool'stitleordescription.@testkit/integrationexportscallMcpTool(db, tool, { as, tenant, args?, scopes?, exposure?, exposedTools? })— turn MCP on, connect asas, list and call over the real/mcp, answering{ listed, listing, isError, text, json, structured }— plusconnectMcp,enableMcp,mcpClient,mcpTestEnvandtoolJson.
For plugin authors: a tool reaches MCP clients through ServerPlugin.tools alone — no mount, no auth of its own — and a plugin proves it scopes there with callMcpTool as a member of a second organisation. A tool's ToolCtx now carries requester — the caller's userId, role, admin-level flag and groups with their type names, or null for a run nobody started — so a tool that scopes by role or group (a semantic layer's security context) reads no membership of its own; features() answers the caller's resolved flags without a query. The opt-in analytics plugin's own /mcp (drizzle-cube, API-key auth) is now refused at load; its next plugins release moves its cube tools onto tools with surfaces: ['mcp', 'agents'], drops the mount and drops its vite coreEdits /mcp proxy line, which the kit's own proxy replaces.
The MCP server itself, at /mcp and /mcp/t/<slug> (docs/CONCEPTS.md §19), shipped dark behind the environment-gated mcp flag:
apps/web/src/api/routes/mcp.tsserves stateless Streamable HTTP through@modelcontextprotocol/server(a new dependency), mounted before the mount table with its own CORS, outside the global one. A request needs an MCP access token;services/mcp/caller.tsresolves it to the person's membership (isGlobalAdminalways false) and answers 401 with aWWW-Authenticatechallenge or 403blocked,tenant_suspended,mcp_disabledormcp_not_allowed./api/mcp/settings|tools|calls(manage McpSettings, owners and admins) hold an organisation's switch (off by default), exposure (read_onlyby default) and who may connect.- Four tenant tables in
apps/web/src/db/schema/mcp.ts:mcp_settings,mcp_grants,mcp_tokensandmcp_tool_calls(pruned nightly afterMCP_CALL_RETENTION_DAYS). - New optional vars:
MCP_GRANT_IDLE_DAYS,MCP_GRANT_MAX_DAYS,MCP_CALL_RETENTION_DAYS,MCP_CALLS_PER_GRANT_PER_MINUTE,MCP_CALLS_PER_USER_PER_MINUTE,MCP_CALLS_PER_TENANT_PER_MINUTE. - Calls are capped per connection (60/min), per person across their connections in an organisation (120/min) and per organisation (600/min), in that order; a limiter that cannot be read fails the call closed as a logged
tool_failedtool error. - A JSON-RPC batch on
/mcpis refused (400,-32600) in both protocol eras, before the SDK dispatches any call in it. - A tool with an
outputSchemawhose answer is over the 60 000-character cap sends nostructuredContentand answers an error result carrying the capped text. - The global CORS skips
/mcp, the token and revocation endpoints and the discovery documents with or without one trailing slash (isMcpPath). CORE_FEATURESgainsmcp,CORE_SUBJECTSgainsMcpSettings, andERROR_CODESgainsinvalid_token,mcp_disabledandmcp_not_allowed./mcp,/mcp/*,/oauth,/oauth/*and/.well-known/oauth-*are reserved for core: a plugin declaring one as a mount, anapiPrefixesentry or a public mount stops the app at load, naming the plugin.tenantAuthContext(cfg, input)is extracted frommiddleware/auth.tsand exported; the API-key path uses it.- Settings → MCP (
ui/pages/settings/Mcp.tsx,hooks/useMcp.ts, themcpquery-key family) — a newmcpsettings tab, shown only where the deployment shipsmcpand tomanage McpSettings.
The app is its own OAuth 2.1 authorization server for /mcp, in Postgres (services/mcp/authorization.ts, routes/oauth.ts):
- Discovery at
/.well-known/oauth-protected-resource[/mcp|/mcp/t/<slug>],/.well-known/oauth-authorization-serverand/.well-known/openid-configuration; clients identify themselves by a Client ID Metadata Document (services/mcp/cimd.tsfetches it behind a guard and caches it inoauth_clients). No dynamic registration. GET /oauth/authorize→ the app's own/login→/oauth/continue→ the consent page/consent(a new SPA route) →POST /oauth/consent→ a code →POST /oauth/token(authorization_code,refresh_tokenwith rotation, reuse detection and a 30-second retry grace) andPOST /oauth/revoke. PKCE S256 is mandatory.- Two platform tables,
oauth_clientsandoauth_requests, both inRLS_REVOKED_TABLES;mcp_tokensgainssuccessor_sealed, andmcp_grantsgainsactivated_at— a consent's grant is a connection (listed, counted,mcp.client_connected) only once its code is redeemed, and the nightly retention deletes one never redeemed. - A client metadata document is accepted when the client can act as a public client:
token_endpoint_auth_methodabsent ornone, ornoneamongtoken_endpoint_auth_methods_supported(ChatGPT's document prefersprivate_key_jwtand listsnone). Itsgrant_typesandresponse_types, when present, must includeauthorization_codeandcode. - A refused client metadata document reads the same on the error page whatever the cause (
CIMD_UNUSABLE, the cause in the server log); a document is cached only once it registers the request'sredirect_uri;pruneMcpdrops anoauth_clientsrow unfetched for 30 days that no grant and no pending request names; aresourcewhose slug does not decode answersinvalid_target. - Removing a member or blocking a person revokes their connections in the same transaction (
revokeMcpGrantsOfinmembers.ts,idp-tenancy.ts,admin.ts). /api/mcp/connections(admins: list, revoke,POST /revoke-all) and/api/mcp-connections(a person's own, across organisations — session only, an API key gets 403insufficient_scope), shown as Connected clients in Settings → MCP and Connected apps in Profile (ui/components/mcp/McpConnectionsTable.tsx).- Settings → MCP renders a tool description's
inline codeas code instead of showing the backticks. - Fix, not MCP-specific:
pnpm dev:tunnelnever gave the Worker the tunnel's public URL.scripts/tunnel-dev.mjspassedpnpm dev:api -- --var APP_URL:…; pnpm 10 forwards the--literally and wrangler drops what follows, so the Worker kept.dev.vars's localhostAPP_URLfor its redirects. It now passes--varwith no--(scripts/lib/tunnel-dev.mjs). - Fix, not MCP-specific: deleting a document (
DELETE /api/ai/documents/:id,deleteExternalDocument) first repairs the facts it superseded or conflicted with, in the same transaction (deleteDocumentsWithFactsin the newservices/knowledge/remove.ts, whereremoveDocumentFactsmoved fromextract.ts), instead of leaving them superseded by nothing or conflicting with a deleted fact. - Fix, not MCP-specific: knowledge extraction drops a submitted value, value wording or validity date over 2,000 characters (
MAX_CANDIDATE_TEXT_CHARS) asbad_value/bad_datebefore parsing it. SETUP.md§1.10 and §2.10 warn that whilepnpm dev:tunnelruns, the development instance and its password-less dev sign-in are public; §1.6 saysPOST /auth/dev-loginsigns in any email in development.docs/THREAT-MODEL.mdgains the OAuth client and its model as actors, the codes, tokens and grants as assets, and an "MCP promises" list.- Agent docs for building on MCP:
.claude/rules/tools.md(the safe-tool checklist and thecallMcpTooltests a tool owes, loaded where tools are written), the/rf-mcpskill (turn MCP on, add a tool, connect Claude or ChatGPT, troubleshoot), andapps/web/src/api/services/mcp/CLAUDE.md(the files and the invariants not to break). RootCLAUDE.mdlists MCP in the stack and/rf-mcpamong the skills an agent may run;rf-how-do-i's MCP entry points at/rf-mcp; the threat model's metadata-fetch promise now says private-resolving names are left to the platform's egress. @/plugins/apiexports the HTTP error classes (ApiError,BadRequestError,ForbiddenError,NotFoundError,ConflictError,RateLimitedError,ServiceUnavailableError,UnauthorizedError,isApiError) fromplugins/api/errors.ts, so a plugin tool or job (noRequestCtx) can refuse with a stable code; a plugin that defined its own copies can import these instead.
Upgrading with the analytics plugin: upgrade it right after the kit, to the plugins release that offers its cube tools through the app's MCP server (the porting note, "How to apply").
Porting note: docs/upgrades/0.41.0.md
Full changes: 0.40.0...0.41.0