Skip to content

0.41.0

Choose a tag to compare

@cliftonc cliftonc released this 20 Nov 15:49
· 69 commits to main since this release
0.41.0
2d5782c

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 (and defineTool in @/plugins/api) gains surfaces?: ('chat' | 'agents' | 'mcp')[] (absent = all) and mcp?: { title?, annotations?, outputSchema?, scope? }; @/plugins/api exports the types ToolSurface, ToolMcpOptions, McpToolAnnotations and McpToolScope.
  • toolsFor(surface, ctx) in services/agents/tools is 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, or mcp:write for sideEffects) and annotations (docs/CONCEPTS.md §9 "Chat").
  • ServerPlugin.agentTools is renamed ServerPlugin.tools, same signature. agentTools is still read when tools is absent and is marked deprecated; pnpm plugin check warns on it, naming the replacement.
  • example-feature declares tools, and list_example_notes carries the reference mcp block (a title, openWorldHint: false).
  • Tool names are one rule for every surface, MCP_TOOL_NAME_PATTERN in @rocketflare/shared/mcp: 1–64 of A–Z a–z 0–9 _ - (no ., which the chat models refuse). admittedPluginTools in services/agents/tools drops and logs a plugin tool whose name breaks it, is a core tool's (CORE_TOOL_NAMES) or an earlier plugin's.
  • pnpm plugin check fails a plugin tool name that breaks the rule or collides (read from defineTool({ name }) literals and consts), fails a reserved-path apiPrefixes entry or ['/mcp', …] mount tuple, and warns on "Rocketflare" in a tool's title or description.
  • @testkit/integration exports callMcpTool(db, tool, { as, tenant, args?, scopes?, exposure?, exposedTools? }) — turn MCP on, connect as as, list and call over the real /mcp, answering { listed, listing, isError, text, json, structured } — plus connectMcp, enableMcp, mcpClient, mcpTestEnv and toolJson.

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.ts serves 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.ts resolves it to the person's membership (isGlobalAdmin always false) and answers 401 with a WWW-Authenticate challenge or 403 blocked, tenant_suspended, mcp_disabled or mcp_not_allowed.
  • /api/mcp/settings|tools|calls (manage McpSettings, owners and admins) hold an organisation's switch (off by default), exposure (read_only by default) and who may connect.
  • Four tenant tables in apps/web/src/db/schema/mcp.ts: mcp_settings, mcp_grants, mcp_tokens and mcp_tool_calls (pruned nightly after MCP_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_failed tool error.
  • A JSON-RPC batch on /mcp is refused (400, -32600) in both protocol eras, before the SDK dispatches any call in it.
  • A tool with an outputSchema whose answer is over the 60 000-character cap sends no structuredContent and 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_FEATURES gains mcp, CORE_SUBJECTS gains McpSettings, and ERROR_CODES gains invalid_token, mcp_disabled and mcp_not_allowed.
  • /mcp, /mcp/*, /oauth, /oauth/* and /.well-known/oauth-* are reserved for core: a plugin declaring one as a mount, an apiPrefixes entry or a public mount stops the app at load, naming the plugin.
  • tenantAuthContext(cfg, input) is extracted from middleware/auth.ts and exported; the API-key path uses it.
  • Settings → MCP (ui/pages/settings/Mcp.tsx, hooks/useMcp.ts, the mcp query-key family) — a new mcp settings tab, shown only where the deployment ships mcp and to manage 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-server and /.well-known/openid-configuration; clients identify themselves by a Client ID Metadata Document (services/mcp/cimd.ts fetches it behind a guard and caches it in oauth_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_token with rotation, reuse detection and a 30-second retry grace) and POST /oauth/revoke. PKCE S256 is mandatory.
  • Two platform tables, oauth_clients and oauth_requests, both in RLS_REVOKED_TABLES; mcp_tokens gains successor_sealed, and mcp_grants gains activated_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_method absent or none, or none among token_endpoint_auth_methods_supported (ChatGPT's document prefers private_key_jwt and lists none). Its grant_types and response_types, when present, must include authorization_code and code.
  • 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's redirect_uri; pruneMcp drops an oauth_clients row unfetched for 30 days that no grant and no pending request names; a resource whose slug does not decode answers invalid_target.
  • Removing a member or blocking a person revokes their connections in the same transaction (revokeMcpGrantsOf in members.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 403 insufficient_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 code as code instead of showing the backticks.
  • Fix, not MCP-specific: pnpm dev:tunnel never gave the Worker the tunnel's public URL. scripts/tunnel-dev.mjs passed pnpm dev:api -- --var APP_URL:…; pnpm 10 forwards the -- literally and wrangler drops what follows, so the Worker kept .dev.vars's localhost APP_URL for its redirects. It now passes --var with 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 (deleteDocumentsWithFacts in the new services/knowledge/remove.ts, where removeDocumentFacts moved from extract.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) as bad_value / bad_date before parsing it.
  • SETUP.md §1.10 and §2.10 warn that while pnpm dev:tunnel runs, the development instance and its password-less dev sign-in are public; §1.6 says POST /auth/dev-login signs in any email in development.
  • docs/THREAT-MODEL.md gains 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 the callMcpTool tests a tool owes, loaded where tools are written), the /rf-mcp skill (turn MCP on, add a tool, connect Claude or ChatGPT, troubleshoot), and apps/web/src/api/services/mcp/CLAUDE.md (the files and the invariants not to break). Root CLAUDE.md lists MCP in the stack and /rf-mcp among 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/api exports the HTTP error classes (ApiError, BadRequestError, ForbiddenError, NotFoundError, ConflictError, RateLimitedError, ServiceUnavailableError, UnauthorizedError, isApiError) from plugins/api/errors.ts, so a plugin tool or job (no RequestCtx) 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