Skip to content

feat(mcp): add HTTP Code Mode with explicit API permissions - #1670

Draft
betegon wants to merge 4 commits into
mainfrom
bt/code-mode-http
Draft

betegon wants to merge 4 commits into
mainfrom
bt/code-mode-http

Conversation

@betegon

@betegon betegon commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Code Mode is the MCP equivalent of sentry api: agents can use published API operations without a dedicated MCP tool.
The client's agent writes JavaScript; our Cloudflare sandbox executes authenticated HTTP calls and returns the result.

For example: “Copy this dashboard for two projects, preserving its widgets and filters.” The existing tool catalog cannot do this; Code Mode can.

search_sentry_api discovers the schema and execute_sentry_code runs the program. This version is HTTP-only; the SDK remains future work.

Prerequisite #1676 is merged. Stack: this PR → #1675 (agent evals). Runtime and permission safety tests remain here.

Code Mode architecture: generated code calls an RPC broker in the parent Worker; the token stays outside the sandbox.

Permissions

The Sentry token authenticates API calls; its OAuth scopes and the user's Sentry permissions set the maximum access.
The permission screen controls which of those actions this MCP connection may perform, without changing the token or its scopes.

  • API Read permits reads. API Write includes reads and enables create/update/delete. It starts unchecked; explicitly remembered selections are preserved.
  • Permissions are additive: API Write can modify issues even with Triage Issues unchecked, and projects/teams with Manage Projects & Teams unchecked. The consent screen explains this before approval.
  • The screen shows the scope: /mcp covers organizations authorized by the Sentry token; /mcp/{org} is restricted to that organization. Project-scoped connections do not expose Code Mode.
  • Existing grants gain no new permissions. Shared upstream OAuth scopes stay unchanged; the broker checks the MCP grant on every call, and Sentry still enforces token, role and resource permissions. Credentials stay outside generated code.
Sentry MCP permissions: organization scope, API Write unchecked, and additive permissions warning

Validation and before production

Previously passed: 469 hosted Cloudflare tests + 26 isolated runtime/access tests, root typechecks, lint, documentation links, frozen install and a production Wrangler dry-run. This extraction preserves the runtime and test sources byte-for-byte. The prerequisite independently passes 443 Cloudflare tests, root typechecks, lint and frozen install; the new documentation links/format also pass.

Pending before production: explicit execution closure for unawaited calls and timeouts, plus hosted OAuth-to-API authorization and CPU/termination verification. Local probes show that returning a result or timeout does not itself cancel work; a write already accepted upstream cannot be rolled back. The lifecycle investigation records the evidence and limits.

CI on the updated stack is pending. No production deployment performed. The previous full workspace run had unrelated CLI fixture/platform failures; CLI fixes are excluded.

@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sentry-local Ready Ready Preview Oct 27, 2026 1:46pm UTC

Request Review

Comment thread packages/mcp-cloudflare/src/code-mode/worker.test.ts Fixed
Comment on lines +117 to +120
const server = new McpServer({
name: "sentry-code-mode-experiment",
version: "0.1.0",
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

High severity vulnerability may affect your project—review required:
Line 117 lists a dependency (@modelcontextprotocol/server) with a known High severity vulnerability.

ℹ️ Why this matters

Affected versions of @modelcontextprotocol/sdk and @modelcontextprotocol/server are vulnerable to Allocation of Resources Without Limits or Throttling. McpServer places no limit on how many array elements and object keys it validates in tool-call arguments. A single unauthenticated HTTP request within the default 4 MiB body limit can exhaust the Node.js heap during validation and crash the server process (denial of service). After upgrading, also set the opt-in maxToolInputElements McpServer option and lower maxRequestBodySize.

References: GHSA

To resolve this comment:
Check if you expose the McpServer over an HTTP transport (Streamable HTTP, SSE, or createMcpHandler) rather than stdio only and it registers tools that accept input, especially arrays or records.

  • If you're affected, upgrade this dependency to at least version 2.3.0 at pnpm-lock.yaml.
  • If you're not affected, comment /fp we don't use this [condition]
💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

Comment on lines +161 to +163
const server = new ModernMcpServer(serverInfo, {
maxToolInputElements: MAX_MCP_TOOL_INPUT_ELEMENTS,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

High severity vulnerability may affect your project—review required:
Line 161 lists a dependency (@modelcontextprotocol/server) with a known High severity vulnerability.

ℹ️ Why this matters

Affected versions of @modelcontextprotocol/sdk and @modelcontextprotocol/server are vulnerable to Allocation of Resources Without Limits or Throttling. McpServer places no limit on how many array elements and object keys it validates in tool-call arguments. A single unauthenticated HTTP request within the default 4 MiB body limit can exhaust the Node.js heap during validation and crash the server process (denial of service). After upgrading, also set the opt-in maxToolInputElements McpServer option and lower maxRequestBodySize.

References: GHSA

To resolve this comment:
Check if you expose the McpServer over an HTTP transport (Streamable HTTP, SSE, or createMcpHandler) rather than stdio only and it registers tools that accept input, especially arrays or records.

  • If you're affected, upgrade this dependency to at least version 2.3.0 at pnpm-lock.yaml.
  • If you're not affected, comment /fp we don't use this [condition]
💬 Ignore this finding

To ignore this, reply with:

  • /fp <comment> for false positive
  • /ar <comment> for acceptable risk
  • /other <comment> for all other reasons

You can view more details on this finding in the Semgrep AppSec Platform here.

Comment thread packages/mcp-cloudflare/src/code-mode/http.ts
Comment thread packages/mcp-cloudflare/src/server/lib/mcp-handler.ts
Comment thread packages/mcp-cloudflare/src/code-mode/worker.test.ts
@betegon
betegon changed the base branch from main to bt/cloudflare-test-runtime October 27, 2026 10:32
@betegon
betegon force-pushed the bt/cloudflare-test-runtime branch from 7fb178a to 49d10be Compare October 27, 2026 13:28
betegon added a commit that referenced this pull request Oct 27, 2026
The Cloudflare test plugin still used an older Miniflare/workerd than
Wrangler, so updating the direct dependency alone left different
runtimes in local and integration tests.

Switch to `@cloudflare/vitest-plugin` 1.4.6 and align Miniflare/workerd
with Wrangler. Miniflare 5 removed `fetchMock`; an Undici outbound
service preserves the existing fixtures and `disableNetConnect()`
policy.

This is the prerequisite for #1670 (HTTP Code Mode), followed by #1675
(agent evals). Only seven test/dependency files move here; the broker,
permissions and production integration remain in #1670.

Validated independently on Node 24: **443 Cloudflare tests across 34
files**, root typechecks, lint and frozen install. The earlier full
workspace run had unrelated CLI fixture/platform failures; CLI fixes are
excluded. No deployment performed.
Base automatically changed from bt/cloudflare-test-runtime to main October 27, 2026 13:42

This branch was successfully deployed

1 active and 1 inactive (outdated) deployments
Preview — 9be49264 Deployed Oct 27, 2026 by vercel[bot]
Actions — 2718d905 Deployed Oct 26, 2026 by betegon via eval #1365
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