Skip to content

Mcp code mode#3510

Open
aditya520 wants to merge 7 commits intomainfrom
mcp-code-mode
Open

Mcp code mode#3510
aditya520 wants to merge 7 commits intomainfrom
mcp-code-mode

Conversation

@aditya520
Copy link
Member

@aditya520 aditya520 commented Mar 2, 2026

Summary

Rationale

How has this been tested?

  • Current tests cover my changes
  • Added new tests
  • Manually tested the code

Open with Devin

@vercel
Copy link

vercel bot commented Mar 2, 2026

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

7 Skipped Deployments
Project Deployment Actions Updated (UTC)
api-reference Skipped Skipped Mar 9, 2026 8:12pm
component-library Skipped Skipped Mar 9, 2026 8:12pm
developer-hub Skipped Skipped Mar 9, 2026 8:12pm
entropy-explorer Skipped Skipped Mar 9, 2026 8:12pm
insights Skipped Skipped Mar 9, 2026 8:12pm
proposals Skipped Skipped Mar 9, 2026 8:12pm
staking Skipped Skipped Mar 9, 2026 8:12pm

Request Review

@aditya520
Copy link
Member Author

@codex and @devin please review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64694656d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +40 to +42
["get_symbols", "get_historical_price", "get_candlestick_data", "get_latest_price"].map(
(name) => [name, (arg: unknown) => hostCall(name, arg)],
),

Choose a reason for hiding this comment

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

P0 Badge Prevent VM escape via host function constructors

The codemode methods are host-realm functions injected directly into untrusted execute code, which lets callers escape the sandbox by using a function constructor chain (for example codemode.get_symbols.constructor("return process.env")()). In the public Code Mode endpoint this gives arbitrary access to process, environment variables (including PYTH_PRO_ACCESS_TOKEN), and host capabilities, so token injection is no longer isolated to server-side code.

Useful? React with 👍 / 👎.

Comment on lines +56 to +58
const result = await runInNewContext(wrapped, sandbox, {
timeout: timeoutMs,
});

Choose a reason for hiding this comment

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

P1 Badge Enforce execution timeout for unresolved async code

The timeout passed to runInNewContext only limits synchronous script execution; if user code returns a never-settling promise (for example await new Promise(() => {})), await runInNewContext(...) can hang indefinitely. Because execute accepts untrusted code, this allows callers to pin requests and degrade service capacity despite the configured timeoutMs.

Useful? React with 👍 / 👎.

Comment on lines +90 to +91
: JSON.stringify(result.result);
const resultSizeBytes = Buffer.byteLength(resultText);

Choose a reason for hiding this comment

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

P2 Badge Handle undefined execute results before byte-length logging

When executed code does not explicitly return a value, result.result is undefined, so JSON.stringify(result.result) also returns undefined; passing that into Buffer.byteLength throws a type error and turns an otherwise valid execution into an internal failure. This is easy to trigger with common snippets that omit return, so execute should normalize undefined results before logging/response construction.

Useful? React with 👍 / 👎.

aditya520 and others added 3 commits March 6, 2026 16:22
Document a Cloudflare-first Code Mode path so API evolution does not require frequent MCP tool reshaping. Capture token-injection security and observability requirements to guide rollout.
- Add codemode executor (isolated-vm, 30s timeout, no network)
- Add codemode bindings: search, execute, get_latest_price (token-injected)
- Add createServerCodeModeOnly and pyth-mcp-codemode entrypoint
- Add pythProAccessToken config and PYTH_PRO_ACCESS_TOKEN env
- Add redact utils and logger serializers for token/sensitive data
- Add unit, integration, and security tests for Code Mode

Made-with: Cursor
Simplify search tool (remove code execution path), include full types
in execute description, fix redactSecrets false positives on keys like
author/authority/token_count, extract shared setupProcessCleanup in
server.ts, complete return types in types.ts, and add sandbox boundary
tests for timeout/process/require.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – component-library March 6, 2026 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference March 6, 2026 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – staking March 6, 2026 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub March 6, 2026 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals March 6, 2026 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer March 6, 2026 21:27 Inactive
@vercel vercel bot temporarily deployed to Preview – insights March 6, 2026 21:27 Inactive
…sults

- Sever prototype chain on injected host functions to prevent sandbox
  escape via .constructor("return process")()
- Race vm execution with a timer so never-settling promises also respect
  the configured timeoutMs
- Normalize undefined results before Buffer.byteLength to avoid TypeError
  when user code omits a return statement

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – component-library March 6, 2026 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – staking March 6, 2026 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – insights March 6, 2026 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference March 6, 2026 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer March 6, 2026 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals March 6, 2026 21:43 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub March 6, 2026 21:43 Inactive
@aditya520 aditya520 marked this pull request as ready for review March 9, 2026 14:13
@aditya520 aditya520 requested a review from a team as a code owner March 9, 2026 14:13
devin-ai-integration[bot]

