[{"data":1,"prerenderedAt":2767},["ShallowReactive",2],{"navigation_docs":3,"-advanced-code-mode":139,"-advanced-code-mode-surround":2762},[4,40,65,110],{"title":5,"path":6,"stem":7,"children":8,"page":39},"Getting Started","\u002Fgetting-started","1.getting-started",[9,14,19,24,29,34],{"title":10,"path":11,"stem":12,"icon":13},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F1.introduction","i-lucide-book-open",{"title":15,"path":16,"stem":17,"icon":18},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F2.installation","i-lucide-download",{"title":20,"path":21,"stem":22,"icon":23},"Configuration","\u002Fgetting-started\u002Fconfiguration","1.getting-started\u002F3.configuration","i-lucide-settings",{"title":25,"path":26,"stem":27,"icon":28},"MCP Inspector","\u002Fgetting-started\u002Finspector","1.getting-started\u002F4.inspector","i-lucide-circuit-board",{"title":30,"path":31,"stem":32,"icon":33},"Connection","\u002Fgetting-started\u002Fconnection","1.getting-started\u002F5.connection","i-lucide-plug",{"title":35,"path":36,"stem":37,"icon":38},"Agent Skills","\u002Fgetting-started\u002Fagent-skills","1.getting-started\u002F6.agent-skills","i-lucide-sparkles",false,{"title":41,"path":42,"stem":43,"children":44,"page":39},"Core Concepts","\u002Fcore-concepts","2.core-concepts",[45,50,55,60],{"title":46,"path":47,"stem":48,"icon":49},"Tools","\u002Fcore-concepts\u002Ftools","2.core-concepts\u002F2.tools","i-lucide-wrench",{"title":51,"path":52,"stem":53,"icon":54},"Resources","\u002Fcore-concepts\u002Fresources","2.core-concepts\u002F3.resources","i-lucide-package",{"title":56,"path":57,"stem":58,"icon":59},"Prompts","\u002Fcore-concepts\u002Fprompts","2.core-concepts\u002F4.prompts","i-lucide-message-square",{"title":61,"path":62,"stem":63,"icon":64},"Handlers","\u002Fcore-concepts\u002Fhandlers","2.core-concepts\u002F5.handlers","i-lucide-server",{"title":66,"path":67,"stem":68,"children":69,"page":39},"Advanced Topics","\u002Fadvanced","3.advanced",[70,75,80,85,90,95,100,105],{"title":71,"path":72,"stem":73,"icon":74},"Custom Paths","\u002Fadvanced\u002Fcustom-paths","3.advanced\u002F1.custom-paths","i-lucide-folder",{"title":76,"path":77,"stem":78,"icon":79},"Middleware","\u002Fadvanced\u002Fmiddleware","3.advanced\u002F2.middleware","i-lucide-shield",{"title":81,"path":82,"stem":83,"icon":84},"TypeScript","\u002Fadvanced\u002Ftypescript","3.advanced\u002F3.typescript","i-lucide-type",{"title":86,"path":87,"stem":88,"icon":89},"Hooks","\u002Fadvanced\u002Fhooks","3.advanced\u002F4.hooks","i-lucide-webhook",{"title":91,"path":92,"stem":93,"icon":94},"MCP Evals","\u002Fadvanced\u002Fevals","3.advanced\u002F5.evals","i-lucide-flask-conical",{"title":96,"path":97,"stem":98,"icon":99},"Sessions","\u002Fadvanced\u002Fsessions","3.advanced\u002F6.sessions","i-lucide-database",{"title":101,"path":102,"stem":103,"icon":104},"Dynamic Definitions","\u002Fadvanced\u002Fdynamic-definitions","3.advanced\u002F7.dynamic-definitions","i-lucide-toggle-right",{"title":106,"path":107,"stem":108,"icon":109},"Code Mode","\u002Fadvanced\u002Fcode-mode","3.advanced\u002F8.code-mode","i-lucide-code",{"title":111,"path":112,"stem":113,"children":114,"page":39},"Examples","\u002Fexamples","4.examples",[115,120,125,130,135],{"title":116,"path":117,"stem":118,"icon":119},"Authentication","\u002Fexamples\u002Fauthentication","4.examples\u002F1.authentication","i-lucide-shield-check",{"title":121,"path":122,"stem":123,"icon":124},"API Integration","\u002Fexamples\u002Fapi-integration","4.examples\u002F2.api-integration","i-lucide-globe",{"title":126,"path":127,"stem":128,"icon":129},"Common Patterns","\u002Fexamples\u002Fcommon-patterns","4.examples\u002F3.common-patterns","i-lucide-lightbulb",{"title":131,"path":132,"stem":133,"icon":134},"File Operations","\u002Fexamples\u002Ffile-operations","4.examples\u002F4.file-operations","i-lucide-file",{"title":136,"path":137,"stem":138,"icon":59},"Prompt Examples","\u002Fexamples\u002Fprompt-examples","4.examples\u002F5.prompt-examples",{"id":140,"title":106,"body":141,"description":2754,"extension":2755,"links":2756,"meta":2757,"navigation":2758,"path":107,"seo":2759,"stem":108,"__hash__":2761},"docs\u002F3.advanced\u002F8.code-mode.md",{"type":142,"value":143,"toc":2725},"minimark",[144,149,157,231,240,244,251,256,266,359,366,379,383,386,427,431,435,446,517,521,528,674,680,684,687,709,713,728,1346,1350,1357,1452,1534,1537,1543,1560,1605,1608,1662,1667,1671,1677,1747,1756,1765,1769,1776,1780,1792,1834,1838,1841,1878,1882,1885,1913,1916,1920,2011,2015,2018,2048,2052,2059,2063,2066,2543,2562,2566,2572,2630,2639,2643,2649,2694,2698,2721],[145,146,148],"h2",{"id":147},"what-is-code-mode","What is Code Mode?",[150,151,152,153,156],"p",{},"Code Mode replaces the traditional multi-turn tool calling pattern with a single ",[154,155,154],"code",{}," tool. Instead of the LLM calling tools one at a time — each requiring a round-trip — it writes JavaScript code that orchestrates multiple tools in one execution.",[158,159,160,174],"table",{},[161,162,163],"thead",{},[164,165,166,169,172],"tr",{},[167,168],"th",{},[167,170,171],{},"Traditional MCP",[167,173,106],{},[175,176,177,192,205,218],"tbody",{},[164,178,179,186,189],{},[180,181,182],"td",{},[183,184,185],"strong",{},"Pattern",[180,187,188],{},"LLM calls tools one by one",[180,190,191],{},"LLM writes JS that calls tools",[164,193,194,199,202],{},[180,195,196],{},[183,197,198],{},"Round-trips",[180,200,201],{},"One per tool call",[180,203,204],{},"One for all operations",[164,206,207,212,215],{},[180,208,209],{},[183,210,211],{},"Complex logic",[180,213,214],{},"Multiple turns for conditionals\u002Floops",[180,216,217],{},"Native JS control flow",[164,219,220,225,228],{},[180,221,222],{},[183,223,224],{},"Token usage",[180,226,227],{},"Higher (repeated context)",[180,229,230],{},"Lower (single invocation)",[232,233,235,236,239],"callout",{"color":234,"icon":94},"warning","Code Mode is ",[183,237,238],{},"experimental for now",". The API may evolve as we stabilize this feature based on feedback.",[145,241,243],{"id":242},"why-code-mode","Why Code Mode?",[150,245,246,247,250],{},"Every LLM round-trip resends ",[183,248,249],{},"all tool descriptions"," as context. With traditional MCP, a task that requires 5 steps with 50 tools sends the full tool catalog 5 times — that's 15,500 tokens just for tool descriptions. Code Mode sends compact TypeScript signatures in a single tool, cutting that to ~3,000 tokens.",[252,253,255],"h3",{"id":254},"the-scaling-problem","The scaling problem",[150,257,258,259,262,263,265],{},"In traditional MCP, tool description overhead scales as ",[183,260,261],{},"tools × round-trips",". Code Mode replaces all tools with one ",[154,264,154],{}," tool containing compact type signatures — and usually needs fewer round-trips.",[158,267,268,282],{},[161,269,270],{},[164,271,272,275,277,279],{},[167,273,274],{},"Server size",[167,276,171],{},[167,278,106],{},[167,280,281],{},"Savings",[175,283,284,303,322,341],{},[164,285,286,292,295,298],{},[180,287,288,291],{},[183,289,290],{},"10 tools",", 3-step task",[180,293,294],{},"~1,860 tokens in tool descriptions",[180,296,297],{},"~920 tokens",[180,299,300],{},[183,301,302],{},"-51%",[164,304,305,311,314,317],{},[180,306,307,310],{},[183,308,309],{},"25 tools",", 4-step task",[180,312,313],{},"~6,200 tokens",[180,315,316],{},"~1,700 tokens",[180,318,319],{},[183,320,321],{},"-73%",[164,323,324,330,333,336],{},[180,325,326,329],{},[183,327,328],{},"50 tools",", 5-step task",[180,331,332],{},"~15,500 tokens",[180,334,335],{},"~3,000 tokens",[180,337,338],{},[183,339,340],{},"-81%",[164,342,343,348,351,354],{},[180,344,345,329],{},[183,346,347],{},"100 tools",[180,349,350],{},"~31,000 tokens",[180,352,353],{},"~5,600 tokens",[180,355,356],{},[183,357,358],{},"-82%",[150,360,361,362,365],{},"These numbers represent tool description overhead only. Total savings depend on the task, but the trend is clear: ",[183,363,364],{},"the more tools you have, the bigger the savings",".",[232,367,370,371,374,375,378],{"color":368,"icon":369},"primary","i-lucide-zap","On a real benchmark with Claude Sonnet (9 tools, 7 tasks), Code Mode saved ",[183,372,373],{},"15% of total tokens overall"," and up to ",[183,376,377],{},"33% on complex batch operations"," — collapsing 8 tool calls into a single JavaScript block.",[252,380,382],{"id":381},"beyond-token-savings","Beyond token savings",[150,384,385],{},"Code Mode also unlocks patterns that traditional MCP cannot do efficiently:",[387,388,389,400,409,418],"ul",{},[390,391,392,395,396,399],"li",{},[183,393,394],{},"Parallel execution"," — ",[154,397,398],{},"Promise.all()"," for independent calls instead of sequential round-trips",[390,401,402,395,405,408],{},[183,403,404],{},"Conditional logic",[154,406,407],{},"if\u002Felse"," branching without an extra LLM step",[390,410,411,395,414,417],{},[183,412,413],{},"Loops",[154,415,416],{},"for"," over data instead of repeating tool calls one by one",[390,419,420,395,423,426],{},[183,421,422],{},"Error handling",[154,424,425],{},"try\u002Fcatch"," to handle failures mid-workflow",[145,428,430],{"id":429},"setup","Setup",[252,432,434],{"id":433},"_1-install-secure-exec","1. Install secure-exec",[150,436,437,438,445],{},"Code Mode uses ",[439,440,444],"a",{"href":441,"rel":442},"https:\u002F\u002Fgithub.com\u002Fnicolo-ribaudo\u002Fsecure-exec",[443],"nofollow","secure-exec"," to run LLM-generated code in a secure V8 isolate:",[447,448,449,474,489,503],"code-group",{},[450,451,457],"pre",{"className":452,"code":453,"filename":454,"language":455,"meta":456,"style":456},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","pnpm add secure-exec\n","pnpm","bash","",[154,458,459],{"__ignoreMap":456},[460,461,464,467,471],"span",{"class":462,"line":463},"line",1,[460,465,454],{"class":466},"sBMFI",[460,468,470],{"class":469},"sfazB"," add",[460,472,473],{"class":469}," secure-exec\n",[450,475,478],{"className":452,"code":476,"filename":477,"language":455,"meta":456,"style":456},"npm install secure-exec\n","npm",[154,479,480],{"__ignoreMap":456},[460,481,482,484,487],{"class":462,"line":463},[460,483,477],{"class":466},[460,485,486],{"class":469}," install",[460,488,473],{"class":469},[450,490,493],{"className":452,"code":491,"filename":492,"language":455,"meta":456,"style":456},"yarn add secure-exec\n","yarn",[154,494,495],{"__ignoreMap":456},[460,496,497,499,501],{"class":462,"line":463},[460,498,492],{"class":466},[460,500,470],{"class":469},[460,502,473],{"class":469},[450,504,507],{"className":452,"code":505,"filename":506,"language":455,"meta":456,"style":456},"bun add secure-exec\n","bun",[154,508,509],{"__ignoreMap":456},[460,510,511,513,515],{"class":462,"line":463},[460,512,506],{"class":466},[460,514,470],{"class":469},[460,516,473],{"class":469},[252,518,520],{"id":519},"_2-enable-on-a-handler","2. Enable on a handler",[150,522,523,524,527],{},"Add ",[154,525,526],{},"experimental_codeMode"," to any handler:",[447,529,530,592],{},[450,531,536],{"className":532,"code":533,"filename":534,"language":535,"meta":456,"style":456},"language-typescript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F server\u002Fmcp\u002Findex.ts\nexport default defineMcpHandler({\n  experimental_codeMode: true,\n})\n","Default handler","typescript",[154,537,538,544,566,583],{"__ignoreMap":456},[460,539,540],{"class":462,"line":463},[460,541,543],{"class":542},"sHwdD","\u002F\u002F server\u002Fmcp\u002Findex.ts\n",[460,545,547,551,554,558,562],{"class":462,"line":546},2,[460,548,550],{"class":549},"s7zQu","export",[460,552,553],{"class":549}," default",[460,555,557],{"class":556},"s2Zo4"," defineMcpHandler",[460,559,561],{"class":560},"sTEyZ","(",[460,563,565],{"class":564},"sMK4o","{\n",[460,567,569,573,576,580],{"class":462,"line":568},3,[460,570,572],{"class":571},"swJcz","  experimental_codeMode",[460,574,575],{"class":564},":",[460,577,579],{"class":578},"sfNiH"," true",[460,581,582],{"class":564},",\n",[460,584,586,589],{"class":462,"line":585},4,[460,587,588],{"class":564},"}",[460,590,591],{"class":560},")\n",[450,593,596],{"className":532,"code":594,"filename":595,"language":535,"meta":456,"style":456},"\u002F\u002F server\u002Fmcp\u002Fai-agent.ts\nexport default defineMcpHandler({\n  name: 'ai-agent',\n  experimental_codeMode: true,\n  tools: [getUserTool, listTodosTool, createTodoTool],\n})\n","Custom handler",[154,597,598,603,615,633,643,667],{"__ignoreMap":456},[460,599,600],{"class":462,"line":463},[460,601,602],{"class":542},"\u002F\u002F server\u002Fmcp\u002Fai-agent.ts\n",[460,604,605,607,609,611,613],{"class":462,"line":546},[460,606,550],{"class":549},[460,608,553],{"class":549},[460,610,557],{"class":556},[460,612,561],{"class":560},[460,614,565],{"class":564},[460,616,617,620,622,625,628,631],{"class":462,"line":568},[460,618,619],{"class":571},"  name",[460,621,575],{"class":564},[460,623,624],{"class":564}," '",[460,626,627],{"class":469},"ai-agent",[460,629,630],{"class":564},"'",[460,632,582],{"class":564},[460,634,635,637,639,641],{"class":462,"line":585},[460,636,572],{"class":571},[460,638,575],{"class":564},[460,640,579],{"class":578},[460,642,582],{"class":564},[460,644,646,649,651,654,657,660,662,665],{"class":462,"line":645},5,[460,647,648],{"class":571},"  tools",[460,650,575],{"class":564},[460,652,653],{"class":560}," [getUserTool",[460,655,656],{"class":564},",",[460,658,659],{"class":560}," listTodosTool",[460,661,656],{"class":564},[460,663,664],{"class":560}," createTodoTool]",[460,666,582],{"class":564},[460,668,670,672],{"class":462,"line":669},6,[460,671,588],{"class":564},[460,673,591],{"class":560},[150,675,676,677,679],{},"That's it. The module replaces all your tools with a single ",[154,678,154],{}," tool that the LLM uses to orchestrate them.",[145,681,683],{"id":682},"how-it-works","How It Works",[150,685,686],{},"When Code Mode is enabled:",[688,689,690,693,699,706],"ol",{},[390,691,692],{},"All registered tools are converted to TypeScript type definitions",[390,694,695,696,698],{},"A ",[154,697,154],{}," tool is created with those types embedded in its description",[390,700,701,702,705],{},"The LLM writes JavaScript using a ",[154,703,704],{},"codemode"," object to call tools",[390,707,708],{},"The code runs in a V8 isolate with only RPC access to your tools",[252,710,712],{"id":711},"example-what-the-llm-generates","Example: what the LLM generates",[150,714,715,716,719,720,723,724,727],{},"Given tools ",[154,717,718],{},"get-user",", ",[154,721,722],{},"list-todos",", and ",[154,725,726],{},"create-todo",", the LLM receives type definitions and writes code like:",[447,729,730,949,1122],{},[450,731,736],{"className":732,"code":733,"filename":734,"language":735,"meta":456,"style":456},"language-javascript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","const user = await codemode.get_user({ id: \"123\" });\nconst todos = await codemode.list_todos({ userId: user.id });\n\nif (todos.length === 0) {\n  await codemode.create_todo({\n    title: \"Welcome task\",\n    userId: user.id,\n  });\n}\n\nreturn { user, todos };\n","Sequential calls","javascript",[154,737,738,789,830,836,861,877,893,910,920,926,931],{"__ignoreMap":456},[460,739,740,744,747,750,753,756,758,761,763,766,769,771,774,777,780,783,786],{"class":462,"line":463},[460,741,743],{"class":742},"spNyl","const",[460,745,746],{"class":560}," user ",[460,748,749],{"class":564},"=",[460,751,752],{"class":549}," await",[460,754,755],{"class":560}," codemode",[460,757,365],{"class":564},[460,759,760],{"class":556},"get_user",[460,762,561],{"class":560},[460,764,765],{"class":564},"{",[460,767,768],{"class":571}," id",[460,770,575],{"class":564},[460,772,773],{"class":564}," \"",[460,775,776],{"class":469},"123",[460,778,779],{"class":564},"\"",[460,781,782],{"class":564}," }",[460,784,785],{"class":560},")",[460,787,788],{"class":564},";\n",[460,790,791,793,796,798,800,802,804,807,809,811,814,816,819,821,824,826,828],{"class":462,"line":546},[460,792,743],{"class":742},[460,794,795],{"class":560}," todos ",[460,797,749],{"class":564},[460,799,752],{"class":549},[460,801,755],{"class":560},[460,803,365],{"class":564},[460,805,806],{"class":556},"list_todos",[460,808,561],{"class":560},[460,810,765],{"class":564},[460,812,813],{"class":571}," userId",[460,815,575],{"class":564},[460,817,818],{"class":560}," user",[460,820,365],{"class":564},[460,822,823],{"class":560},"id ",[460,825,588],{"class":564},[460,827,785],{"class":560},[460,829,788],{"class":564},[460,831,832],{"class":462,"line":568},[460,833,835],{"emptyLinePlaceholder":834},true,"\n",[460,837,838,841,844,846,849,852,856,859],{"class":462,"line":585},[460,839,840],{"class":549},"if",[460,842,843],{"class":560}," (todos",[460,845,365],{"class":564},[460,847,848],{"class":560},"length ",[460,850,851],{"class":564},"===",[460,853,855],{"class":854},"sbssI"," 0",[460,857,858],{"class":560},") ",[460,860,565],{"class":564},[460,862,863,866,868,870,873,875],{"class":462,"line":645},[460,864,865],{"class":549},"  await",[460,867,755],{"class":560},[460,869,365],{"class":564},[460,871,872],{"class":556},"create_todo",[460,874,561],{"class":571},[460,876,565],{"class":564},[460,878,879,882,884,886,889,891],{"class":462,"line":669},[460,880,881],{"class":571},"    title",[460,883,575],{"class":564},[460,885,773],{"class":564},[460,887,888],{"class":469},"Welcome task",[460,890,779],{"class":564},[460,892,582],{"class":564},[460,894,896,899,901,903,905,908],{"class":462,"line":895},7,[460,897,898],{"class":571},"    userId",[460,900,575],{"class":564},[460,902,818],{"class":560},[460,904,365],{"class":564},[460,906,907],{"class":560},"id",[460,909,582],{"class":564},[460,911,913,916,918],{"class":462,"line":912},8,[460,914,915],{"class":564},"  }",[460,917,785],{"class":571},[460,919,788],{"class":564},[460,921,923],{"class":462,"line":922},9,[460,924,925],{"class":564},"}\n",[460,927,929],{"class":462,"line":928},10,[460,930,835],{"emptyLinePlaceholder":834},[460,932,934,937,940,942,944,946],{"class":462,"line":933},11,[460,935,936],{"class":549},"return",[460,938,939],{"class":564}," {",[460,941,818],{"class":560},[460,943,656],{"class":564},[460,945,795],{"class":560},[460,947,948],{"class":564},"};\n",[450,950,953],{"className":732,"code":951,"filename":952,"language":735,"meta":456,"style":456},"const [users, products, orders] = await Promise.all([\n  codemode.list_users(),\n  codemode.list_products(),\n  codemode.list_orders({ status: \"pending\" }),\n]);\n\nreturn {\n  userCount: users.length,\n  productCount: products.length,\n  pendingOrders: orders.length,\n};\n","Parallel calls",[154,954,955,994,1009,1022,1053,1060,1064,1071,1088,1103,1118],{"__ignoreMap":456},[460,956,957,959,962,965,967,970,972,975,978,981,983,986,988,991],{"class":462,"line":463},[460,958,743],{"class":742},[460,960,961],{"class":564}," [",[460,963,964],{"class":560},"users",[460,966,656],{"class":564},[460,968,969],{"class":560}," products",[460,971,656],{"class":564},[460,973,974],{"class":560}," orders",[460,976,977],{"class":564},"]",[460,979,980],{"class":564}," =",[460,982,752],{"class":549},[460,984,985],{"class":466}," Promise",[460,987,365],{"class":564},[460,989,990],{"class":556},"all",[460,992,993],{"class":560},"([\n",[460,995,996,999,1001,1004,1007],{"class":462,"line":546},[460,997,998],{"class":560},"  codemode",[460,1000,365],{"class":564},[460,1002,1003],{"class":556},"list_users",[460,1005,1006],{"class":560},"()",[460,1008,582],{"class":564},[460,1010,1011,1013,1015,1018,1020],{"class":462,"line":568},[460,1012,998],{"class":560},[460,1014,365],{"class":564},[460,1016,1017],{"class":556},"list_products",[460,1019,1006],{"class":560},[460,1021,582],{"class":564},[460,1023,1024,1026,1028,1031,1033,1035,1038,1040,1042,1045,1047,1049,1051],{"class":462,"line":585},[460,1025,998],{"class":560},[460,1027,365],{"class":564},[460,1029,1030],{"class":556},"list_orders",[460,1032,561],{"class":560},[460,1034,765],{"class":564},[460,1036,1037],{"class":571}," status",[460,1039,575],{"class":564},[460,1041,773],{"class":564},[460,1043,1044],{"class":469},"pending",[460,1046,779],{"class":564},[460,1048,782],{"class":564},[460,1050,785],{"class":560},[460,1052,582],{"class":564},[460,1054,1055,1058],{"class":462,"line":645},[460,1056,1057],{"class":560},"])",[460,1059,788],{"class":564},[460,1061,1062],{"class":462,"line":669},[460,1063,835],{"emptyLinePlaceholder":834},[460,1065,1066,1068],{"class":462,"line":895},[460,1067,936],{"class":549},[460,1069,1070],{"class":564}," {\n",[460,1072,1073,1076,1078,1081,1083,1086],{"class":462,"line":912},[460,1074,1075],{"class":571},"  userCount",[460,1077,575],{"class":564},[460,1079,1080],{"class":560}," users",[460,1082,365],{"class":564},[460,1084,1085],{"class":560},"length",[460,1087,582],{"class":564},[460,1089,1090,1093,1095,1097,1099,1101],{"class":462,"line":922},[460,1091,1092],{"class":571},"  productCount",[460,1094,575],{"class":564},[460,1096,969],{"class":560},[460,1098,365],{"class":564},[460,1100,1085],{"class":560},[460,1102,582],{"class":564},[460,1104,1105,1108,1110,1112,1114,1116],{"class":462,"line":928},[460,1106,1107],{"class":571},"  pendingOrders",[460,1109,575],{"class":564},[460,1111,974],{"class":560},[460,1113,365],{"class":564},[460,1115,1085],{"class":560},[460,1117,582],{"class":564},[460,1119,1120],{"class":462,"line":933},[460,1121,948],{"class":564},[450,1123,1126],{"className":732,"code":1124,"filename":1125,"language":735,"meta":456,"style":456},"const users = await codemode.list_users();\nconst results = [];\n\nfor (const user of users) {\n  const todos = await codemode.list_todos({ userId: user.id });\n  if (todos.some(t => t.overdue)) {\n    await codemode.send_reminder({ userId: user.id });\n    results.push(user.name);\n  }\n}\n\nreturn { reminded: results };\n","Loop + conditional",[154,1127,1128,1149,1163,1167,1186,1224,1261,1293,1317,1322,1326,1330],{"__ignoreMap":456},[460,1129,1130,1132,1135,1137,1139,1141,1143,1145,1147],{"class":462,"line":463},[460,1131,743],{"class":742},[460,1133,1134],{"class":560}," users ",[460,1136,749],{"class":564},[460,1138,752],{"class":549},[460,1140,755],{"class":560},[460,1142,365],{"class":564},[460,1144,1003],{"class":556},[460,1146,1006],{"class":560},[460,1148,788],{"class":564},[460,1150,1151,1153,1156,1158,1161],{"class":462,"line":546},[460,1152,743],{"class":742},[460,1154,1155],{"class":560}," results ",[460,1157,749],{"class":564},[460,1159,1160],{"class":560}," []",[460,1162,788],{"class":564},[460,1164,1165],{"class":462,"line":568},[460,1166,835],{"emptyLinePlaceholder":834},[460,1168,1169,1171,1174,1176,1178,1181,1184],{"class":462,"line":585},[460,1170,416],{"class":549},[460,1172,1173],{"class":560}," (",[460,1175,743],{"class":742},[460,1177,746],{"class":560},[460,1179,1180],{"class":564},"of",[460,1182,1183],{"class":560}," users) ",[460,1185,565],{"class":564},[460,1187,1188,1191,1194,1196,1198,1200,1202,1204,1206,1208,1210,1212,1214,1216,1218,1220,1222],{"class":462,"line":645},[460,1189,1190],{"class":742},"  const",[460,1192,1193],{"class":560}," todos",[460,1195,980],{"class":564},[460,1197,752],{"class":549},[460,1199,755],{"class":560},[460,1201,365],{"class":564},[460,1203,806],{"class":556},[460,1205,561],{"class":571},[460,1207,765],{"class":564},[460,1209,813],{"class":571},[460,1211,575],{"class":564},[460,1213,818],{"class":560},[460,1215,365],{"class":564},[460,1217,907],{"class":560},[460,1219,782],{"class":564},[460,1221,785],{"class":571},[460,1223,788],{"class":564},[460,1225,1226,1229,1231,1234,1236,1239,1241,1245,1248,1251,1253,1256,1259],{"class":462,"line":669},[460,1227,1228],{"class":549},"  if",[460,1230,1173],{"class":571},[460,1232,1233],{"class":560},"todos",[460,1235,365],{"class":564},[460,1237,1238],{"class":556},"some",[460,1240,561],{"class":571},[460,1242,1244],{"class":1243},"sHdIc","t",[460,1246,1247],{"class":742}," =>",[460,1249,1250],{"class":560}," t",[460,1252,365],{"class":564},[460,1254,1255],{"class":560},"overdue",[460,1257,1258],{"class":571},")) ",[460,1260,565],{"class":564},[460,1262,1263,1266,1268,1270,1273,1275,1277,1279,1281,1283,1285,1287,1289,1291],{"class":462,"line":895},[460,1264,1265],{"class":549},"    await",[460,1267,755],{"class":560},[460,1269,365],{"class":564},[460,1271,1272],{"class":556},"send_reminder",[460,1274,561],{"class":571},[460,1276,765],{"class":564},[460,1278,813],{"class":571},[460,1280,575],{"class":564},[460,1282,818],{"class":560},[460,1284,365],{"class":564},[460,1286,907],{"class":560},[460,1288,782],{"class":564},[460,1290,785],{"class":571},[460,1292,788],{"class":564},[460,1294,1295,1298,1300,1303,1305,1308,1310,1313,1315],{"class":462,"line":912},[460,1296,1297],{"class":560},"    results",[460,1299,365],{"class":564},[460,1301,1302],{"class":556},"push",[460,1304,561],{"class":571},[460,1306,1307],{"class":560},"user",[460,1309,365],{"class":564},[460,1311,1312],{"class":560},"name",[460,1314,785],{"class":571},[460,1316,788],{"class":564},[460,1318,1319],{"class":462,"line":922},[460,1320,1321],{"class":564},"  }\n",[460,1323,1324],{"class":462,"line":928},[460,1325,925],{"class":564},[460,1327,1328],{"class":462,"line":933},[460,1329,835],{"emptyLinePlaceholder":834},[460,1331,1333,1335,1337,1340,1342,1344],{"class":462,"line":1332},12,[460,1334,936],{"class":549},[460,1336,939],{"class":564},[460,1338,1339],{"class":571}," reminded",[460,1341,575],{"class":564},[460,1343,1155],{"class":560},[460,1345,948],{"class":564},[145,1347,1349],{"id":1348},"configuration-options","Configuration Options",[150,1351,1352,1353,1356],{},"Pass an options object instead of ",[154,1354,1355],{},"true"," for fine-grained control:",[450,1358,1361],{"className":532,"code":1359,"filename":1360,"language":535,"meta":456,"style":456},"export default defineMcpHandler({\n  experimental_codeMode: {\n    memoryLimit: 64,\n    cpuTimeLimitMs: 10_000,\n    maxResultSize: 102_400,\n    progressive: false,\n    description: undefined,\n  },\n})\n","server\u002Fmcp\u002Findex.ts",[154,1362,1363,1375,1383,1395,1407,1419,1431,1441,1446],{"__ignoreMap":456},[460,1364,1365,1367,1369,1371,1373],{"class":462,"line":463},[460,1366,550],{"class":549},[460,1368,553],{"class":549},[460,1370,557],{"class":556},[460,1372,561],{"class":560},[460,1374,565],{"class":564},[460,1376,1377,1379,1381],{"class":462,"line":546},[460,1378,572],{"class":571},[460,1380,575],{"class":564},[460,1382,1070],{"class":564},[460,1384,1385,1388,1390,1393],{"class":462,"line":568},[460,1386,1387],{"class":571},"    memoryLimit",[460,1389,575],{"class":564},[460,1391,1392],{"class":854}," 64",[460,1394,582],{"class":564},[460,1396,1397,1400,1402,1405],{"class":462,"line":585},[460,1398,1399],{"class":571},"    cpuTimeLimitMs",[460,1401,575],{"class":564},[460,1403,1404],{"class":854}," 10_000",[460,1406,582],{"class":564},[460,1408,1409,1412,1414,1417],{"class":462,"line":645},[460,1410,1411],{"class":571},"    maxResultSize",[460,1413,575],{"class":564},[460,1415,1416],{"class":854}," 102_400",[460,1418,582],{"class":564},[460,1420,1421,1424,1426,1429],{"class":462,"line":669},[460,1422,1423],{"class":571},"    progressive",[460,1425,575],{"class":564},[460,1427,1428],{"class":578}," false",[460,1430,582],{"class":564},[460,1432,1433,1436,1438],{"class":462,"line":895},[460,1434,1435],{"class":571},"    description",[460,1437,575],{"class":564},[460,1439,1440],{"class":564}," undefined,\n",[460,1442,1443],{"class":462,"line":912},[460,1444,1445],{"class":564},"  },\n",[460,1447,1448,1450],{"class":462,"line":922},[460,1449,588],{"class":564},[460,1451,591],{"class":560},[1453,1454,1455,1473,1484,1496,1513],"field-group",{},[1456,1457,1460,1466],"field",{"name":1458,"type":1459},"memoryLimit","number",[150,1461,1462,1463],{},"Default: ",[154,1464,1465],{},"64",[150,1467,1468,1469,1472],{},"V8 isolate memory limit in MB. Set once at first execution — call ",[154,1470,1471],{},"disposeCodeMode()"," to change.",[1456,1474,1476,1481],{"name":1475,"type":1459},"cpuTimeLimitMs",[150,1477,1462,1478],{},[154,1479,1480],{},"10000",[150,1482,1483],{},"CPU time limit per execution in milliseconds. The sandbox is killed after this duration.",[1456,1485,1487,1493],{"name":1486,"type":1459},"maxResultSize",[150,1488,1462,1489,1492],{},[154,1490,1491],{},"102400"," (100 KB)",[150,1494,1495],{},"Maximum result size in bytes before truncation. Large results are intelligently truncated — arrays by number of items, objects by number of keys.",[1456,1497,1500,1505],{"name":1498,"type":1499},"progressive","boolean",[150,1501,1462,1502],{},[154,1503,1504],{},"false",[150,1506,1507,1508,1512],{},"Enable progressive disclosure mode. See ",[439,1509,1511],{"href":1510},"#progressive-mode","Progressive Mode"," below.",[1456,1514,1517,1520],{"name":1515,"type":1516},"description","string",[150,1518,1519],{},"Default: built-in template",[150,1521,1522,1523,1525,1526,1529,1530,1533],{},"Custom description for the ",[154,1524,154],{}," tool. Supports ",[154,1527,1528],{},"{{types}}"," and ",[154,1531,1532],{},"{{count}}"," placeholders.",[145,1535,1511],{"id":1536},"progressive-mode",[150,1538,1539,1540,1542],{},"When your server exposes many tools (50+), embedding all type definitions in the ",[154,1541,154],{}," tool description becomes expensive in tokens. Progressive mode solves this by splitting into two tools:",[688,1544,1545,1553],{},[390,1546,1547,1552],{},[183,1548,1549],{},[154,1550,1551],{},"search"," — discovers tools by keyword, returns their signatures",[390,1554,1555,1559],{},[183,1556,1557],{},[154,1558,154],{}," — executes code using discovered tools",[450,1561,1563],{"className":532,"code":1562,"filename":1360,"language":535,"meta":456,"style":456},"export default defineMcpHandler({\n  experimental_codeMode: {\n    progressive: true,\n  },\n})\n",[154,1564,1565,1577,1585,1595,1599],{"__ignoreMap":456},[460,1566,1567,1569,1571,1573,1575],{"class":462,"line":463},[460,1568,550],{"class":549},[460,1570,553],{"class":549},[460,1572,557],{"class":556},[460,1574,561],{"class":560},[460,1576,565],{"class":564},[460,1578,1579,1581,1583],{"class":462,"line":546},[460,1580,572],{"class":571},[460,1582,575],{"class":564},[460,1584,1070],{"class":564},[460,1586,1587,1589,1591,1593],{"class":462,"line":568},[460,1588,1423],{"class":571},[460,1590,575],{"class":564},[460,1592,579],{"class":578},[460,1594,582],{"class":564},[460,1596,1597],{"class":462,"line":585},[460,1598,1445],{"class":564},[460,1600,1601,1603],{"class":462,"line":645},[460,1602,588],{"class":564},[460,1604,591],{"class":560},[150,1606,1607],{},"The LLM workflow becomes:",[447,1609,1610,1642],{},[450,1611,1616],{"className":1612,"code":1613,"filename":1614,"language":1615,"meta":456,"style":456},"language-txt shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","LLM calls: search({ query: \"user\" })\n\n→ Found 2\u002F12 tools matching \"user\":\n  codemode.get_user: (input: { id: string }) => Promise\u003Cunknown>; \u002F\u002F Get user by ID\n  codemode.list_users: () => Promise\u003Cunknown>; \u002F\u002F List all users\n","Step 1 — Search","txt",[154,1617,1618,1623,1627,1632,1637],{"__ignoreMap":456},[460,1619,1620],{"class":462,"line":463},[460,1621,1622],{},"LLM calls: search({ query: \"user\" })\n",[460,1624,1625],{"class":462,"line":546},[460,1626,835],{"emptyLinePlaceholder":834},[460,1628,1629],{"class":462,"line":568},[460,1630,1631],{},"→ Found 2\u002F12 tools matching \"user\":\n",[460,1633,1634],{"class":462,"line":585},[460,1635,1636],{},"  codemode.get_user: (input: { id: string }) => Promise\u003Cunknown>; \u002F\u002F Get user by ID\n",[460,1638,1639],{"class":462,"line":645},[460,1640,1641],{},"  codemode.list_users: () => Promise\u003Cunknown>; \u002F\u002F List all users\n",[450,1643,1646],{"className":1612,"code":1644,"filename":1645,"language":1615,"meta":456,"style":456},"LLM calls: code({ code: \"...\" })\n\n→ Executes code using the discovered tools\n","Step 2 — Execute",[154,1647,1648,1653,1657],{"__ignoreMap":456},[460,1649,1650],{"class":462,"line":463},[460,1651,1652],{},"LLM calls: code({ code: \"...\" })\n",[460,1654,1655],{"class":462,"line":546},[460,1656,835],{"emptyLinePlaceholder":834},[460,1658,1659],{"class":462,"line":568},[460,1660,1661],{},"→ Executes code using the discovered tools\n",[232,1663,1666],{"color":1664,"icon":1665},"info","i-lucide-info","Progressive mode adds an extra tool call but significantly reduces the initial prompt size. Only use it when you have a large number of tools — for small toolsets, standard mode is more efficient.",[145,1668,1670],{"id":1669},"custom-description","Custom Description",[150,1672,1673,1674,1676],{},"Override the ",[154,1675,154],{}," tool description to customize LLM instructions:",[450,1678,1680],{"className":532,"code":1679,"filename":1360,"language":535,"meta":456,"style":456},"export default defineMcpHandler({\n  experimental_codeMode: {\n    description: `You have {{count}} tools available. Write JavaScript using the codemode object.\n\n{{types}}\n\nAlways combine related operations into a single code block.`,\n  },\n})\n",[154,1681,1682,1694,1702,1714,1718,1723,1727,1737,1741],{"__ignoreMap":456},[460,1683,1684,1686,1688,1690,1692],{"class":462,"line":463},[460,1685,550],{"class":549},[460,1687,553],{"class":549},[460,1689,557],{"class":556},[460,1691,561],{"class":560},[460,1693,565],{"class":564},[460,1695,1696,1698,1700],{"class":462,"line":546},[460,1697,572],{"class":571},[460,1699,575],{"class":564},[460,1701,1070],{"class":564},[460,1703,1704,1706,1708,1711],{"class":462,"line":568},[460,1705,1435],{"class":571},[460,1707,575],{"class":564},[460,1709,1710],{"class":564}," `",[460,1712,1713],{"class":469},"You have {{count}} tools available. Write JavaScript using the codemode object.\n",[460,1715,1716],{"class":462,"line":585},[460,1717,835],{"emptyLinePlaceholder":834},[460,1719,1720],{"class":462,"line":645},[460,1721,1722],{"class":469},"{{types}}\n",[460,1724,1725],{"class":462,"line":669},[460,1726,835],{"emptyLinePlaceholder":834},[460,1728,1729,1732,1735],{"class":462,"line":895},[460,1730,1731],{"class":469},"Always combine related operations into a single code block.",[460,1733,1734],{"class":564},"`",[460,1736,582],{"class":564},[460,1738,1739],{"class":462,"line":912},[460,1740,1445],{"class":564},[460,1742,1743,1745],{"class":462,"line":922},[460,1744,588],{"class":564},[460,1746,591],{"class":560},[150,1748,1749,1750,1752,1753,1755],{},"The ",[154,1751,1528],{}," placeholder is replaced with the generated TypeScript definitions. The ",[154,1754,1532],{}," placeholder is replaced with the number of available tools.",[150,1757,1758,1759,1761,1762,1764],{},"In progressive mode, ",[154,1760,1528],{}," is not available since types are discovered via the ",[154,1763,1551],{}," tool.",[145,1766,1768],{"id":1767},"security","Security",[150,1770,1771,1772,1775],{},"Running LLM-generated code requires serious security measures. Code Mode implements ",[183,1773,1774],{},"defense in depth"," across 7 layers to ensure the sandbox cannot escape, access unauthorized resources, or exhaust host resources.",[252,1777,1779],{"id":1778},"sandbox-isolation","Sandbox Isolation",[150,1781,1782,1783,1788,1789,1791],{},"LLM-generated code runs in a separate ",[439,1784,1787],{"href":1785,"rel":1786},"https:\u002F\u002Fv8.dev\u002Fdocs\u002Fembed",[443],"V8 isolate"," via ",[154,1790,444],{},". This is the same isolation technology used by Cloudflare Workers and similar platforms. The sandbox has:",[387,1793,1794,1800,1822,1828],{},[390,1795,1796,1799],{},[183,1797,1798],{},"No filesystem access"," — cannot read, write, or list files",[390,1801,1802,1805,1806,719,1809,719,1812,719,1815,719,1818,1821],{},[183,1803,1804],{},"No Node.js APIs"," — no ",[154,1807,1808],{},"require()",[154,1810,1811],{},"import()",[154,1813,1814],{},"process",[154,1816,1817],{},"fs",[154,1819,1820],{},"child_process",", etc.",[390,1823,1824,1827],{},[183,1825,1826],{},"No environment variables"," — cannot read secrets or configuration",[390,1829,1830,1833],{},[183,1831,1832],{},"No host process access"," — cannot modify the parent process in any way",[252,1835,1837],{"id":1836},"network-restrictions","Network Restrictions",[150,1839,1840],{},"The sandbox can only communicate with the internal RPC server. All other network access is blocked:",[387,1842,1843,1849,1862,1868],{},[390,1844,1845,1848],{},[183,1846,1847],{},"Port-locked"," — Only the randomly-assigned RPC port is accessible. Other localhost services (databases, admin panels, other apps) are blocked.",[390,1850,1851,1854,1855,1529,1858,1861],{},[183,1852,1853],{},"Host-locked"," — Only ",[154,1856,1857],{},"127.0.0.1",[154,1859,1860],{},"localhost"," are allowed. External hosts are rejected.",[390,1863,1864,1867],{},[183,1865,1866],{},"No DNS"," — DNS resolution is disabled entirely.",[390,1869,1870,1873,1874,1877],{},[183,1871,1872],{},"No redirects"," — HTTP redirects are rejected (",[154,1875,1876],{},"redirect: 'error'","), preventing SSRF via open redirects.",[252,1879,1881],{"id":1880},"rpc-authentication","RPC Authentication",[150,1883,1884],{},"Communication between the sandbox and the host uses a per-session cryptographic token:",[387,1886,1887,1897,1907],{},[390,1888,1889,1892,1893,1896],{},[183,1890,1891],{},"256-bit token"," — Generated with ",[154,1894,1895],{},"crypto.randomBytes(32)"," at RPC server startup.",[390,1898,1899,1902,1903,1906],{},[183,1900,1901],{},"Header-based auth"," — Every request must include the token via ",[154,1904,1905],{},"x-rpc-token"," header.",[390,1908,1909,1912],{},[183,1910,1911],{},"403 on mismatch"," — Requests without a valid token are rejected immediately.",[150,1914,1915],{},"This prevents other local processes from calling your MCP tools through the RPC port.",[252,1917,1919],{"id":1918},"resource-limits","Resource Limits",[158,1921,1922,1938],{},[161,1923,1924],{},[164,1925,1926,1929,1932,1935],{},[167,1927,1928],{},"Resource",[167,1930,1931],{},"Default",[167,1933,1934],{},"Configurable",[167,1936,1937],{},"Protection",[175,1939,1940,1957,1974,1991],{},[164,1941,1942,1947,1950,1954],{},[180,1943,1944],{},[183,1945,1946],{},"CPU time",[180,1948,1949],{},"10 seconds",[180,1951,1952],{},[154,1953,1475],{},[180,1955,1956],{},"Sandbox is killed on timeout — prevents infinite loops",[164,1958,1959,1964,1967,1971],{},[180,1960,1961],{},[183,1962,1963],{},"Memory",[180,1965,1966],{},"64 MB",[180,1968,1969],{},[154,1970,1458],{},[180,1972,1973],{},"V8 isolate hard limit — prevents OOM crashes",[164,1975,1976,1981,1984,1988],{},[180,1977,1978],{},[183,1979,1980],{},"Result size",[180,1982,1983],{},"100 KB",[180,1985,1986],{},[154,1987,1486],{},[180,1989,1990],{},"Intelligent truncation (arrays by items, objects by keys)",[164,1992,1993,1998,2001,2004],{},[180,1994,1995],{},[183,1996,1997],{},"Log entries",[180,1999,2000],{},"200",[180,2002,2003],{},"No",[180,2005,2006,2007,2010],{},"Console output capped — prevents ",[154,2008,2009],{},"console.log"," flooding",[252,2012,2014],{"id":2013},"input-validation","Input Validation",[150,2016,2017],{},"Tool names are interpolated into the sandbox code template. To prevent code injection:",[387,2019,2020,2030,2042],{},[390,2021,2022,2025,2026,2029],{},[183,2023,2024],{},"Strict identifier regex"," — Every tool name is validated against ",[154,2027,2028],{},"\u002F^[\\w$]+$\u002F"," before being injected into the sandbox template.",[390,2031,2032,2035,2036,2038,2039,2041],{},[183,2033,2034],{},"Sanitization"," — Names are sanitized upstream (",[154,2037,718],{}," → ",[154,2040,760],{},"), but a second validation layer at the template level ensures defense in depth.",[390,2043,2044,2047],{},[183,2045,2046],{},"Rejection"," — If a name fails validation, the execution throws immediately — no partial injection.",[252,2049,2051],{"id":2050},"summary","Summary",[232,2053,2054,2055,2058],{"color":1664,"icon":79},"The sandbox can ",[183,2056,2057],{},"only"," communicate with your registered MCP tools via the authenticated RPC bridge. It cannot access the filesystem, network, environment, or any other host resources.",[145,2060,2062],{"id":2061},"usage-with-other-features","Usage with Other Features",[150,2064,2065],{},"Code Mode is fully compatible with other module features. Your tools remain unchanged — only the way they are exposed to the LLM changes.",[447,2067,2068,2215,2376],{},[450,2069,2072],{"className":532,"code":2070,"filename":2071,"language":535,"meta":456,"style":456},"\u002F\u002F server\u002Fmcp\u002Findex.ts\nexport default defineMcpHandler({\n  experimental_codeMode: true,\n  middleware: async (event) => {\n    const user = await getUser(event)\n    if (!user) {\n      throw createError({ statusCode: 401 })\n    }\n    event.context.user = user\n  },\n})\n","With Middleware",[154,2073,2074,2078,2090,2100,2121,2141,2157,2181,2186,2205,2209],{"__ignoreMap":456},[460,2075,2076],{"class":462,"line":463},[460,2077,543],{"class":542},[460,2079,2080,2082,2084,2086,2088],{"class":462,"line":546},[460,2081,550],{"class":549},[460,2083,553],{"class":549},[460,2085,557],{"class":556},[460,2087,561],{"class":560},[460,2089,565],{"class":564},[460,2091,2092,2094,2096,2098],{"class":462,"line":568},[460,2093,572],{"class":571},[460,2095,575],{"class":564},[460,2097,579],{"class":578},[460,2099,582],{"class":564},[460,2101,2102,2105,2107,2110,2112,2115,2117,2119],{"class":462,"line":585},[460,2103,2104],{"class":556},"  middleware",[460,2106,575],{"class":564},[460,2108,2109],{"class":742}," async",[460,2111,1173],{"class":564},[460,2113,2114],{"class":1243},"event",[460,2116,785],{"class":564},[460,2118,1247],{"class":742},[460,2120,1070],{"class":564},[460,2122,2123,2126,2128,2130,2132,2135,2137,2139],{"class":462,"line":645},[460,2124,2125],{"class":742},"    const",[460,2127,818],{"class":560},[460,2129,980],{"class":564},[460,2131,752],{"class":549},[460,2133,2134],{"class":556}," getUser",[460,2136,561],{"class":571},[460,2138,2114],{"class":560},[460,2140,591],{"class":571},[460,2142,2143,2146,2148,2151,2153,2155],{"class":462,"line":669},[460,2144,2145],{"class":549},"    if",[460,2147,1173],{"class":571},[460,2149,2150],{"class":564},"!",[460,2152,1307],{"class":560},[460,2154,858],{"class":571},[460,2156,565],{"class":564},[460,2158,2159,2162,2165,2167,2169,2172,2174,2177,2179],{"class":462,"line":895},[460,2160,2161],{"class":549},"      throw",[460,2163,2164],{"class":556}," createError",[460,2166,561],{"class":571},[460,2168,765],{"class":564},[460,2170,2171],{"class":571}," statusCode",[460,2173,575],{"class":564},[460,2175,2176],{"class":854}," 401",[460,2178,782],{"class":564},[460,2180,591],{"class":571},[460,2182,2183],{"class":462,"line":912},[460,2184,2185],{"class":564},"    }\n",[460,2187,2188,2191,2193,2196,2198,2200,2202],{"class":462,"line":922},[460,2189,2190],{"class":560},"    event",[460,2192,365],{"class":564},[460,2194,2195],{"class":560},"context",[460,2197,365],{"class":564},[460,2199,1307],{"class":560},[460,2201,980],{"class":564},[460,2203,2204],{"class":560}," user\n",[460,2206,2207],{"class":462,"line":928},[460,2208,1445],{"class":564},[460,2210,2211,2213],{"class":462,"line":933},[460,2212,588],{"class":564},[460,2214,591],{"class":560},[450,2216,2219],{"className":532,"code":2217,"filename":2218,"language":535,"meta":456,"style":456},"\u002F\u002F server\u002Fmcp\u002Ftools\u002Fadmin-tool.ts\nexport default defineMcpTool({\n  name: 'admin-delete',\n  description: 'Delete a resource (admin only)',\n  enabled: event => event.context.user?.role === 'admin',\n  inputSchema: {\n    id: z.string(),\n  },\n  handler: async ({ id }) => {\n    \u002F\u002F Only visible in code mode when user is admin\n  },\n})\n","With Dynamic Definitions",[154,2220,2221,2226,2239,2254,2270,2309,2318,2336,2340,2361,2366,2370],{"__ignoreMap":456},[460,2222,2223],{"class":462,"line":463},[460,2224,2225],{"class":542},"\u002F\u002F server\u002Fmcp\u002Ftools\u002Fadmin-tool.ts\n",[460,2227,2228,2230,2232,2235,2237],{"class":462,"line":546},[460,2229,550],{"class":549},[460,2231,553],{"class":549},[460,2233,2234],{"class":556}," defineMcpTool",[460,2236,561],{"class":560},[460,2238,565],{"class":564},[460,2240,2241,2243,2245,2247,2250,2252],{"class":462,"line":568},[460,2242,619],{"class":571},[460,2244,575],{"class":564},[460,2246,624],{"class":564},[460,2248,2249],{"class":469},"admin-delete",[460,2251,630],{"class":564},[460,2253,582],{"class":564},[460,2255,2256,2259,2261,2263,2266,2268],{"class":462,"line":585},[460,2257,2258],{"class":571},"  description",[460,2260,575],{"class":564},[460,2262,624],{"class":564},[460,2264,2265],{"class":469},"Delete a resource (admin only)",[460,2267,630],{"class":564},[460,2269,582],{"class":564},[460,2271,2272,2275,2277,2280,2282,2284,2286,2288,2290,2292,2295,2298,2300,2302,2305,2307],{"class":462,"line":645},[460,2273,2274],{"class":556},"  enabled",[460,2276,575],{"class":564},[460,2278,2279],{"class":1243}," event",[460,2281,1247],{"class":742},[460,2283,2279],{"class":560},[460,2285,365],{"class":564},[460,2287,2195],{"class":560},[460,2289,365],{"class":564},[460,2291,1307],{"class":560},[460,2293,2294],{"class":564},"?.",[460,2296,2297],{"class":560},"role ",[460,2299,851],{"class":564},[460,2301,624],{"class":564},[460,2303,2304],{"class":469},"admin",[460,2306,630],{"class":564},[460,2308,582],{"class":564},[460,2310,2311,2314,2316],{"class":462,"line":669},[460,2312,2313],{"class":571},"  inputSchema",[460,2315,575],{"class":564},[460,2317,1070],{"class":564},[460,2319,2320,2323,2325,2328,2330,2332,2334],{"class":462,"line":895},[460,2321,2322],{"class":571},"    id",[460,2324,575],{"class":564},[460,2326,2327],{"class":560}," z",[460,2329,365],{"class":564},[460,2331,1516],{"class":556},[460,2333,1006],{"class":560},[460,2335,582],{"class":564},[460,2337,2338],{"class":462,"line":912},[460,2339,1445],{"class":564},[460,2341,2342,2345,2347,2349,2352,2354,2357,2359],{"class":462,"line":922},[460,2343,2344],{"class":556},"  handler",[460,2346,575],{"class":564},[460,2348,2109],{"class":742},[460,2350,2351],{"class":564}," ({",[460,2353,768],{"class":1243},[460,2355,2356],{"class":564}," })",[460,2358,1247],{"class":742},[460,2360,1070],{"class":564},[460,2362,2363],{"class":462,"line":928},[460,2364,2365],{"class":542},"    \u002F\u002F Only visible in code mode when user is admin\n",[460,2367,2368],{"class":462,"line":933},[460,2369,1445],{"class":564},[460,2371,2372,2374],{"class":462,"line":1332},[460,2373,588],{"class":564},[460,2375,591],{"class":560},[450,2377,2380],{"className":532,"code":2378,"filename":2379,"language":535,"meta":456,"style":456},"\u002F\u002F server\u002Fmcp\u002Findex.ts\nexport default defineMcpHandler({\n  experimental_codeMode: {\n    progressive: true,\n    cpuTimeLimitMs: 15_000,\n  },\n  middleware: async (event) => {\n    const apiKey = getHeader(event, 'x-api-key')\n    if (!apiKey) throw createError({ statusCode: 401 })\n    event.context.user = await getUserByApiKey(apiKey)\n  },\n})\n","With Progressive + Auth",[154,2381,2382,2386,2398,2406,2416,2427,2431,2449,2476,2508,2533,2537],{"__ignoreMap":456},[460,2383,2384],{"class":462,"line":463},[460,2385,543],{"class":542},[460,2387,2388,2390,2392,2394,2396],{"class":462,"line":546},[460,2389,550],{"class":549},[460,2391,553],{"class":549},[460,2393,557],{"class":556},[460,2395,561],{"class":560},[460,2397,565],{"class":564},[460,2399,2400,2402,2404],{"class":462,"line":568},[460,2401,572],{"class":571},[460,2403,575],{"class":564},[460,2405,1070],{"class":564},[460,2407,2408,2410,2412,2414],{"class":462,"line":585},[460,2409,1423],{"class":571},[460,2411,575],{"class":564},[460,2413,579],{"class":578},[460,2415,582],{"class":564},[460,2417,2418,2420,2422,2425],{"class":462,"line":645},[460,2419,1399],{"class":571},[460,2421,575],{"class":564},[460,2423,2424],{"class":854}," 15_000",[460,2426,582],{"class":564},[460,2428,2429],{"class":462,"line":669},[460,2430,1445],{"class":564},[460,2432,2433,2435,2437,2439,2441,2443,2445,2447],{"class":462,"line":895},[460,2434,2104],{"class":556},[460,2436,575],{"class":564},[460,2438,2109],{"class":742},[460,2440,1173],{"class":564},[460,2442,2114],{"class":1243},[460,2444,785],{"class":564},[460,2446,1247],{"class":742},[460,2448,1070],{"class":564},[460,2450,2451,2453,2456,2458,2461,2463,2465,2467,2469,2472,2474],{"class":462,"line":912},[460,2452,2125],{"class":742},[460,2454,2455],{"class":560}," apiKey",[460,2457,980],{"class":564},[460,2459,2460],{"class":556}," getHeader",[460,2462,561],{"class":571},[460,2464,2114],{"class":560},[460,2466,656],{"class":564},[460,2468,624],{"class":564},[460,2470,2471],{"class":469},"x-api-key",[460,2473,630],{"class":564},[460,2475,591],{"class":571},[460,2477,2478,2480,2482,2484,2487,2489,2492,2494,2496,2498,2500,2502,2504,2506],{"class":462,"line":922},[460,2479,2145],{"class":549},[460,2481,1173],{"class":571},[460,2483,2150],{"class":564},[460,2485,2486],{"class":560},"apiKey",[460,2488,858],{"class":571},[460,2490,2491],{"class":549},"throw",[460,2493,2164],{"class":556},[460,2495,561],{"class":571},[460,2497,765],{"class":564},[460,2499,2171],{"class":571},[460,2501,575],{"class":564},[460,2503,2176],{"class":854},[460,2505,782],{"class":564},[460,2507,591],{"class":571},[460,2509,2510,2512,2514,2516,2518,2520,2522,2524,2527,2529,2531],{"class":462,"line":928},[460,2511,2190],{"class":560},[460,2513,365],{"class":564},[460,2515,2195],{"class":560},[460,2517,365],{"class":564},[460,2519,1307],{"class":560},[460,2521,980],{"class":564},[460,2523,752],{"class":549},[460,2525,2526],{"class":556}," getUserByApiKey",[460,2528,561],{"class":571},[460,2530,2486],{"class":560},[460,2532,591],{"class":571},[460,2534,2535],{"class":462,"line":933},[460,2536,1445],{"class":564},[460,2538,2539,2541],{"class":462,"line":1332},[460,2540,588],{"class":564},[460,2542,591],{"class":560},[150,2544,2545,2547,2548,2551,2552,2558,2559,2561],{},[439,2546,76],{"href":77}," runs before tool execution — your tools access ",[154,2549,2550],{},"event.context"," as usual. Tools with ",[439,2553,2554,2557],{"href":102},[154,2555,2556],{},"enabled"," guards"," are excluded from the generated type definitions and the ",[154,2560,704],{}," object.",[145,2563,2565],{"id":2564},"tool-name-sanitization","Tool Name Sanitization",[150,2567,2568,2569,2571],{},"MCP tool names (kebab-case) are automatically converted to valid JavaScript identifiers for the ",[154,2570,704],{}," object:",[158,2573,2574,2584],{},[161,2575,2576],{},[164,2577,2578,2581],{},[167,2579,2580],{},"MCP Name",[167,2582,2583],{},"JavaScript Name",[175,2585,2586,2596,2606,2618],{},[164,2587,2588,2592],{},[180,2589,2590],{},[154,2591,718],{},[180,2593,2594],{},[154,2595,760],{},[164,2597,2598,2602],{},[180,2599,2600],{},[154,2601,722],{},[180,2603,2604],{},[154,2605,806],{},[164,2607,2608,2613],{},[180,2609,2610],{},[154,2611,2612],{},"123-tool",[180,2614,2615],{},[154,2616,2617],{},"_123_tool",[164,2619,2620,2625],{},[180,2621,2622],{},[154,2623,2624],{},"delete",[180,2626,2627],{},[154,2628,2629],{},"delete_",[150,2631,2632,2633,2636,2637,365],{},"Reserved JavaScript words are suffixed with ",[154,2634,2635],{},"_",". Names starting with a digit are prefixed with ",[154,2638,2635],{},[145,2640,2642],{"id":2641},"cleanup","Cleanup",[150,2644,2645,2646,2648],{},"Call ",[154,2647,1471],{}," during shutdown to release resources (V8 runtime, RPC server):",[450,2650,2652],{"className":532,"code":2651,"language":535,"meta":456,"style":456},"import { disposeCodeMode } from '#imports'\n\n\u002F\u002F In a shutdown hook or cleanup function\ndisposeCodeMode()\n",[154,2653,2654,2677,2681,2686],{"__ignoreMap":456},[460,2655,2656,2659,2661,2664,2666,2669,2671,2674],{"class":462,"line":463},[460,2657,2658],{"class":549},"import",[460,2660,939],{"class":564},[460,2662,2663],{"class":560}," disposeCodeMode",[460,2665,782],{"class":564},[460,2667,2668],{"class":549}," from",[460,2670,624],{"class":564},[460,2672,2673],{"class":469},"#imports",[460,2675,2676],{"class":564},"'\n",[460,2678,2679],{"class":462,"line":546},[460,2680,835],{"emptyLinePlaceholder":834},[460,2682,2683],{"class":462,"line":568},[460,2684,2685],{"class":542},"\u002F\u002F In a shutdown hook or cleanup function\n",[460,2687,2688,2691],{"class":462,"line":585},[460,2689,2690],{"class":556},"disposeCodeMode",[460,2692,2693],{"class":560},"()\n",[145,2695,2697],{"id":2696},"next-steps","Next Steps",[387,2699,2700,2705,2710,2715],{},[390,2701,2702,2704],{},[439,2703,61],{"href":62}," - Create custom MCP endpoints",[390,2706,2707,2709],{},[439,2708,76],{"href":77}," - Add authentication",[390,2711,2712,2714],{},[439,2713,101],{"href":102}," - Conditionally register tools",[390,2716,2717,2720],{},[439,2718,2719],{"href":92},"Evals"," - Benchmark code mode vs standard MCP",[2722,2723,2724],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .s7zQu, html code.shiki .s7zQu{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#89DDFF;--shiki-dark-font-style:italic}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sHdIc, html code.shiki .sHdIc{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#BABED8;--shiki-dark-font-style:italic}",{"title":456,"searchDepth":546,"depth":546,"links":2726},[2727,2728,2732,2736,2739,2740,2741,2742,2750,2751,2752,2753],{"id":147,"depth":546,"text":148},{"id":242,"depth":546,"text":243,"children":2729},[2730,2731],{"id":254,"depth":568,"text":255},{"id":381,"depth":568,"text":382},{"id":429,"depth":546,"text":430,"children":2733},[2734,2735],{"id":433,"depth":568,"text":434},{"id":519,"depth":568,"text":520},{"id":682,"depth":546,"text":683,"children":2737},[2738],{"id":711,"depth":568,"text":712},{"id":1348,"depth":546,"text":1349},{"id":1536,"depth":546,"text":1511},{"id":1669,"depth":546,"text":1670},{"id":1767,"depth":546,"text":1768,"children":2743},[2744,2745,2746,2747,2748,2749],{"id":1778,"depth":568,"text":1779},{"id":1836,"depth":568,"text":1837},{"id":1880,"depth":568,"text":1881},{"id":1918,"depth":568,"text":1919},{"id":2013,"depth":568,"text":2014},{"id":2050,"depth":568,"text":2051},{"id":2061,"depth":546,"text":2062},{"id":2564,"depth":546,"text":2565},{"id":2641,"depth":546,"text":2642},{"id":2696,"depth":546,"text":2697},"Let LLMs orchestrate multiple tool calls in a single JavaScript execution.","md",null,{},{"icon":109},{"title":106,"description":2760},"Reduce token usage and latency by letting LLMs write JavaScript that orchestrates MCP tools in a secure V8 sandbox.","Sh812_Ye2LXLa_fz8GS2YuiuAhF2lXZORVENc5vYUmg",[2763,2765],{"title":101,"path":102,"stem":103,"description":2764,"icon":104,"children":-1},"Conditionally register tools, resources, and prompts based on authentication, roles, or request context.",{"title":116,"path":117,"stem":118,"description":2766,"icon":119,"children":-1},"Secure your MCP endpoints with Bearer token authentication.",1773935596466]