Skip to content

feat(mcp): Sim MCP server for the full Sim API - #7985

Merged
waleedlatif1 merged 3 commits into
stagingfrom
feat/sim-mcp-server
Sep 18, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
feat/sim-mcp-server

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Adds the Sim MCP server: one stateless Streamable HTTP endpoint (/api/mcp, or SIM_MCP_URL on a dedicated host such as mcp.sim.ai/mcp) that exposes the full public v2 API — the same 237 operations and names as the CLI
  • Four tools instead of one per operation: search_operations, describe_operation, call_read_operation (GET, read-only annotated), call_write_operation (destructive annotated). Unknown names get closest-match suggestions; wrong tool gets pointed at the right one
  • Tool calls dispatch in-process to the real v2 route handlers (generated table from the v2 contracts, bun run generate:mcp-operations, enforced by check:mcp-operations), so auth, OAuth scope, rate limits, validation, use cases, and the error envelope are the route's own — MCP adds no authorization of its own
  • Auth: API key (X-API-Key or Bearer) or OAuth. OAuth tokens are RFC 8707 audience-bound to the MCP server; in-process v2 routes accept them via a server-only audience context, while the REST API still rejects them
  • OAuth: resource parsing generalized to Search + Sim MCP with per-resource scope families; public client registration can now request api:read/api:write, and publicly registered clients must bind API grants to the Sim MCP resource (operator clients like the CLI unchanged)
  • Step-up: a token missing the dispatched operation's declared scope gets HTTP 403 insufficient_scope with resource_metadata, before the tool runs
  • Dedicated host routing in proxy.ts: on the MCP host only the endpoint + OAuth metadata are served; the app host stops serving /api/mcp so clients bind to one URL
  • Shared MCP route helpers (credential parsing, stateless transport, 405, protected-resource metadata/challenge, tool results) — Sim Search MCP refactored onto them
  • describe_operation returns the OpenAPI description plus JSON Schema of params/query/body/headers
  • mcp client-info surface on dispatched requests; new MCP docs tab (overview, authentication, tools); SIM_MCP_URL documented

Follow-ups (not in this PR): DNS/ALB for mcp.sim.ai + SIM_MCP_URL in hosted envs; Client ID Metadata Documents in the authorization server; MCP SDK v2 for the 2026-07-28 protocol revision

Type of Change

  • New feature

Testing

  • Unit/route tests for catalog, dispatch, route handler (end-to-end through a real v2 route), host routing, OAuth resource/authorize/register, protected-resource metadata
  • End to end against a local instance with the official MCP SDK client: API key and full OAuth flow (DCR → authorize with resource → consent → token → refresh), audience rejection on REST, read-only step-up 403, table create/rows/delete, error paths, and dedicated-host routing
  • bun run lint, type-check, check:audits (all audits), docs-manifest:check pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@waleedlatif1
waleedlatif1 requested a review from a team as a code owner September 18, 2026 21:50
@vercel

vercel Bot commented Sep 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 18, 2026 10:17pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue remains, and both previous findings are resolved.

Summary

The PR adds a stateless Sim MCP endpoint exposing the public v2 API through searchable read/write operation tools, with in-process route dispatch, OAuth resource binding, API-key support, dedicated-host routing, generated operation metadata, tests, and documentation. Changes since the previous review harden API-key/OAuth token-prefix separation and make dedicated-host matching correctly account for ports.

  • Exposes the v2 API through four MCP tools while retaining route-level authentication, authorization, validation, and rate limiting.
  • Adds OAuth resource metadata, public client registration, audience-bound grants, and operation-level scope enforcement.
  • Adds dedicated MCP host routing, generated operation catalogs, documentation, and extensive route and integration tests.
  • Resolves both previous findings: operation classification now follows declared OAuth scope, and dedicated-host requests receive the required CORS handling.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Client[MCP client] --> Endpoint[Sim MCP endpoint]
  Endpoint --> Auth[API key or OAuth admission]
  Auth --> Catalog[Search or describe operation]
  Auth --> Dispatch[Call read or write operation]
  Dispatch --> Scope[Operation scope check]
  Scope --> Route[v2 route handler]
  Route --> Policy[Authorization, validation, and rate limits]
  Policy --> Result[MCP tool result]
Loading

Reviews (3) · Last reviewed commit: "fix(mcp): match the MCP host by full aut..."

Comment thread apps/sim/lib/api/mcp/catalog.ts Outdated
Comment thread apps/sim/proxy.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/api/mcp/host-routing.ts Outdated
Comment thread apps/sim/lib/api/server/routes/mcp-server-route.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 60 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 62 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 4b28dff into staging Sep 18, 2026
42 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/sim-mcp-server branch September 18, 2026 22:25
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.

1 participant