Skip to content

Mcp code mode#3510

Draft
aditya520 wants to merge 4 commits intomainfrom
mcp-code-mode
Draft

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

Conversation

@aditya520
Copy link
Member

Summary

Rationale

How has this been tested?

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

@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 6, 2026 9:43pm
component-library Skipped Skipped Mar 6, 2026 9:43pm
developer-hub Skipped Skipped Mar 6, 2026 9:43pm
entropy-explorer Skipped Skipped Mar 6, 2026 9:43pm
insights Skipped Skipped Mar 6, 2026 9:43pm
proposals Skipped Skipped Mar 6, 2026 9:43pm
staking Skipped Skipped Mar 6, 2026 9:43pm

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
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