This comment was marked as resolved.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b188620186

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const codemode = Object.fromEntries(
["get_symbols", "get_historical_price", "get_candlestick_data", "get_latest_price"].map(
(name) => {
const fn = (arg: unknown) => hostCall(name, arg);

Choose a reason for hiding this comment

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

P0 Badge Marshal host return values into sandbox realm

Setting Object.setPrototypeOf(fn, null) blocks codemode.*.constructor, but untrusted code can still escape through host objects returned by hostCall: const x = await codemode.get_symbols({}); x.constructor.constructor("return process")() yields host process in Node vm. Because bindings return plain host-realm objects, this keeps arbitrary environment/process access possible even after the function-constructor hardening.

Useful? React with 👍 / 👎.

Comment on lines +36 to +37
"build": "tsup src/index.ts src/http.ts --format esm --dts --clean",
"build": "tsup src/index.ts src/index-codemode.ts --format esm --dts --clean",

Choose a reason for hiding this comment

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

P1 Badge Restore HTTP entrypoint in build script

The scripts object defines build twice, and JSON keeps only the last one, so src/http.ts is no longer built. start still runs node dist/http.js, so the normal buildstart flow now fails at runtime because dist/http.js is missing.

Useful? React with 👍 / 👎.

Code mode uses node:vm instead of isolated-vm. The lockfile still
referenced the removed dependency, causing CI frozen-lockfile failures.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – proposals March 9, 2026 14:35 Inactive
@vercel vercel bot temporarily deployed to Preview – staking March 9, 2026 14:35 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library March 9, 2026 14:35 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference March 9, 2026 14:35 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer March 9, 2026 14:35 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub March 9, 2026 14:35 Inactive
@vercel vercel bot temporarily deployed to Preview – insights March 9, 2026 14:35 Inactive
devin-ai-integration[bot]

This comment was marked as resolved.

@vercel vercel bot temporarily deployed to Preview – staking March 9, 2026 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub March 9, 2026 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library March 9, 2026 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – api-reference March 9, 2026 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer March 9, 2026 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – insights March 9, 2026 14:59 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals March 9, 2026 14:59 Inactive
devin-ai-integration[bot]

This comment was marked as resolved.

Host-realm async functions return host-realm Promises whose prototype
chain allows escape: p.constructor.constructor("return process")().
Replace async binding functions with a bridge function created inside
the sandbox context that produces sandbox-realm Promises, preventing
prototype chain traversal back to host Function/process.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel vercel bot temporarily deployed to Preview – api-reference March 9, 2026 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – developer-hub March 9, 2026 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – entropy-explorer March 9, 2026 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – proposals March 9, 2026 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – insights March 9, 2026 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – staking March 9, 2026 20:12 Inactive
@vercel vercel bot temporarily deployed to Preview – component-library March 9, 2026 20:12 Inactive
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

View 15 additional findings in Devin Review.

Open in Devin Review

});

const trimmed = code.trim();
const isFnExpr = /^async\s+(?:\(|function\b)/.test(trimmed);
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Regex fails to detect async() arrow functions without space, causing incorrect code wrapping

The isFnExpr regex /^async\s+(?:\(|function\b)/ requires one or more whitespace characters (\s+) between async and (. When an LLM generates async(params) => { ... } (valid JavaScript with no space), the regex doesn't match, so the executor wraps it as (async () => { async(params) => { ... } })() instead of (async(params) => { ... })(). This produces a syntax error because async(params) is parsed as a function call to an undefined async identifier, followed by an invalid => token. The fix is to use \s* for the ( alternative while keeping \s+ for function: /^async(?:\s*\(|\s+function\b)/.

Suggested change
const isFnExpr = /^async\s+(?:\(|function\b)/.test(trimmed);
const isFnExpr = /^async(?:\s*\(|\s+function\b)/.test(trimmed);
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +99 to +101
Code Mode exposes these via `codemode.get_symbols`, `codemode.get_latest_price`, etc. inside `execute()`.

## Setup
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 README has misplaced Code Mode text under ### Build and broken heading hierarchy with ## Setup

The ### Build subsection (under ## Local Development) now contains an orphaned Code Mode description sentence (Code Mode exposes these via...) instead of the build command. The build command was moved into a new ## Setup top-level section, which breaks the document hierarchy — ## Setup sits at the same level as ## Local Development but the build instructions logically belong under ### Build. The Code Mode sentence appears to belong in the ## Modes or ## Tools (Legacy mode) section instead.

Prompt for agents
In apps/mcp/README.md, lines 98-101, the sentence 'Code Mode exposes these via codemode.get_symbols, codemode.get_latest_price, etc. inside execute().' appears to be misplaced under the '### Build' heading. It should be moved to the '## Modes' section (around line 51-64) or the '## Tools (Legacy mode)' section (around line 66). Additionally, the '## Setup' heading on line 101 should be removed or changed to '### Build' to restore the original subsection hierarchy under '## Local Development'. The build command on line 103-105 should remain under the '### Build' subsection.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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