Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn
Overview
Code Mode is an opt-in Smart Routing capability ($smart and $smart/<group>) that lets an LLM write a short async JavaScript snippet to search for tools, call multiple upstream tools in loops, filter or aggregate intermediate payloads, and return only the final answer.By keeping intermediate payloads inside the sandbox instead of bouncing every raw upstream response back through the model context window, Code Mode reduces multi-step round trips and token consumption while reusing MCPHub’s exact caller-scoped authorization pipeline.Code Mode is off by default and must be explicitly enabled by an administrator.
Exposed Tools
When enabled under Settings → Smart Routing → Code Mode, $smart and $smart/<group> routes expose:
execute_code({ code }): Runs an async JavaScript function body in an isolated QuickJS-NG WebAssembly worker and returns { value, logs, toolCalls }.
execute_code_read({ code })(enabled by default when Code Mode is on; can be toggled off separately): Runs the same sandbox, but restricts tools.call(...) to tools whose descriptors declare readOnlyHint: true and do not set destructiveHint: true.
Existing Smart Routing meta-tools (search_tools, describe_tool, call_tool) remain available. describe_tool also returns a generated typescriptSignature derived from each tool’s inputSchema to help models write accurate tools.call(...) invocations.
MCP readOnlyHint and destructiveHint annotations are advisory hints self-declared by upstream servers. For hard security boundaries, configure MCPHub Tool Policies in addition to execute_code_read.
Sandbox API
Scripts run as the body of an async () => { ... } function. Top-level await and return are supported:
tools.call(toolName, args?): Invokes an authorized tool through MCPHub’s $smart call_tool path.
If the upstream tool returns isError: true, tools.call throws a JavaScript Error.
If structuredContent is present, it is returned directly.
Otherwise, a single JSON text block is parsed and returned as a JS value; plain text is returned as a string; mixed/binary results return the raw CallToolResult.
console.log / info / warn / error: Captured up to maxLogBytes and returned in logs (with truncatedLogs: true if capped).
Security Model & Isolation
QuickJS-NG WebAssembly in worker_threads: Guest code executes inside QuickJS-NG compiled to WebAssembly (quickjs-emscripten), isolated from Node.js and running off the main event loop.
No ambient capabilities: The sandbox has no access to fetch, network sockets, filesystem (fs), process, environment variables, require/import, or timers. Credentials never enter the sandbox.
Zero new permission surface: Every tools.call() bridges back to the main thread inside the caller’s live request and user context, enforcing group visibility, bearer-key exclusions and personal-key scopes, user-scoped runtimes, Tool Policies, TOOL_CALL_GUARD_ENABLED, hidden parameters, file staging, activity logging, and refusal of hub built-ins (mcphub_file_*) and recursive meta-tool calls.
Intermediate vs. final compression: When Tool Result Compression is enabled, intermediate tools.call() payloads stay uncompressed (bounded by maxToolResultBytes) so scripts can reliably parse JSON, while the final execute_code output is compressed once before returning to the model.
Elicitation & Sampling: Upstream elicitation requests are rejected with elicitation_unsupported while a script is running.
Limits & Configuration
Configure Code Mode in Settings → Smart Routing or via environment variables:
Setting
Environment Variable
Default
Range
Enable Code Mode
SMART_ROUTING_CODE_MODE_ENABLED
false
true / false
Read-Only Variant
SMART_ROUTING_CODE_MODE_READ_ONLY_ENABLED
true
true / false
Wall-Clock Timeout (ms)
SMART_ROUTING_CODE_MODE_TIMEOUT_MS
30000
500–120000
JS CPU Timeout (ms)
SMART_ROUTING_CODE_MODE_CPU_TIMEOUT_MS
5000
100–30000
Memory Cap (MB)
SMART_ROUTING_CODE_MODE_MEMORY_LIMIT_MB
32
4–256
Max Tool Calls
SMART_ROUTING_CODE_MODE_MAX_TOOL_CALLS
20
1–100
Max Source Size (bytes)
SMART_ROUTING_CODE_MODE_MAX_SOURCE_BYTES
32768
256–262144
Max Log Size (bytes)
SMART_ROUTING_CODE_MODE_MAX_LOG_BYTES
16384
256–131072
Max Intermediate Result (bytes)
SMART_ROUTING_CODE_MODE_MAX_TOOL_RESULT_BYTES
524288
4096–4194304
Max Final Output (bytes)
SMART_ROUTING_CODE_MODE_MAX_OUTPUT_BYTES
65536
1024–1048576
Max Concurrent Runs
SMART_ROUTING_CODE_MODE_MAX_CONCURRENT_RUNS
4
1–32
Error Kinds
When execution fails, execute_code returns isError: true with a structured error payload { error: { kind, message }, toolCalls }:
disabled — Code Mode or execute_code_read is turned off, or the route is not $smart.
syntax_error / runtime_error — Invalid JavaScript or uncaught exception.
timeout / cpu_timeout — Wall-clock timeout or JS CPU budget exceeded (worker terminated).
concurrency_limit — Too many concurrent sandbox runs active.
unauthorized / readonly_violation — Caller lacks access, attempted to call a hub built-in, or called a non-read-only tool from execute_code_read.
elicitation_unsupported — An upstream tool requested elicitation during script execution.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"MCPHub Documentation","description":"Open-source, self-hosted MCP gateway and control plane for connecting, controlling, and operating MCP servers.","colors":{"primary":"#16A34A","light":"#07C983","dark":"#15803D"},"logo":{"light":"https://mintcdn.com/samanhappy/9h46pIQJpM8j24KA/logo/light.svg?fit=max\u0026auto=format\u0026n=9h46pIQJpM8j24KA\u0026q=85\u0026s=0ad41a1afc62510dfcb4e07f4ae2c20a","dark":"https://mintcdn.com/samanhappy/9h46pIQJpM8j24KA/logo/dark.svg?fit=max\u0026auto=format\u0026n=9h46pIQJpM8j24KA\u0026q=85\u0026s=b155d5350c887f4b2ec803f958039595"},"favicon":"https://mintcdn.com/samanhappy/sxFj91voS1iOja8k/favicon.ico?fit=max\u0026auto=format\u0026n=sxFj91voS1iOja8k\u0026q=85\u0026s=a269daa3d6e65452887b8f192e4142ff","navbar":{"links":[{"href":"https://demo.mcphub.app","label":"Demo"}],"primary":{"type":"button","label":"Get Started","href":"https://docs.mcphub.app/quickstart"}},"footer":{"socials":{"github":"https://github.com/samanhappy/mcphub","discord":"https://discord.gg/2BJehJZVH5"}},"styling":{"latex":false},"navigation":{"global":{"anchors":[]},"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"samanhappy","hasAudioNarration":false,"actualSubdomain":"samanhappy","customDomains":["docs.mcphub.app"],"gitSource":{"type":"github","owner":"samanhappy","repo":"mcphub","deployBranch":"main","contentDirectory":"docs","isPrivate":true,"mountPath":"","label":"","_id":"6b10b4909ffae5051c400283"},"entitlements":{},"buildId":"6b1363cd65e0f0631a5413c0","clientVersion":"0.0.4453","searchFilterCounts":[{"language":"default","tag":"User Docs","count":27},{"language":"default","tag":"用户文档","count":22},{"language":"default","tag":"API","count":15},{"language":"default","tag":"接口","count":15},{"language":"default","tag":"Core Features","count":12},{"language":"default","tag":"核心功能","count":12},{"language":"default","tag":"Management Endpoints","count":10},{"language":"default","tag":"管理端点","count":10},{"language":"default","tag":"Configuration","count":7},{"language":"default","tag":"配置指南","count":7}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"auth-vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"starterQuestions":[],"googleFontsInlined":false},"customCss":[]}
{"page":{"pagePath":"features/code-mode","slug":"/features/code-mode","pageMetadata":{"title":"Code Mode","description":"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn","href":"/features/code-mode"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={code:`code`,em:`em`,li:`li`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,tbody:`tbody`,td:`td`,th:`th`,thead:`thead`,tr:`tr`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Table,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Table)_missingMdxReference(`Table`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(Heading,{level:`2`,id:`overview`,children:`Overview`}),`\n`,_jsxs(_components.p,{children:[_jsx(_components.strong,{children:`Code Mode`}),` is an opt-in Smart Routing capability (`,_jsx(_components.code,{children:`$smart`}),` and `,_jsx(_components.code,{children:`$smart/\u003cgroup>`}),`) that lets an LLM write a short async JavaScript snippet to search for tools, call multiple upstream tools in loops, filter or aggregate intermediate payloads, and return only the final answer.`]}),`\n`,_jsx(_components.p,{children:`By keeping intermediate payloads inside the sandbox instead of bouncing every raw upstream response back through the model context window, Code Mode reduces multi-step round trips and token consumption while reusing MCPHub’s exact caller-scoped authorization pipeline.`}),`\n`,_jsxs(_components.p,{children:[`Code Mode is `,_jsx(_components.strong,{children:`off by default`}),` and must be explicitly enabled by an administrator.`]}),`\n`,_jsx(Heading,{level:`2`,id:`exposed-tools`,children:`Exposed Tools`}),`\n`,_jsxs(_components.p,{children:[`When enabled under `,_jsx(_components.strong,{children:`Settings → Smart Routing → Code Mode`}),`, `,_jsx(_components.code,{children:`$smart`}),` and `,_jsx(_components.code,{children:`$smart/\u003cgroup>`}),` routes expose:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`execute_code({ code })`})}),`: Runs an async JavaScript function body in an isolated QuickJS-NG WebAssembly worker and returns `,_jsx(_components.code,{children:`{ value, logs, toolCalls }`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:_jsx(_components.code,{children:`execute_code_read({ code })`})}),` `,_jsx(_components.em,{children:`(enabled by default when Code Mode is on; can be toggled off separately)`}),`: Runs the same sandbox, but restricts `,_jsx(_components.code,{children:`tools.call(...)`}),` to tools whose descriptors declare `,_jsx(_components.code,{children:`readOnlyHint: true`}),` and do not set `,_jsx(_components.code,{children:`destructiveHint: true`}),`.`]}),`\n`]}),`\n`,_jsxs(_components.p,{children:[`Existing Smart Routing meta-tools (`,_jsx(_components.code,{children:`search_tools`}),`, `,_jsx(_components.code,{children:`describe_tool`}),`, `,_jsx(_components.code,{children:`call_tool`}),`) remain available. `,_jsx(_components.code,{children:`describe_tool`}),` also returns a generated `,_jsx(_components.code,{children:`typescriptSignature`}),` derived from each tool’s `,_jsx(_components.code,{children:`inputSchema`}),` to help models write accurate `,_jsx(_components.code,{children:`tools.call(...)`}),` invocations.`]}),`\n`,_jsx(Warning,{children:_jsxs(_components.p,{children:[`MCP `,_jsx(_components.code,{children:`readOnlyHint`}),` and `,_jsx(_components.code,{children:`destructiveHint`}),` annotations are `,_jsx(_components.strong,{children:`advisory hints self-declared by upstream servers`}),`. For hard security boundaries, configure MCPHub `,_jsx(_components.strong,{children:`Tool Policies`}),` in addition to `,_jsx(_components.code,{children:`execute_code_read`}),`.`]})}),`\n`,_jsx(Heading,{level:`2`,id:`sandbox-api`,children:`Sandbox API`}),`\n`,_jsxs(_components.p,{children:[`Scripts run as the body of an `,_jsx(_components.code,{children:`async () => { ... }`}),` function. Top-level `,_jsx(_components.code,{children:`await`}),` and `,_jsx(_components.code,{children:`return`}),` are supported:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`21`,language:`javascript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`javascript`,children:_jsxs(_components.code,{language:`javascript`,numberOfLines:`21`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` hits`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`search`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'github pull requests'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, { `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`limit:`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#B5CEA8`},children:` 5`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` prs`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`call`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'github-list_pull_requests'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` owner:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'samanhappy'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` repo:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'mcphub'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` state:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'open'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` failing`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` [];`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`for`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` pr`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` of`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` prs`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` const`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4FC1FF`},children:` status`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` tools`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`call`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`'github-get_commit_status'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` owner:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'samanhappy'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` repo:`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'mcphub'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` ref:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` pr`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`head`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`sha`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`,`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`status`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`state`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` ===`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` 'failure'`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` failing`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`push`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`({ `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`number:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` pr`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`number`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`title:`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` pr`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`title`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` });`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` }`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`}`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`console`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`log`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\"`Checked \"}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`prs`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#D4D4D4`},children:`.`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#9CDCFE`},children:`length`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#569CD6`},children:`}`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:\" PRs`\"}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`);`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` failing`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`;`})]}),`\n`]})})}),`\n`,_jsx(Heading,{level:`3`,id:`globals-available-inside-the-sandbox`,children:`Globals Available Inside the Sandbox`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`tools.search(query, { limit? })`}),`: Runs caller-scoped semantic tool search (`,_jsx(_components.code,{children:`search_tools`}),`).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`tools.call(toolName, args?)`}),`: Invokes an authorized tool through MCPHub’s `,_jsx(_components.code,{children:`$smart call_tool`}),` path.`,`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[`If the upstream tool returns `,_jsx(_components.code,{children:`isError: true`}),`, `,_jsx(_components.code,{children:`tools.call`}),` throws a JavaScript `,_jsx(_components.code,{children:`Error`}),`.`]}),`\n`,_jsxs(_components.li,{children:[`If `,_jsx(_components.code,{children:`structuredContent`}),` is present, it is returned directly.`]}),`\n`,_jsxs(_components.li,{children:[`Otherwise, a single JSON text block is parsed and returned as a JS value; plain text is returned as a string; mixed/binary results return the raw `,_jsx(_components.code,{children:`CallToolResult`}),`.`]}),`\n`]}),`\n`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`console.log / info / warn / error`}),`: Captured up to `,_jsx(_components.code,{children:`maxLogBytes`}),` and returned in `,_jsx(_components.code,{children:`logs`}),` (with `,_jsx(_components.code,{children:`truncatedLogs: true`}),` if capped).`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`security-model-\u0026-isolation`,children:`Security Model \u0026 Isolation`}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsxs(_components.strong,{children:[`QuickJS-NG WebAssembly in `,_jsx(_components.code,{children:`worker_threads`}),`:`]}),` Guest code executes inside QuickJS-NG compiled to WebAssembly (`,_jsx(_components.code,{children:`quickjs-emscripten`}),`), isolated from Node.js and running off the main event loop.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`No ambient capabilities:`}),` The sandbox has no access to `,_jsx(_components.code,{children:`fetch`}),`, network sockets, filesystem (`,_jsx(_components.code,{children:`fs`}),`), `,_jsx(_components.code,{children:`process`}),`, environment variables, `,_jsx(_components.code,{children:`require`}),`/`,_jsx(_components.code,{children:`import`}),`, or timers. Credentials never enter the sandbox.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Zero new permission surface:`}),` Every `,_jsx(_components.code,{children:`tools.call()`}),` bridges back to the main thread inside the caller’s live request and user context, enforcing group visibility, bearer-key exclusions and personal-key scopes, user-scoped runtimes, Tool Policies, `,_jsx(_components.code,{children:`TOOL_CALL_GUARD_ENABLED`}),`, hidden parameters, file staging, activity logging, and refusal of hub built-ins (`,_jsx(_components.code,{children:`mcphub_file_*`}),`) and recursive meta-tool calls.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Intermediate vs. final compression:`}),` When Tool Result Compression is enabled, intermediate `,_jsx(_components.code,{children:`tools.call()`}),` payloads stay uncompressed (bounded by `,_jsx(_components.code,{children:`maxToolResultBytes`}),`) so scripts can reliably parse JSON, while the final `,_jsx(_components.code,{children:`execute_code`}),` output is compressed once before returning to the model.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Elicitation \u0026 Sampling:`}),` Upstream elicitation requests are rejected with `,_jsx(_components.code,{children:`elicitation_unsupported`}),` while a script is running.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`limits-\u0026-configuration`,children:`Limits \u0026 Configuration`}),`\n`,_jsxs(_components.p,{children:[`Configure Code Mode in `,_jsx(_components.strong,{children:`Settings → Smart Routing`}),` or via environment variables:`]}),`\n`,_jsxs(Table,{children:[_jsx(_components.thead,{children:_jsxs(_components.tr,{children:[_jsx(_components.th,{children:`Setting`}),_jsx(_components.th,{children:`Environment Variable`}),_jsx(_components.th,{children:`Default`}),_jsx(_components.th,{children:`Range`})]})}),_jsxs(_components.tbody,{children:[_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Enable Code Mode`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_ENABLED`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`false`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`true`}),` / `,_jsx(_components.code,{children:`false`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Read-Only Variant`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_READ_ONLY_ENABLED`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`true`})}),_jsxs(_components.td,{children:[_jsx(_components.code,{children:`true`}),` / `,_jsx(_components.code,{children:`false`})]})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Wall-Clock Timeout (ms)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_TIMEOUT_MS`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`30000`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`500–120000`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`JS CPU Timeout (ms)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_CPU_TIMEOUT_MS`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`5000`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`100–30000`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Memory Cap (MB)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MEMORY_LIMIT_MB`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`32`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`4–256`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Tool Calls`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MAX_TOOL_CALLS`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`20`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`1–100`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Source Size (bytes)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MAX_SOURCE_BYTES`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`32768`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`256–262144`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Log Size (bytes)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MAX_LOG_BYTES`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`16384`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`256–131072`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Intermediate Result (bytes)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MAX_TOOL_RESULT_BYTES`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`524288`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`4096–4194304`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Final Output (bytes)`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MAX_OUTPUT_BYTES`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`65536`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`1024–1048576`})})]}),_jsxs(_components.tr,{children:[_jsx(_components.td,{children:`Max Concurrent Runs`}),_jsx(_components.td,{children:_jsx(_components.code,{children:`SMART_ROUTING_CODE_MODE_MAX_CONCURRENT_RUNS`})}),_jsx(_components.td,{\"data-numeric\":`true`,children:_jsx(_components.code,{children:`4`})}),_jsx(_components.td,{children:_jsx(_components.code,{children:`1–32`})})]})]})]}),`\n`,_jsx(Heading,{level:`2`,id:`error-kinds`,children:`Error Kinds`}),`\n`,_jsxs(_components.p,{children:[`When execution fails, `,_jsx(_components.code,{children:`execute_code`}),` returns `,_jsx(_components.code,{children:`isError: true`}),` with a structured error payload `,_jsx(_components.code,{children:`{ error: { kind, message }, toolCalls }`}),`:`]}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`disabled`}),` — Code Mode or `,_jsx(_components.code,{children:`execute_code_read`}),` is turned off, or the route is not `,_jsx(_components.code,{children:`$smart`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`syntax_error`}),` / `,_jsx(_components.code,{children:`runtime_error`}),` — Invalid JavaScript or uncaught exception.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`timeout`}),` / `,_jsx(_components.code,{children:`cpu_timeout`}),` — Wall-clock timeout or JS CPU budget exceeded (worker terminated).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`memory_limit`}),` — QuickJS heap limit exceeded.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`call_budget_exceeded`}),` — Script exceeded `,_jsx(_components.code,{children:`maxToolCalls`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`source_too_large`}),` / `,_jsx(_components.code,{children:`tool_result_too_large`}),` / `,_jsx(_components.code,{children:`output_too_large`}),` — Payload exceeded configured byte limits.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`concurrency_limit`}),` — Too many concurrent sandbox runs active.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`unauthorized`}),` / `,_jsx(_components.code,{children:`readonly_violation`}),` — Caller lacks access, attempted to call a hub built-in, or called a non-read-only tool from `,_jsx(_components.code,{children:`execute_code_read`}),`.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.code,{children:`elicitation_unsupported`}),` — An upstream tool requested elicitation during script execution.`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Code Mode","description":"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn","href":"/features/code-mode"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Overview","slug":"overview","depth":2,"children":[]},{"title":"Exposed Tools","slug":"exposed-tools","depth":2,"children":[]},{"title":"Sandbox API","slug":"sandbox-api","depth":2,"children":[{"title":"Globals Available Inside the Sandbox","slug":"globals-available-inside-the-sandbox","depth":3,"children":[]}]},{"title":"Security Model \u0026 Isolation","slug":"security-model-\u0026-isolation","depth":2,"children":[]},{"title":"Limits \u0026 Configuration","slug":"limits-\u0026-configuration","depth":2,"children":[]},{"title":"Error Kinds","slug":"error-kinds","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"samanhappy","siteName":"MCPHub Documentation","title":"Code Mode - MCPHub Documentation","contextualStarterQuestions":[],"navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-26T08:57:33.041Z","originalFileLocation":"features/code-mode.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn\">\u003cmeta data-mint-head name=\"application-name\" content=\"MCPHub Documentation\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Code Mode - MCPHub Documentation\">\u003cmeta data-mint-head property=\"og:description\" content=\"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"MCPHub Documentation\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.mcphub.app/features/code-mode\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://samanhappy.mintlify.site/_mintlify/api/og/v2?division=Core+Features\u0026amp;title=Code+Mode\u0026amp;description=Run+model-written+JavaScript+in+a+QuickJS+WebAssembly+sandbox+to+orchestrate+authorized+MCPHub+tools+in+a+single+turn\u0026amp;theme=2d0e772a0ee670b6d177465b\u0026amp;signature=9635cbbdb4511f3a8358c1958a23071176325a89fa0aa3053c641ae12ad321b5\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Code Mode - MCPHub Documentation\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://samanhappy.mintlify.site/_mintlify/api/og/v2?division=Core+Features\u0026amp;title=Code+Mode\u0026amp;description=Run+model-written+JavaScript+in+a+QuickJS+WebAssembly+sandbox+to+orchestrate+authorized+MCPHub+tools+in+a+single+turn\u0026amp;theme=2d0e772a0ee670b6d177465b\u0026amp;signature=9635cbbdb4511f3a8358c1958a23071176325a89fa0aa3053c641ae12ad321b5\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/samanhappy/l9hRXb8qpyttGyMz/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"MCPHub Documentation\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#16A34A\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.mcphub.app/features/code-mode\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/features/code-mode.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.mcphub.app/#organization\",\"name\":\"MCPHub Documentation\",\"url\":\"https://docs.mcphub.app\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/samanhappy/9h46pIQJpM8j24KA/logo/light.svg?fit=max\u0026auto=format\u0026n=9h46pIQJpM8j24KA\u0026q=85\u0026s=0ad41a1afc62510dfcb4e07f4ae2c20a\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.mcphub.app#website\",\"name\":\"MCPHub Documentation\",\"url\":\"https://docs.mcphub.app\",\"publisher\":{\"@id\":\"https://docs.mcphub.app/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.mcphub.app/features/code-mode#webpage\",\"url\":\"https://docs.mcphub.app/features/code-mode\",\"name\":\"Code Mode\",\"description\":\"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn\",\"dateModified\":\"2026-11-26T08:57:33.041Z\",\"isPartOf\":{\"@id\":\"https://docs.mcphub.app#website\"},\"breadcrumb\":{\"@id\":\"https://docs.mcphub.app/features/code-mode#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.mcphub.app/features/code-mode#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Core Features\",\"item\":\"https://docs.mcphub.app/features/server-management\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Code Mode\",\"item\":\"https://docs.mcphub.app/features/code-mode\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://docs.mcphub.app/features/code-mode#article\",\"headline\":\"Code Mode\",\"name\":\"Code Mode\",\"description\":\"Run model-written JavaScript in a QuickJS WebAssembly sandbox to orchestrate authorized MCPHub tools in a single turn\",\"url\":\"https://docs.mcphub.app/features/code-mode\",\"mainEntityOfPage\":{\"@id\":\"https://docs.mcphub.app/features/code-mode#webpage\"},\"dateModified\":\"2026-11-26T08:57:33.041Z\",\"publisher\":{\"@id\":\"https://docs.mcphub.app/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.mcphub.app#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"MCPHub Documentation\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"MCPHub Documentation\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/features/code-mode.md","siteName":"MCPHub Documentation","nav":{"global":{"anchors":[]},"tabs":[{"tab":"User Docs","groups":[{"group":"Get Started","pages":[{"title":"MCPHub","href":""},{"title":"Quick Start Guide","href":"/quickstart"},{"title":"Installation Guide","href":"/installation"}]},{"group":"Core Features","pages":[{"title":"Server Management","href":"/features/server-management"},{"title":"Per-user Credentials","href":"/features/per-user-credentials"},{"title":"Group Management","href":"/features/group-management"},{"title":"Smart Routing","description":"AI-powered tool discovery using vector semantic search","href":"/features/smart-routing"},{"title":"Code Mode","href":"/features/code-mode"},{"title":"File Staging","description":"Let stdio tools work with uploaded copies of client files","href":"/features/file-staging"},{"title":"MCP Apps","href":"/features/mcp-apps"},{"title":"Skills over MCP","href":"/features/skills"},{"title":null,"href":"/features/oauth"},{"title":"Authentication \u0026 Security","href":"/features/authentication"},{"title":"Monitoring \u0026 Observability","href":"/features/monitoring"},{"title":"CLI","href":"/features/cli"}]},{"group":"Configuration","pages":[{"title":"MCP Settings Configuration","href":"/configuration/mcp-settings"},{"title":"Environment Variables","href":"/configuration/environment-variables"},{"title":"Docker Setup","href":"/configuration/docker-setup"},{"title":"Credential Key Upgrade and Recovery","href":"/configuration/credential-key-upgrade"},{"title":"Nginx Configuration","href":"/configuration/nginx"},{"title":"Database Configuration","href":"/configuration/database-configuration"},{"title":"Multiple Replicas","href":"/configuration/replicas"}]},{"group":"Development","pages":[{"title":"Development","href":"/development"},{"title":"Getting Started with Development","href":"/development/getting-started"},{"title":"Architecture","href":"/development/architecture"},{"title":"Embedding Lifecycle","href":"/development/embedding-lifecycle"},{"title":"Contributing to MCPHub","href":"/development/contributing"}]}]},{"tab":"用户文档","pages":[{"title":"用户文档","href":"/zh"}]},{"tab":"API","pages":[{"title":"API","href":"/api-reference/introduction"}]},{"tab":"接口","pages":[{"title":"接口","href":"/zh/api-reference/introduction"}]}]},"basePath":"","title":"Code Mode - MCPHub Documentation","deploymentId":"dpl_BLZw3QngerHodH9E8mGgC4v752y3","buildId":"dpl_BLZw3QngerHodH9E8mGgC4v752y3","dynamics":[],"chunks":[]}