pi-namespace-patch 1.0.0-namespace.2 → 1.0.2-namespace.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +22 -4
  3. package/dist/bundle/chunks/{anthropic-messages-UID2PALB.js → anthropic-messages-MVG2FL56.js} +3 -3
  4. package/dist/bundle/chunks/azure-openai-responses-7AMFUIWJ.js +2 -0
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +2 -2
  6. package/dist/bundle/chunks/chunk-2KAZSACP.js +2 -0
  7. package/dist/bundle/chunks/{chunk-2KTBZM5G.js → chunk-6FX7UEPL.js} +5 -5
  8. package/dist/bundle/chunks/{chunk-2VNGUWBO.js → chunk-BYB6ZAAQ.js} +1 -1
  9. package/dist/bundle/chunks/chunk-DN3QEIXS.js +2 -0
  10. package/dist/bundle/chunks/chunk-F5ZABL6Z.js +20 -0
  11. package/dist/bundle/chunks/{chunk-3LH3ZQKY.js → chunk-G7EDXK4D.js} +1 -1
  12. package/dist/bundle/chunks/chunk-IKZJX7ZT.js +2 -0
  13. package/dist/bundle/chunks/{chunk-4N5K4RKC.js → chunk-OLBCNJCL.js} +31 -32
  14. package/dist/bundle/chunks/{chunk-PRD6WYBT.js → chunk-OYBSLV7Y.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-IBCPYVFK.js → chunk-PDFMCAOZ.js} +4 -4
  16. package/dist/bundle/chunks/{chunk-LTXEMVMA.js → chunk-SYF2TF6W.js} +2 -2
  17. package/dist/bundle/chunks/chunk-WCQZGZ6I.js +82 -0
  18. package/dist/bundle/chunks/{chunk-KDN6RCEQ.js → chunk-ZSI3BL5Q.js} +2 -2
  19. package/dist/bundle/chunks/{cli-QOMC26IJ.js → cli-KILDDGW3.js} +2 -2
  20. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-NPQN263E.js → cloudflare-workers-ai-system-one-X5PVWWYJ.js} +1 -1
  21. package/dist/bundle/chunks/codemode-worker.js +24 -3
  22. package/dist/bundle/chunks/easter-egg-3d-T5FFWIBR.js +2 -0
  23. package/dist/bundle/chunks/{execute-GVRSEGHL.js → execute-RYVK27GT.js} +25 -4
  24. package/dist/bundle/chunks/{google-generative-ai-APTPZOQL.js → google-generative-ai-ZOK6CV7D.js} +1 -1
  25. package/dist/bundle/chunks/{google-vertex-MXCOSOY3.js → google-vertex-VKWZQ3AY.js} +1 -1
  26. package/dist/bundle/chunks/{mistral-conversations-DKVFNQL6.js → mistral-conversations-7DAUEE4N.js} +1 -1
  27. package/dist/bundle/chunks/node-N5BSDOA5.js +16 -0
  28. package/dist/bundle/chunks/openai-chatgpt.js +1 -1
  29. package/dist/bundle/chunks/{openai-codex-responses-GK67DQQJ.js → openai-codex-responses-TC3OK7B4.js} +1 -1
  30. package/dist/bundle/chunks/openai-completions-GWHGMQ3T.js +7 -0
  31. package/dist/bundle/chunks/openai-responses-EZ7FJ2KL.js +3 -0
  32. package/dist/bundle/chunks/{runtime-2SO2JDWM.js → runtime-D5I2NTIF.js} +1 -1
  33. package/dist/bundle/chunks/virtual-modules-J2M3WAR2.js +2 -0
  34. package/dist/bundle/cli-runtime.js +1 -1
  35. package/dist/bundle/index.js +1 -1
  36. package/dist/bundle/rpc-entry.js +1 -1
  37. package/dist/cli/args.d.ts.map +1 -1
  38. package/dist/cli/args.js +4 -1
  39. package/dist/cli/args.js.map +1 -1
  40. package/dist/config.d.ts.map +1 -1
  41. package/dist/config.js +3 -0
  42. package/dist/config.js.map +1 -1
  43. package/dist/core/agent-session.d.ts.map +1 -1
  44. package/dist/core/agent-session.js +1 -1
  45. package/dist/core/agent-session.js.map +1 -1
  46. package/dist/core/export-html/tool-renderer.d.ts +3 -3
  47. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  48. package/dist/core/export-html/tool-renderer.js +3 -3
  49. package/dist/core/export-html/tool-renderer.js.map +1 -1
  50. package/dist/core/extensions/index.d.ts +1 -1
  51. package/dist/core/extensions/index.d.ts.map +1 -1
  52. package/dist/core/extensions/index.js.map +1 -1
  53. package/dist/core/extensions/loader.d.ts.map +1 -1
  54. package/dist/core/extensions/loader.js +5 -0
  55. package/dist/core/extensions/loader.js.map +1 -1
  56. package/dist/core/extensions/runner.d.ts +3 -1
  57. package/dist/core/extensions/runner.d.ts.map +1 -1
  58. package/dist/core/extensions/runner.js +6 -0
  59. package/dist/core/extensions/runner.js.map +1 -1
  60. package/dist/core/extensions/types.d.ts +9 -0
  61. package/dist/core/extensions/types.d.ts.map +1 -1
  62. package/dist/core/extensions/types.js.map +1 -1
  63. package/dist/core/mcp-servers.d.ts +6 -0
  64. package/dist/core/mcp-servers.d.ts.map +1 -1
  65. package/dist/core/mcp-servers.js +11 -0
  66. package/dist/core/mcp-servers.js.map +1 -1
  67. package/dist/core/model-config.d.ts +36 -0
  68. package/dist/core/model-config.d.ts.map +1 -1
  69. package/dist/core/model-config.js +14 -2
  70. package/dist/core/model-config.js.map +1 -1
  71. package/dist/core/model-resolver.js +1 -1
  72. package/dist/core/model-resolver.js.map +1 -1
  73. package/dist/core/provider-composer.d.ts +2 -1
  74. package/dist/core/provider-composer.d.ts.map +1 -1
  75. package/dist/core/provider-composer.js +13 -0
  76. package/dist/core/provider-composer.js.map +1 -1
  77. package/dist/core/tools/renderers/index.d.ts +2 -2
  78. package/dist/core/tools/renderers/index.d.ts.map +1 -1
  79. package/dist/core/tools/renderers/index.js.map +1 -1
  80. package/dist/extensions/mcp/cli.d.ts.map +1 -1
  81. package/dist/extensions/mcp/cli.js +3 -0
  82. package/dist/extensions/mcp/cli.js.map +1 -1
  83. package/dist/extensions/mcp/config.d.ts +15 -3
  84. package/dist/extensions/mcp/config.d.ts.map +1 -1
  85. package/dist/extensions/mcp/config.js +46 -10
  86. package/dist/extensions/mcp/config.js.map +1 -1
  87. package/dist/extensions/mcp/index.d.ts +4 -1
  88. package/dist/extensions/mcp/index.d.ts.map +1 -1
  89. package/dist/extensions/mcp/index.js +80 -45
  90. package/dist/extensions/mcp/index.js.map +1 -1
  91. package/dist/extensions/mcp/oauth.d.ts +4 -1
  92. package/dist/extensions/mcp/oauth.d.ts.map +1 -1
  93. package/dist/extensions/mcp/oauth.js +54 -10
  94. package/dist/extensions/mcp/oauth.js.map +1 -1
  95. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  96. package/dist/extensions/mcp/runtime.js +1 -0
  97. package/dist/extensions/mcp/runtime.js.map +1 -1
  98. package/dist/extensions/mcp/tools.d.ts +3 -1
  99. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  100. package/dist/extensions/mcp/tools.js +19 -13
  101. package/dist/extensions/mcp/tools.js.map +1 -1
  102. package/dist/extensions/mcp/ui.d.ts.map +1 -1
  103. package/dist/extensions/mcp/ui.js +8 -4
  104. package/dist/extensions/mcp/ui.js.map +1 -1
  105. package/dist/index.d.ts +1 -1
  106. package/dist/index.d.ts.map +1 -1
  107. package/dist/index.js.map +1 -1
  108. package/dist/modes/interactive/components/armin.d.ts +3 -0
  109. package/dist/modes/interactive/components/armin.d.ts.map +1 -1
  110. package/dist/modes/interactive/components/armin.js +7 -5
  111. package/dist/modes/interactive/components/armin.js.map +1 -1
  112. package/dist/modes/interactive/components/auth-url.d.ts +14 -0
  113. package/dist/modes/interactive/components/auth-url.d.ts.map +1 -0
  114. package/dist/modes/interactive/components/auth-url.js +37 -0
  115. package/dist/modes/interactive/components/auth-url.js.map +1 -0
  116. package/dist/modes/interactive/components/easter-egg-3d.d.ts +104 -0
  117. package/dist/modes/interactive/components/easter-egg-3d.d.ts.map +1 -0
  118. package/dist/modes/interactive/components/{pi-logo-animation.js → easter-egg-3d.js} +127 -74
  119. package/dist/modes/interactive/components/easter-egg-3d.js.map +1 -0
  120. package/dist/modes/interactive/components/easter-egg-3d.lazy.d.ts +6 -0
  121. package/dist/modes/interactive/components/easter-egg-3d.lazy.d.ts.map +1 -0
  122. package/dist/modes/interactive/components/easter-egg-3d.lazy.js +23 -0
  123. package/dist/modes/interactive/components/easter-egg-3d.lazy.js.map +1 -0
  124. package/dist/modes/interactive/components/index.d.ts +0 -1
  125. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  126. package/dist/modes/interactive/components/index.js +0 -1
  127. package/dist/modes/interactive/components/index.js.map +1 -1
  128. package/dist/modes/interactive/components/login-dialog.d.ts +2 -0
  129. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  130. package/dist/modes/interactive/components/login-dialog.js +11 -5
  131. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  132. package/dist/modes/interactive/components/tool-execution.d.ts +6 -18
  133. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  134. package/dist/modes/interactive/components/tool-execution.js +22 -45
  135. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  136. package/dist/modes/interactive/interactive-mode.d.ts +2 -2
  137. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  138. package/dist/modes/interactive/interactive-mode.js +15 -17
  139. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  140. package/dist/package-manager-cli.d.ts.map +1 -1
  141. package/dist/package-manager-cli.js +12 -0
  142. package/dist/package-manager-cli.js.map +1 -1
  143. package/dist/utils/image-convert.d.ts +12 -0
  144. package/dist/utils/image-convert.d.ts.map +1 -1
  145. package/dist/utils/image-convert.js +45 -6
  146. package/dist/utils/image-convert.js.map +1 -1
  147. package/docs/cli.md +2 -0
  148. package/docs/codemode.md +1 -1
  149. package/docs/extensions.md +4 -0
  150. package/docs/keybindings.md +1 -1
  151. package/docs/mcp.md +23 -1
  152. package/docs/models.md +28 -2
  153. package/docs/quickstart.md +16 -2
  154. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  155. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  156. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  157. package/examples/extensions/gondolin/package-lock.json +2 -2
  158. package/examples/extensions/gondolin/package.json +1 -1
  159. package/examples/extensions/sandbox/package-lock.json +2 -2
  160. package/examples/extensions/sandbox/package.json +1 -1
  161. package/examples/extensions/with-deps/package-lock.json +2 -2
  162. package/examples/extensions/with-deps/package.json +1 -1
  163. package/package.json +13 -14
  164. package/dist/bundle/chunks/azure-openai-responses-AFMVM6NP.js +0 -2
  165. package/dist/bundle/chunks/chunk-6D7LHLKG.js +0 -2
  166. package/dist/bundle/chunks/chunk-7FH3BDRG.js +0 -82
  167. package/dist/bundle/chunks/chunk-DTD7JQ7Y.js +0 -42
  168. package/dist/bundle/chunks/chunk-MJOHEBV7.js +0 -2
  169. package/dist/bundle/chunks/node-O3RIBJRH.js +0 -16
  170. package/dist/bundle/chunks/openai-completions-JXDDPZ23.js +0 -7
  171. package/dist/bundle/chunks/openai-responses-CQDDLDQF.js +0 -3
  172. package/dist/bundle/chunks/pi-logo-animation-MPKZE4EK.js +0 -2
  173. package/dist/bundle/chunks/virtual-modules-3THEGRQQ.js +0 -2
  174. package/dist/modes/interactive/components/daxnuts.d.ts +0 -23
  175. package/dist/modes/interactive/components/daxnuts.d.ts.map +0 -1
  176. package/dist/modes/interactive/components/daxnuts.js +0 -140
  177. package/dist/modes/interactive/components/daxnuts.js.map +0 -1
  178. package/dist/modes/interactive/components/pi-logo-animation.d.ts +0 -68
  179. package/dist/modes/interactive/components/pi-logo-animation.d.ts.map +0 -1
  180. package/dist/modes/interactive/components/pi-logo-animation.js.map +0 -1
  181. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts +0 -7
  182. package/dist/modes/interactive/components/pi-logo-animation.lazy.d.ts.map +0 -1
  183. package/dist/modes/interactive/components/pi-logo-animation.lazy.js +0 -12
  184. package/dist/modes/interactive/components/pi-logo-animation.lazy.js.map +0 -1
  185. package/npm-shrinkwrap.json +0 -1952
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,IAAI,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AAC,UAAU,EAAE,KAAK,KAAK,cAAc;4BAC3F,IAAI,EAAE,qCAAqC;yBAC3C,CAAC,CAAC;wBACH,IAAI,CAAC,MAAM;4BAAE,OAAO;wBACpB,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;wBACxC,IAAI,OAAO;4BAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;6BACxC,CAAC;4BACL,qBAAqB,CAAC,GAAG,CAAC,CAAC;4BAC3B,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,8BAA8B,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,aAAa,CAAC,MAAM,CAAC,IAAI,EAC9E,MAAM,CACN,CAAC;wBACH,CAAC;wBACD,OAAO;oBACR,CAAC;oBACD;wBACC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAqB;IAC/C,OAAO,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AACzG,CAAC;AAED,eAAe,kBAAkB,EAAE,CAAC","sourcesContent":["/**\n * Built-in MCP integration.\n *\n * Connects the servers from `mcp.json` and the servers extensions register with\n * `pi.registerMcpServer()` when a session starts, and servers registered later right away. A server\n * in `mcp.json` takes precedence over a registered server of the same name. Connections run in the\n * background: the first prompt waits only for servers with `direct` tools, and codemode scripts,\n * `tool_search`, and the resource tools wait for the servers they need when they run. Tools are\n * registered as `mcp__<server>__<tool>`. By default (`\"exposure\": \"codemode\"`) the tools are only\n * callable from codemode scripts, which keeps MCP tools out of the model's tool declarations and\n * the codemode description: scripts find the tools with `searchTools()` and the server instructions\n * with `describeNamespace()`. The codemode tool is activated for that unless `autoEnableCodemode` is\n * false. `\"deferred\"` declares the tools to the model once the `tool_search` tool loads them, and\n * activates `tool_search` instead of codemode.\n * `\"exposure\": \"direct\"` declares them to the model right away, and `\"hidden\"` makes them\n * unreachable. `toolExposure` overrides the exposure of single tools. Servers with resources are\n * reached through Codex's `list_mcp_resources`, `list_mcp_resource_templates`, and\n * `read_mcp_resource` tools (resources.ts).\n *\n * Every call runs through pi's tool pipeline, so `tool_call`/`tool_result` hooks and permission\n * extensions apply to MCP tools the same way they do to built-in tools.\n *\n * Problems found at startup (config errors, failed connections, servers that need a sign-in) are\n * reported once. `/mcp` opens a manager to sign in, reconnect, enable or disable servers, and change\n * their exposure; the last two are saved to the `mcp.json` that defines the server, or apply to the\n * current session for registered servers.\n */\n\nimport { join, resolve } from \"node:path\";\nimport { hyperlink, type SelectItem } from \"@earendil-works/pi-tui\";\nimport type { TSchema } from \"typebox\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tToolDefinition,\n} from \"../../core/extensions/types.ts\";\nimport { mcpNamespace } from \"../../core/mcp-servers.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { openBrowser } from \"../../utils/open-browser.ts\";\nimport { CODEMODE_TOOL_NAME, isCodemodeTool } from \"../codemode/tool.ts\";\nimport { isToolSearchTool, TOOL_SEARCH_TOOL_NAME } from \"../tool-search/tool.ts\";\nimport {\n\tgetMcpToolExposure,\n\ttype LoadedMcpConfig,\n\tloadMcpConfig,\n\ttype McpExposure,\n\ttype McpServerConfigPatch,\n\ttype McpServerEntry,\n\tupdateMcpServerConfig,\n} from \"./config.ts\";\nimport type { McpOAuthCredentialStore, McpSignInPrompt } from \"./oauth.ts\";\nimport {\n\tcreateMcpResourceToolDefinitions,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tLIST_MCP_RESOURCES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n} from \"./resources.ts\";\nimport { loadMcpRuntime } from \"./runtime.lazy.ts\";\nimport type * as McpRuntime from \"./runtime.ts\";\nimport type { McpServerConnection, McpServerLog, McpTransportFactory } from \"./runtime.ts\";\nimport { createMcpToolDefinition, createMcpToolName, type McpToolDetails } from \"./tools.ts\";\nimport { type McpMenu, type McpUi, showMcpManager } from \"./ui.ts\";\n\nexport type { McpTransportFactory } from \"./runtime.ts\";\n\nexport interface McpExtensionOptions {\n\t/** Defaults to reading `mcp.json` from the agent directory and the trusted project. */\n\tloadConfig?: (ctx: ExtensionContext) => LoadedMcpConfig;\n\t/** Defaults to stdio and streamable HTTP transports built from the server config. */\n\tcreateTransport?: McpTransportFactory;\n\t/** Defaults to `mcp-auth.json` in the agent directory. */\n\tcredentials?: McpOAuthCredentialStore;\n\t/** File server log messages are appended to. Defaults to `mcp.log` in the agent directory. */\n\tlogPath?: string;\n\t/** Opens the OAuth authorization URL. Defaults to the platform browser. */\n\topenUrl?: (url: string) => void;\n\t/** Saves `/mcp` changes to the server's config file. Defaults to editing its `mcp.json`. */\n\tupdateConfig?: (entry: McpServerEntry, patch: McpServerConfigPatch) => void;\n\t/**\n\t * How long the first prompt waits for servers with `direct` tools that are still connecting at\n\t * startup, in milliseconds. Their tools become available when they connect. Other servers are\n\t * waited for when a script or search needs them. Default: 10000.\n\t */\n\tstartupWaitMs?: number;\n}\n\nconst DEFAULT_STARTUP_WAIT_MS = 10_000;\n\nconst RESOURCE_TOOL_NAMES: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** A configured server. Disabled servers have no connection. */\ninterface McpServer {\n\tentry: McpServerEntry;\n\tconnection?: McpServerConnection;\n\t/** For servers extensions registered: the config as registered, to detect re-registrations. */\n\tregisteredConfig?: string;\n\t/** Result of the last `/mcp` action that failed, shown in the manager. */\n\tmessage?: string;\n\t/** Settles when the connection started for the server connected or failed. */\n\tready?: Promise<void>;\n}\n\nconst EXPOSURE_DESCRIPTIONS: Record<Exclude<McpExposure, \"hidden\">, string> = {\n\tcodemode: \"called from codemode scripts, which find them with searchTools()\",\n\tdeferred: \"not declared until tool_search loads them, then called directly; no codemode needed\",\n\tdirect: \"declared to the model like built-in tools\",\n};\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction firstLine(text: string): string {\n\treturn text.split(\"\\n\", 1)[0] ?? \"\";\n}\n\nfunction isEnabled(server: Pick<McpServer, \"entry\">): boolean {\n\treturn server.entry.config.enabled !== false;\n}\n\nfunction exposureOf(entry: McpServerEntry): McpExposure {\n\treturn entry.config.exposure ?? \"codemode\";\n}\n\n/** Exposures the server's tools can have, known from its config before it connects. */\nfunction configuredExposures(entry: McpServerEntry): Set<McpExposure> {\n\treturn new Set([exposureOf(entry), ...Object.values(entry.config.toolExposure ?? {})]);\n}\n\n/** Whether some of the server's tools are declared to the model, so the first prompt waits for them. */\nfunction hasDirectTools(entry: McpServerEntry): boolean {\n\treturn configuredExposures(entry).has(\"direct\");\n}\n\n/** Whether some of the server's tools are reached through codemode or tool_search. */\nfunction hasIndirectTools(entry: McpServerEntry): boolean {\n\tconst exposures = configuredExposures(entry);\n\treturn exposures.has(\"codemode\") || exposures.has(\"deferred\");\n}\n\n/** Name of the system prompt section that lists the servers whose tools are not declared. */\nexport const MCP_SERVERS_SECTION = \"mcp_servers\";\n/** Characters of a server description in the section, as Codex allows for deferred namespaces. */\nconst MAX_SERVER_DESCRIPTION_CHARS = 250;\n/**\n * Characters of the whole section. Descriptions shrink to fit; when the server lines alone do not\n * fit, the last servers are left out and counted in a closing line.\n */\nexport const MAX_SERVERS_SECTION_CHARS = 4096;\n\n/** The section's first line. It explains only the ways of reaching tools that the listed servers use. */\nfunction serversSectionIntro(reaches: ReadonlySet<string>): string {\n\tlet intro = \"MCP servers whose tools are not declared to you.\";\n\tif (reaches.has(\"codemode\")) intro += \" Call the tools of `codemode` servers from codemode scripts.\";\n\tif (reaches.has(\"tool_search\")) intro += \" Load the tools of `tool_search` servers with `tool_search`.\";\n\treturn intro;\n}\n\nfunction truncate(text: string, max: number): string {\n\tif (text.length <= max) return text;\n\treturn max <= 1 ? \"\" : `${text.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What the `mcp_servers` section needs of a server. */\nexport interface McpServerListing {\n\tentry: McpServerEntry;\n\tconnection?: { instructions?: string };\n}\n\n/** First line of the configured description, or of the server instructions once connected. */\nfunction serverSummary(server: McpServerListing): string {\n\tconst text = server.entry.config.description?.trim() || server.connection?.instructions || \"\";\n\treturn (text.split(\"\\n\", 1)[0] ?? \"\").trim();\n}\n\n/**\n * The `mcp_servers` section: every enabled server with codemode or deferred tools, with how its\n * tools are reached and a one-line summary. The model learns of the servers from it, since neither\n * codemode nor tool_search lists them. Undefined when there are no such servers.\n */\nexport function renderServersSection(servers: readonly McpServerListing[]): string | undefined {\n\tconst listed = servers\n\t\t.filter((server) => isEnabled(server) && hasIndirectTools(server.entry))\n\t\t.sort((a, b) => a.entry.name.localeCompare(b.entry.name));\n\tif (listed.length === 0) return undefined;\n\tconst reaches = listed.map((server) =>\n\t\tconfiguredExposures(server.entry).has(\"codemode\") ? \"codemode\" : \"tool_search\",\n\t);\n\tconst intro = serversSectionIntro(new Set(reaches));\n\tconst heads = listed.map((server, index) => `- ${mcpNamespace(server.entry.name)} (${reaches[index]})`);\n\tconst omitted = (count: number) =>\n\t\tcount > 0 ? [`- … ${count} more server${count === 1 ? \"\" : \"s\"}; find their tools with searchTools()`] : [];\n\t// Characters of the intro, the first `kept` server lines without descriptions, and the omission line.\n\tconst size = (kept: number) => [intro, ...heads.slice(0, kept), ...omitted(listed.length - kept)].join(\"\\n\").length;\n\tlet kept = listed.length;\n\twhile (kept > 0 && size(kept) > MAX_SERVERS_SECTION_CHARS) kept--;\n\t// Each description also takes a \": \" separator.\n\tconst perServer =\n\t\tkept === 0\n\t\t\t? 0\n\t\t\t: Math.min(MAX_SERVER_DESCRIPTION_CHARS, Math.floor((MAX_SERVERS_SECTION_CHARS - size(kept)) / kept) - 2);\n\tconst lines = listed.slice(0, kept).map((server, index) => {\n\t\tconst summary = perServer > 0 ? truncate(serverSummary(server), perServer) : \"\";\n\t\treturn summary ? `${heads[index]}: ${summary}` : heads[index];\n\t});\n\treturn [intro, ...lines, ...omitted(listed.length - kept)].join(\"\\n\");\n}\n\n/**\n * Whether a codemode script needs the server: it names the server's namespace, or searches,\n * enumerates, or describes tools or namespaces, which may name the server in other forms.\n */\nfunction scriptNeedsServer(code: string, server: string): boolean {\n\tif (/\\b(searchTools|describeNamespace|describeTool|ALL_TOOLS)\\b/.test(code)) return true;\n\treturn code.includes(mcpNamespace(server));\n}\n\n/** Short state for lists and the startup report. `withError` appends the first line of a failure. */\nfunction describeState(server: McpServer, withError = true): string {\n\tif (!isEnabled(server)) return \"disabled\";\n\tconst connection = server.connection;\n\tif (!connection) return \"starting\";\n\tswitch (connection.state) {\n\t\tcase \"needs-auth\":\n\t\t\treturn \"needs sign-in\";\n\t\tcase \"failed\":\n\t\t\treturn withError ? `failed: ${firstLine(connection.error ?? \"unknown error\")}` : \"failed\";\n\t\tcase \"connected\": {\n\t\t\tconst { tools, resources } = connection;\n\t\t\tconst count = resources.length;\n\t\t\tconst resourceCount = count > 0 ? ` · ${count} resource${count === 1 ? \"\" : \"s\"}` : \"\";\n\t\t\treturn `connected · ${tools.length} tool${tools.length === 1 ? \"\" : \"s\"}${resourceCount}`;\n\t\t}\n\t\tcase \"connecting\":\n\t\t\treturn \"connecting…\";\n\t\tdefault:\n\t\t\treturn connection.state;\n\t}\n}\n\n/** Servers that need the user first. */\nfunction attentionRank(server: McpServer): number {\n\tif (!isEnabled(server)) return 5;\n\tswitch (server.connection?.state) {\n\t\tcase \"needs-auth\":\n\t\t\treturn 0;\n\t\tcase \"failed\":\n\t\t\treturn 1;\n\t\tcase \"disconnected\":\n\t\t\treturn 2;\n\t\tcase \"connected\":\n\t\t\treturn 4;\n\t\tdefault:\n\t\t\treturn 3;\n\t}\n}\n\nfunction describeTransport(entry: McpServerEntry): string {\n\tconst { config } = entry;\n\tif (\"url\" in config) return config.url;\n\treturn [config.command, ...(config.args ?? [])].join(\" \");\n}\n\nconst MCP_USAGE = \"Usage: /mcp, /mcp login [server], /mcp logout [server], /mcp reconnect [server]\";\n\nexport function createMcpExtension(options: McpExtensionOptions = {}): ExtensionFactory {\n\treturn (pi: ExtensionAPI) => {\n\t\tlet servers: McpServer[] = [];\n\t\t/** Servers from `mcp.json`, which take precedence over registered servers of the same name. */\n\t\tlet configuredEntries: McpServerEntry[] = [];\n\t\tlet configErrors: string[] = [];\n\t\t/** Registered servers that `mcp.json` overrides, shown in `/mcp`. */\n\t\tlet overridden: string[] = [];\n\t\t/** Between session_start and session_shutdown. Registrations before that are read on session_start. */\n\t\tlet sessionActive = false;\n\t\tlet autoEnableCodemode = true;\n\t\t/** Whether the \"codemode tools unreachable\" warning was shown since the session started. */\n\t\tlet warnedUnreachable = false;\n\t\tlet pending: Promise<unknown> | undefined;\n\t\t/** Whether a prompt already waited for the startup connections since the session started. */\n\t\tlet waitedForStartup = false;\n\t\tconst startupWaitMs = options.startupWaitMs ?? DEFAULT_STARTUP_WAIT_MS;\n\t\t/** Bumped on every session start and shutdown so a runtime load that resolves late is dropped. */\n\t\tlet generation = 0;\n\t\t/** Working directory of the session, for stdio servers. */\n\t\tlet sessionCwd = process.cwd();\n\t\tlet credentials = options.credentials;\n\t\t/** The session's model registry, which resolves `auth.provider` tokens. */\n\t\tlet modelRegistry: ModelRegistry | undefined;\n\t\tlet serverLog: McpServerLog | undefined;\n\t\tconst openUrl = options.openUrl ?? openBrowser;\n\t\tconst updateConfig =\n\t\t\toptions.updateConfig ?? ((entry, patch) => updateMcpServerConfig(entry.source, entry.name, patch));\n\n\t\tconst listeners = new Set<() => void>();\n\t\tconst emitChange = () => {\n\t\t\tfor (const listener of listeners) listener();\n\t\t};\n\t\tconst subscribe = (listener: () => void) => {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener);\n\t\t\t};\n\t\t};\n\n\t\tconst connections = () => servers.flatMap((server) => (server.connection ? [server.connection] : []));\n\t\tconst findServer = (name: string) => servers.find((server) => server.entry.name === name);\n\n\t\t/** Servers extensions registered, except names `mcp.json` defines, which take precedence. */\n\t\tconst registeredServers = (): { servers: McpServer[]; overridden: string[] } => {\n\t\t\tconst registered: McpServer[] = [];\n\t\t\tconst overriddenNames: string[] = [];\n\t\t\tfor (const { name, config, extensionPath } of pi.getMcpServers()) {\n\t\t\t\tconst configured = configuredEntries.find((entry) => mcpNamespace(entry.name) === mcpNamespace(name));\n\t\t\t\tif (configured) {\n\t\t\t\t\toverriddenNames.push(\n\t\t\t\t\t\t`\"${name}\" registered by ${extensionPath} is overridden by \"${configured.name}\" in ${configured.source}`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tregistered.push({\n\t\t\t\t\tentry: { name, config, source: extensionPath, scope: \"extension\" },\n\t\t\t\t\tregisteredConfig: JSON.stringify(config),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn { servers: registered, overridden: overriddenNames };\n\t\t};\n\n\t\tconst getCredentials = (runtime: typeof McpRuntime): McpOAuthCredentialStore => {\n\t\t\tcredentials ??= new runtime.McpOAuthCredentialStore();\n\t\t\treturn credentials;\n\t\t};\n\n\t\tconst getServerLog = (runtime: typeof McpRuntime): McpServerLog => {\n\t\t\tserverLog ??= new runtime.McpServerLog(options.logPath ?? join(getAgentDir(), \"mcp.log\"));\n\t\t\treturn serverLog;\n\t\t};\n\n\t\t/** pi tool name to the `<server>\\0<tool>` it was assigned to, so names stay unique and stable. */\n\t\tconst toolOwners = new Map<string, string>();\n\t\t/** Tool names currently offered by each server. */\n\t\tconst serverTools = new Map<string, Set<string>>();\n\t\t/** Last definition registered under each tool name, to re-register withdrawn tools as hidden. */\n\t\tconst definitions = new Map<string, ToolDefinition<TSchema, McpToolDetails>>();\n\n\t\tconst registerTools = (connection: McpServerConnection) => {\n\t\t\tconst server = connection.entry.name;\n\t\t\tconst entry = findServer(server)?.entry ?? connection.entry;\n\t\t\tconst description = entry.config.description?.trim();\n\t\t\tconst namespace = {\n\t\t\t\tname: mcpNamespace(server),\n\t\t\t\t...(description ? { description } : {}),\n\t\t\t\t...(connection.instructions ? { instructions: connection.instructions } : {}),\n\t\t\t};\n\t\t\tconst previous = serverTools.get(server) ?? new Set<string>();\n\t\t\tconst current = new Set<string>();\n\t\t\t// Like Codex, all tools whose names sanitize to the same name get the hash suffix, so which\n\t\t\t// one would keep the plain name does not depend on the order of the list.\n\t\t\tconst plain = [...new Set(connection.tools.map((tool) => tool.name))].map((tool) =>\n\t\t\t\tcreateMcpToolName(server, tool),\n\t\t\t);\n\t\t\tconst assignName = (tool: string, owner: string) => {\n\t\t\t\tconst name = createMcpToolName(server, tool, (candidate) => {\n\t\t\t\t\tconst existing = toolOwners.get(candidate);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(existing !== undefined && existing !== owner) ||\n\t\t\t\t\t\tcurrent.has(candidate) ||\n\t\t\t\t\t\tplain.indexOf(candidate) !== plain.lastIndexOf(candidate)\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\ttoolOwners.set(name, owner);\n\t\t\t\tcurrent.add(name);\n\t\t\t\treturn name;\n\t\t\t};\n\t\t\tfor (const tool of connection.tools) {\n\t\t\t\tconst definition = createMcpToolDefinition({\n\t\t\t\t\tserver,\n\t\t\t\t\ttool,\n\t\t\t\t\tname: assignName(tool.name, `${server}\\0${tool.name}`),\n\t\t\t\t\texposure: getMcpToolExposure(entry.config, tool.name),\n\t\t\t\t\tnamespace,\n\t\t\t\t\ttimeoutMs: connection.timeoutMs,\n\t\t\t\t\tgetClient: async () => connection,\n\t\t\t\t\treadableResources: () => resourceServers().includes(connection),\n\t\t\t\t});\n\t\t\t\tdefinitions.set(definition.name, definition);\n\t\t\t\tpi.registerTool(definition);\n\t\t\t}\n\t\t\tserverTools.set(server, current);\n\t\t\t// Tools cannot be unregistered, so tools the server dropped are re-registered as hidden. When\n\t\t\t// the server offers them again they are registered with their configured exposure above.\n\t\t\tfor (const name of previous) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (!current.has(name) && definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Make a disabled server's tools unreachable. */\n\t\tconst hideTools = (server: string) => {\n\t\t\tfor (const name of serverTools.get(server) ?? []) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tserverTools.set(server, new Set());\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Enabled servers with resources whose exposure is not `hidden`, which the resource tools reach. */\n\t\tconst serversWithResources = (): McpServer[] =>\n\t\t\tservers.filter(\n\t\t\t\t(server) => server.connection?.hasResources && isEnabled(server) && exposureOf(server.entry) !== \"hidden\",\n\t\t\t);\n\t\tconst resourceServers = (): McpServerConnection[] =>\n\t\t\tserversWithResources().flatMap((server) => (server.connection ? [server.connection] : []));\n\n\t\t/** Exposure the resource tools were last registered with; undefined until a server has resources. */\n\t\tlet resourceToolsExposure: McpExposure | undefined;\n\t\t/**\n\t\t * Register the resource tools with the widest exposure of the servers they reach: `direct` when\n\t\t * one of them is direct, and so on. They are hidden when no server has resources.\n\t\t */\n\t\tconst syncResourceTools = () => {\n\t\t\tconst exposures = new Set(serversWithResources().map((server) => exposureOf(server.entry)));\n\t\t\tconst exposure = ([\"direct\", \"codemode\", \"deferred\"] as const).find((candidate) => exposures.has(candidate));\n\t\t\tconst next = exposure ?? \"hidden\";\n\t\t\tif (next === resourceToolsExposure || (resourceToolsExposure === undefined && next === \"hidden\")) return;\n\t\t\tconst wasDirect = resourceToolsExposure === \"direct\";\n\t\t\tresourceToolsExposure = next;\n\t\t\tconst resourceDefinitions = createMcpResourceToolDefinitions({ exposure: next, servers: resourceServers });\n\t\t\tfor (const definition of resourceDefinitions) pi.registerTool(definition);\n\t\t\tif (wasDirect) {\n\t\t\t\tconst names = new Set(resourceDefinitions.map((definition) => definition.name));\n\t\t\t\tpi.setActiveTools(pi.getActiveTools().filter((name) => !names.has(name)));\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * Tools that are not declared to the model are reached through the codemode tool (scripts call\n\t\t * them) or the tool_search tool (it declares them). Either reaches every such tool. Activate the\n\t\t * one the tools' exposure asks for: codemode for `codemode` unless `autoEnableCodemode` is false,\n\t\t * tool_search for `deferred`.\n\t\t */\n\t\tconst ensureDiscoveryActive = (ctx: ExtensionContext) => {\n\t\t\t// From the config, so the tool is active before the servers connect. Resource tools share\n\t\t\t// their server's exposure.\n\t\t\tconst exposures = new Set<McpExposure>();\n\t\t\tfor (const server of servers) {\n\t\t\t\tif (isEnabled(server)) for (const exposure of configuredExposures(server.entry)) exposures.add(exposure);\n\t\t\t}\n\t\t\tconst needsCodemode = exposures.has(\"codemode\");\n\t\t\tconst needsToolSearch = exposures.has(\"deferred\");\n\t\t\tif (!needsCodemode && !needsToolSearch) return;\n\t\t\t// Other extensions' tools of the same names cannot reach MCP tools, so never activate them.\n\t\t\tconst tools = pi.getAllTools();\n\t\t\tconst hasCodemode = tools.some(isCodemodeTool);\n\t\t\tconst hasToolSearch = tools.some(isToolSearchTool);\n\t\t\tconst active = pi.getActiveTools();\n\t\t\tconst activate: string[] = [];\n\t\t\tif (needsCodemode && hasCodemode && autoEnableCodemode && !active.includes(CODEMODE_TOOL_NAME)) {\n\t\t\t\tactivate.push(CODEMODE_TOOL_NAME);\n\t\t\t}\n\t\t\tif (needsToolSearch && hasToolSearch && !active.includes(TOOL_SEARCH_TOOL_NAME)) {\n\t\t\t\tactivate.push(TOOL_SEARCH_TOOL_NAME);\n\t\t\t}\n\t\t\tif (activate.length > 0) pi.setActiveTools([...active, ...activate]);\n\t\t\tconst reachable = [...active, ...activate];\n\t\t\tif (hasCodemode && reachable.includes(CODEMODE_TOOL_NAME)) return;\n\t\t\tif (hasToolSearch && reachable.includes(TOOL_SEARCH_TOOL_NAME)) return;\n\t\t\tif (warnedUnreachable) return;\n\t\t\twarnedUnreachable = true;\n\t\t\tconst reason = needsCodemode && hasCodemode && !autoEnableCodemode ? \" (autoEnableCodemode is false)\" : \"\";\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP tools are only reachable from the codemode or tool_search tool, but neither is active${reason}; they cannot be called.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/**\n\t\t * Stored tokens of servers waiting for a sign-in, as they were when the sign-in was needed.\n\t\t * `pi mcp login` in another process (for example run by the agent) changes them.\n\t\t */\n\t\tconst tokensAtSignIn = new Map<McpServerConnection, string>();\n\t\tconst storedTokens = (connection: McpServerConnection): string => {\n\t\t\tconst url = connection.oauthUrl;\n\t\t\treturn url && credentials ? JSON.stringify(credentials.tokens(connection.name, url) ?? null) : \"null\";\n\t\t};\n\t\tconst onConnectionChange = (connection: McpServerConnection) => {\n\t\t\tif (connection.state !== \"needs-auth\") tokensAtSignIn.delete(connection);\n\t\t\telse if (!tokensAtSignIn.has(connection)) tokensAtSignIn.set(connection, storedTokens(connection));\n\t\t\temitChange();\n\t\t};\n\t\t/** Reconnect servers that need a sign-in when their credentials were stored since. */\n\t\tconst reconnectSignedIn = async (ctx: ExtensionContext) => {\n\t\t\tconst signedIn = [...tokensAtSignIn].filter(([connection, tokens]) => storedTokens(connection) !== tokens);\n\t\t\tif (signedIn.length === 0) return;\n\t\t\tfor (const [connection] of signedIn) tokensAtSignIn.delete(connection);\n\t\t\tawait Promise.allSettled(signedIn.map(([connection]) => connection.reconnect()));\n\t\t\tensureDiscoveryActive(ctx);\n\t\t};\n\n\t\t/** Create the server's connection, loading the MCP runtime on first use. */\n\t\tconst createConnection = async (server: McpServer): Promise<McpServerConnection> => {\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\tconst connection = new runtime.McpServerConnection({\n\t\t\t\tentry: server.entry,\n\t\t\t\tcwd: sessionCwd,\n\t\t\t\tcreateTransport: options.createTransport ?? runtime.createDefaultTransport,\n\t\t\t\tcredentials: getCredentials(runtime),\n\t\t\t\tproviderToken: async (provider) => modelRegistry?.getApiKeyForProvider(provider),\n\t\t\t\tlog: getServerLog(runtime),\n\t\t\t\tonTools: registerTools,\n\t\t\t\tonChange: onConnectionChange,\n\t\t\t});\n\t\t\tserver.connection = connection;\n\t\t\temitChange();\n\t\t\treturn connection;\n\t\t};\n\n\t\t/**\n\t\t * Connect the server in the background. `server.ready` settles when it connected or failed;\n\t\t * failures show in its state. It starts after `after`; `isCurrent` stops it when the session ended\n\t\t * meanwhile. The returned promise rejects when the MCP runtime cannot be loaded.\n\t\t */\n\t\tconst startConnection = (\n\t\t\tserver: McpServer,\n\t\t\tisCurrent: () => boolean,\n\t\t\tafter?: Promise<unknown>,\n\t\t): Promise<void> => {\n\t\t\tconst ready = (async () => {\n\t\t\t\tawait after;\n\t\t\t\tif (!isCurrent()) return;\n\t\t\t\tconst connection = await createConnection(server);\n\t\t\t\tif (!isCurrent()) return;\n\t\t\t\tawait connection.getClient().catch(() => undefined);\n\t\t\t})();\n\t\t\tserver.ready = ready.catch(() => undefined);\n\t\t\treturn ready;\n\t\t};\n\n\t\t/** Wait for servers still connecting, until they settle or `signal` aborts. */\n\t\tconst waitForServers = async (waiting: readonly McpServer[], signal: AbortSignal | undefined) => {\n\t\t\tconst ready = waiting.flatMap((server) => (server.ready ? [server.ready] : []));\n\t\t\tif (ready.length === 0 || signal?.aborted) return;\n\t\t\tlet onAbort: (() => void) | undefined;\n\t\t\tawait Promise.race([\n\t\t\t\tPromise.all(ready),\n\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\tonAbort = () => resolve();\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tif (onAbort) signal?.removeEventListener(\"abort\", onAbort);\n\t\t};\n\n\t\t/**\n\t\t * One message for everything that needs the user after startup, or only for `only`, servers\n\t\t * that connected later.\n\t\t */\n\t\tconst reportProblems = (ctx: ExtensionContext, only?: readonly McpServer[]) => {\n\t\t\tconst lines = only ? [] : configErrors.map((error) => `config: ${error}`);\n\t\t\tfor (const server of only ?? servers) {\n\t\t\t\tconst state = server.connection?.state;\n\t\t\t\tif (state === \"needs-auth\" || state === \"failed\")\n\t\t\t\t\tlines.push(`${server.entry.name}: ${describeState(server)}`);\n\t\t\t}\n\t\t\tif (lines.length === 0) return;\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP servers need attention:\\n${lines.map((line) => ` ${line}`).join(\"\\n\")}\\nRun /mcp to fix.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/**\n\t\t * Save a config change; returns an error message when the file could not be updated. Changes to\n\t\t * registered servers only apply to the current session.\n\t\t */\n\t\tconst saveConfig = (server: McpServer, patch: McpServerConfigPatch): string | undefined => {\n\t\t\tif (server.entry.scope !== \"extension\") {\n\t\t\t\ttry {\n\t\t\t\t\tupdateConfig(server.entry, patch);\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn `Could not update ${server.entry.source}: ${errorMessage(error)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\tserver.entry = { ...server.entry, config: { ...server.entry.config, ...patch } };\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst signIn = async (server: McpServer, prompt: McpSignInPrompt): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return `MCP server \"${server.entry.name}\" does not use OAuth.`;\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\ttry {\n\t\t\t\tawait runtime.signInMcpServer({\n\t\t\t\t\tserverUrl: url,\n\t\t\t\t\tstore: getCredentials(runtime).forServer(server.entry.name, url),\n\t\t\t\t\tsettings: connection.oauthSettings(),\n\t\t\t\t\tchallenge: connection.challenge,\n\t\t\t\t\tprompt,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof runtime.McpSignInCancelledError) return \"Sign-in cancelled.\";\n\t\t\t\treturn `Sign-in failed: ${errorMessage(error)}`;\n\t\t\t}\n\t\t\t// The challenge that asked for this sign-in (for example for more scope) is answered.\n\t\t\tconnection.challenge = undefined;\n\t\t\ttry {\n\t\t\t\tawait connection.reconnect();\n\t\t\t} catch (error) {\n\t\t\t\treturn `Signed in, but ${errorMessage(error)}`;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst signOut = async (server: McpServer): Promise<boolean> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return false;\n\t\t\tconst removed = getCredentials(await loadMcpRuntime()).remove(server.entry.name, url);\n\t\t\tawait connection.signOut();\n\t\t\treturn removed;\n\t\t};\n\n\t\tconst reconnect = async (server: McpServer): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tif (!connection) return `MCP server \"${server.entry.name}\" is disabled.`;\n\t\t\ttry {\n\t\t\t\tawait connection.reconnect();\n\t\t\t\treturn undefined;\n\t\t\t} catch (error) {\n\t\t\t\treturn errorMessage(error);\n\t\t\t}\n\t\t};\n\n\t\t/** Returns an error message when the config could not be saved; connection errors show in the state. */\n\t\tconst setEnabled = async (server: McpServer, enabled: boolean): Promise<string | undefined> => {\n\t\t\tconst failed = saveConfig(server, { enabled });\n\t\t\tif (failed) return failed;\n\t\t\tif (!enabled) {\n\t\t\t\tconst connection = server.connection;\n\t\t\t\tserver.connection = undefined;\n\t\t\t\thideTools(server.entry.name);\n\t\t\t\temitChange();\n\t\t\t\tawait connection?.close();\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tawait startConnection(server, () => true);\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst setExposure = (server: McpServer, exposure: McpExposure): string | undefined => {\n\t\t\tconst failed = saveConfig(server, { exposure });\n\t\t\tif (failed) return failed;\n\t\t\tif (server.connection?.state === \"connected\") registerTools(server.connection);\n\t\t\tsyncResourceTools();\n\t\t\t// Tools no longer exposed directly leave the declared set; direct tools are activated on registration.\n\t\t\tconst indirect = new Set(\n\t\t\t\tpi\n\t\t\t\t\t.getAllTools()\n\t\t\t\t\t.filter((tool) => tool.exposure !== \"direct\")\n\t\t\t\t\t.map((tool) => tool.name),\n\t\t\t);\n\t\t\tconst tools = serverTools.get(server.entry.name) ?? new Set<string>();\n\t\t\tpi.setActiveTools(pi.getActiveTools().filter((name) => !tools.has(name) || !indirect.has(name)));\n\t\t\temitChange();\n\t\t\treturn undefined;\n\t\t};\n\n\t\t// ---------------------------------------------------------------------------------------\n\t\t// Manager (`/mcp` in the TUI)\n\t\t// ---------------------------------------------------------------------------------------\n\n\t\tconst notices = () => [\n\t\t\t...configErrors.map((error) => `config: ${error}`),\n\t\t\t...overridden.map((line) => `overridden: ${line}`),\n\t\t];\n\n\t\tconst serversMenu = (): McpMenu => ({\n\t\t\ttitle: \"MCP servers\",\n\t\t\terror: notices().join(\"\\n\") || undefined,\n\t\t\titems: [...servers]\n\t\t\t\t.sort((a, b) => attentionRank(a) - attentionRank(b) || a.entry.name.localeCompare(b.entry.name))\n\t\t\t\t.map((server) => ({\n\t\t\t\t\tvalue: server.entry.name,\n\t\t\t\t\tlabel: server.entry.name,\n\t\t\t\t\tdescription: `${describeState(server)} · ${exposureOf(server.entry)} · ${server.entry.scope ?? server.entry.source}`,\n\t\t\t\t})),\n\t\t\tempty: `No MCP servers configured. Add them to ${resolve(getAgentDir(), \"mcp.json\")} or .pi/mcp.json.`,\n\t\t\tconfirmLabel: \"manage\",\n\t\t\tcancelLabel: \"close\",\n\t\t});\n\n\t\tconst serverMenu = (name: string): McpMenu => {\n\t\t\tconst server = findServer(name);\n\t\t\tif (!server) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: name,\n\t\t\t\t\titems: [],\n\t\t\t\t\tempty: \"This server is no longer configured.\",\n\t\t\t\t\tconfirmLabel: \"\",\n\t\t\t\t\tcancelLabel: \"back\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst { entry, connection } = server;\n\t\t\tconst saved =\n\t\t\t\tentry.scope === \"extension\"\n\t\t\t\t\t? \"for this session\"\n\t\t\t\t\t: entry.scope\n\t\t\t\t\t\t? `saved to the ${entry.scope} mcp.json`\n\t\t\t\t\t\t: \"saved to mcp.json\";\n\t\t\tconst items: SelectItem[] = [];\n\t\t\tif (!isEnabled(server)) {\n\t\t\t\titems.push({ value: \"enable\", label: \"Enable\", description: saved });\n\t\t\t} else {\n\t\t\t\tconst state = connection?.state;\n\t\t\t\tif (state === \"needs-auth\")\n\t\t\t\t\titems.push({ value: \"signin\", label: \"Sign in\", description: \"opens the browser\" });\n\t\t\t\tif (state === \"connected\" && connection) {\n\t\t\t\t\titems.push({ value: \"tools\", label: \"Tools\", description: `${connection.tools.length} offered` });\n\t\t\t\t}\n\t\t\t\tif (state === \"failed\" || state === \"disconnected\" || state === \"connected\" || state === \"needs-auth\") {\n\t\t\t\t\titems.push({ value: \"reconnect\", label: \"Reconnect\" });\n\t\t\t\t}\n\t\t\t\tif (state === \"connected\" && connection?.oauthUrl) {\n\t\t\t\t\titems.push({ value: \"signout\", label: \"Sign out\", description: \"deletes the stored credentials\" });\n\t\t\t\t}\n\t\t\t\titems.push({ value: \"exposure\", label: \"Exposure\", description: exposureOf(entry) });\n\t\t\t\titems.push({ value: \"disable\", label: \"Disable\", description: saved });\n\t\t\t}\n\t\t\tconst details = [\n\t\t\t\tdescribeTransport(entry),\n\t\t\t\t`${entry.scope ?? \"config\"}: ${entry.source}`,\n\t\t\t\t`State: ${describeState(server, false)}`,\n\t\t\t];\n\t\t\tconst error = [server.message, connection?.state === \"connected\" ? undefined : connection?.error]\n\t\t\t\t.filter((line): line is string => line !== undefined)\n\t\t\t\t.join(\"\\n\");\n\t\t\treturn {\n\t\t\t\ttitle: `MCP server ${name}`,\n\t\t\t\tdetails: details.join(\"\\n\"),\n\t\t\t\terror: error || undefined,\n\t\t\t\titems,\n\t\t\t\tselected: items[0]?.value,\n\t\t\t\tconfirmLabel: \"select\",\n\t\t\t\tcancelLabel: \"back\",\n\t\t\t};\n\t\t};\n\n\t\tconst showTools = async (ui: McpUi, server: McpServer) => {\n\t\t\tconst exposure = exposureOf(server.entry);\n\t\t\tconst overridden = Object.keys(server.entry.config.toolExposure ?? {}).length > 0;\n\t\t\tawait ui.menu(() => ({\n\t\t\t\ttitle: `Tools of ${server.entry.name}`,\n\t\t\t\tdetails: `Exposure ${exposure}: ${exposure === \"hidden\" ? \"unreachable\" : EXPOSURE_DESCRIPTIONS[exposure]}${overridden ? \"\\nSome tools override it with toolExposure.\" : \"\"}`,\n\t\t\t\titems: (server.connection?.tools ?? []).map((tool) => {\n\t\t\t\t\tconst toolExposure = getMcpToolExposure(server.entry.config, tool.name);\n\t\t\t\t\tconst description = firstLine(tool.description ?? \"\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: tool.name,\n\t\t\t\t\t\tlabel: tool.name,\n\t\t\t\t\t\tdescription: toolExposure === exposure ? description : `[${toolExposure}] ${description}`,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t\tempty: \"The server offers no tools.\",\n\t\t\t\tconfirmLabel: \"back\",\n\t\t\t\tcancelLabel: \"back\",\n\t\t\t}));\n\t\t};\n\n\t\tconst chooseExposure = async (ui: McpUi, server: McpServer): Promise<string | undefined> => {\n\t\t\tconst current = exposureOf(server.entry);\n\t\t\tconst choice = await ui.menu(() => ({\n\t\t\t\ttitle: `Exposure of ${server.entry.name}`,\n\t\t\t\tdetails:\n\t\t\t\t\tserver.entry.scope === \"extension\"\n\t\t\t\t\t\t? `Applies to this session; the server is registered by ${server.entry.source}.`\n\t\t\t\t\t\t: `Saved to ${server.entry.source}.`,\n\t\t\t\titems: (Object.keys(EXPOSURE_DESCRIPTIONS) as (keyof typeof EXPOSURE_DESCRIPTIONS)[]).map((exposure) => ({\n\t\t\t\t\tvalue: exposure,\n\t\t\t\t\tlabel: `${exposure === current ? \"✓ \" : \" \"}${exposure}`,\n\t\t\t\t\tdescription: EXPOSURE_DESCRIPTIONS[exposure],\n\t\t\t\t})),\n\t\t\t\tselected: current,\n\t\t\t\tconfirmLabel: \"save\",\n\t\t\t\tcancelLabel: \"back\",\n\t\t\t}));\n\t\t\tif (!choice || choice === current) return undefined;\n\t\t\treturn setExposure(server, choice as McpExposure);\n\t\t};\n\n\t\tconst runAction = async (ui: McpUi, ctx: ExtensionContext, server: McpServer, action: string) => {\n\t\t\tconst { name } = server.entry;\n\t\t\tlet message: string | undefined;\n\t\t\tswitch (action) {\n\t\t\t\tcase \"signin\": {\n\t\t\t\t\tconst title = `Sign in to ${name}`;\n\t\t\t\t\tlet authorizationUrl = \"\";\n\t\t\t\t\tui.status(title, \"Contacting the authorization server…\");\n\t\t\t\t\tmessage = await signIn(server, {\n\t\t\t\t\t\tshowAuthorizationUrl: (url) => {\n\t\t\t\t\t\t\tauthorizationUrl = url.href;\n\t\t\t\t\t\t\topenUrl(url.href);\n\t\t\t\t\t\t},\n\t\t\t\t\t\tpromptForRedirectUrl: async (signal) => {\n\t\t\t\t\t\t\tconst value = await ui.redirectUrl(title, authorizationUrl, signal);\n\t\t\t\t\t\t\tui.status(title, \"Connecting…\");\n\t\t\t\t\t\t\treturn value;\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase \"reconnect\":\n\t\t\t\t\t// A failure shows as the connection's state and error.\n\t\t\t\t\tui.status(`MCP server ${name}`, \"Reconnecting…\");\n\t\t\t\t\tawait reconnect(server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"signout\":\n\t\t\t\t\tawait signOut(server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"tools\":\n\t\t\t\t\tawait showTools(ui, server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"exposure\":\n\t\t\t\t\tmessage = await chooseExposure(ui, server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"enable\":\n\t\t\t\tcase \"disable\":\n\t\t\t\t\tui.status(`MCP server ${name}`, action === \"enable\" ? \"Connecting…\" : \"Disconnecting…\");\n\t\t\t\t\tmessage = await setEnabled(server, action === \"enable\");\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tserver.message = message;\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\temitChange();\n\t\t};\n\t\tconst manage = async (ui: McpUi, ctx: ExtensionContext) => {\n\t\t\tfor (;;) {\n\t\t\t\tconst name = await ui.menu(serversMenu, subscribe);\n\t\t\t\tif (!name) return;\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst action = await ui.menu(() => serverMenu(name), subscribe);\n\t\t\t\t\tconst server = findServer(name);\n\t\t\t\t\tif (!action || !server) break;\n\t\t\t\t\tawait runAction(ui, ctx, server, action);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// ---------------------------------------------------------------------------------------\n\t\t// Subcommands and plain status (no TUI)\n\t\t// ---------------------------------------------------------------------------------------\n\n\t\tconst formatStatus = (): string => {\n\t\t\tif (servers.length === 0 && configErrors.length === 0 && overridden.length === 0) {\n\t\t\t\treturn `No MCP servers configured. Add them to ${resolve(getAgentDir(), \"mcp.json\")} or .pi/mcp.json.`;\n\t\t\t}\n\t\t\tconst lines = servers.map((server) => {\n\t\t\t\tconst { name } = server.entry;\n\t\t\t\tconst exposure = exposureOf(server.entry);\n\t\t\t\tconst connection = server.connection;\n\t\t\t\tif (connection?.state === \"needs-auth\")\n\t\t\t\t\treturn `${name}: needs sign-in, run /mcp login ${name} (${exposure})`;\n\t\t\t\tconst tools = connection?.state === \"connected\" ? `, ${connection.tools.length} tools` : \"\";\n\t\t\t\tconst state = !isEnabled(server)\n\t\t\t\t\t? \"disabled\"\n\t\t\t\t\t: connection?.state === \"disconnected\"\n\t\t\t\t\t\t? \"disconnected, reconnects on next call\"\n\t\t\t\t\t\t: (connection?.state ?? \"starting\");\n\t\t\t\tconst error =\n\t\t\t\t\tconnection?.error && connection.state !== \"connected\"\n\t\t\t\t\t\t? `\\n ${connection.error.split(\"\\n\").join(\"\\n \")}`\n\t\t\t\t\t\t: \"\";\n\t\t\t\treturn `${name}: ${state}${tools} (${exposure})${error}`;\n\t\t\t});\n\t\t\tfor (const error of configErrors) lines.push(`config error: ${error}`);\n\t\t\tfor (const line of overridden) lines.push(`overridden: ${line}`);\n\t\t\treturn lines.join(\"\\n\");\n\t\t};\n\n\t\t/** Resolve the server for a subcommand, asking when the name is omitted and ambiguous. */\n\t\tconst pickServer = async (\n\t\t\tname: string | undefined,\n\t\t\tctx: ExtensionCommandContext,\n\t\t\toptions: { eligible: (server: McpServer) => boolean; preferred: (server: McpServer) => boolean; none: string },\n\t\t): Promise<McpServer | undefined> => {\n\t\t\tif (name) {\n\t\t\t\tconst server = findServer(name);\n\t\t\t\tif (!server) ctx.ui.notify(`No MCP server named \"${name}\".`, \"error\");\n\t\t\t\telse if (!options.eligible(server)) ctx.ui.notify(options.none, \"error\");\n\t\t\t\treturn server && options.eligible(server) ? server : undefined;\n\t\t\t}\n\t\t\tconst candidates = servers.filter(options.eligible);\n\t\t\tif (candidates.length === 0) {\n\t\t\t\tctx.ui.notify(options.none, \"info\");\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst preferred = candidates.filter(options.preferred);\n\t\t\tif (candidates.length === 1) return candidates[0];\n\t\t\tif (preferred.length === 1) return preferred[0];\n\t\t\tconst choice = await ctx.ui.select(\n\t\t\t\t\"MCP server\",\n\t\t\t\tcandidates.map((server) => server.entry.name),\n\t\t\t);\n\t\t\treturn candidates.find((server) => server.entry.name === choice);\n\t\t};\n\n\t\tconst usesOAuth = (server: McpServer) => server.connection?.oauthUrl !== undefined;\n\t\tconst oauthPick = {\n\t\t\teligible: usesOAuth,\n\t\t\tpreferred: (server: McpServer) => server.connection?.state === \"needs-auth\",\n\t\t\tnone: \"No enabled MCP server uses OAuth. Only HTTP servers without an Authorization header do.\",\n\t\t};\n\n\t\tconst loginCommand = async (server: McpServer, ctx: ExtensionCommandContext) => {\n\t\t\tconst { name } = server.entry;\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\tctx.ui.notify(`Signing in to MCP server \"${name}\" requires interactive mode.`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst failure = await signIn(server, {\n\t\t\t\tshowAuthorizationUrl: (url) => {\n\t\t\t\t\t// Long URLs wrap, which some terminals cannot open; a short link line stays on one line.\n\t\t\t\t\tconst lines =\n\t\t\t\t\t\tctx.mode === \"tui\"\n\t\t\t\t\t\t\t? `${hyperlink(url.href, url.href)}\\n${hyperlink(process.platform === \"darwin\" ? \"Cmd+click to open\" : \"Ctrl+click to open\", url.href)}`\n\t\t\t\t\t\t\t: url.href;\n\t\t\t\t\tctx.ui.notify(`Sign in to MCP server \"${name}\" in your browser:\\n${lines}`, \"info\");\n\t\t\t\t\topenUrl(url.href);\n\t\t\t\t},\n\t\t\t\tpromptForRedirectUrl: (signal) =>\n\t\t\t\t\tctx.ui.input(\n\t\t\t\t\t\t`Waiting for sign-in to \"${name}\". If the browser cannot reach this machine, paste the URL it was redirected to.`,\n\t\t\t\t\t\t\"http://127.0.0.1:.../callback?code=...\",\n\t\t\t\t\t\t{ signal },\n\t\t\t\t\t),\n\t\t\t});\n\t\t\tif (failure) {\n\t\t\t\tctx.ui.notify(failure, failure === \"Sign-in cancelled.\" ? \"info\" : \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tctx.ui.notify(`Signed in to MCP server \"${name}\" (${server.connection?.tools.length ?? 0} tools).`, \"info\");\n\t\t};\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tconst loaded = (options.loadConfig ?? defaultLoadConfig)(ctx);\n\t\t\tconfigErrors = loaded.errors;\n\t\t\tautoEnableCodemode = loaded.autoEnableCodemode ?? true;\n\t\t\twarnedUnreachable = false;\n\t\t\twaitedForStartup = false;\n\t\t\tsessionCwd = ctx.cwd;\n\t\t\tmodelRegistry = ctx.modelRegistry;\n\t\t\tconst current = ++generation;\n\t\t\tsessionActive = true;\n\t\t\tconfiguredEntries = loaded.servers;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tservers = [...loaded.servers.map((entry) => ({ entry })), ...registered.servers];\n\t\t\temitChange();\n\t\t\t// Codemode or tool_search is activated from the config: the first prompt does not wait for\n\t\t\t// servers whose tools are not declared to the model, and scripts or searches wait for them.\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tconst enabled = servers.filter(isEnabled);\n\t\t\tif (enabled.length === 0) {\n\t\t\t\treportProblems(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The MCP client loads only now, so sessions without servers never pay for it. Waiting one\n\t\t\t// event loop turn lets the first render happen before loading and connecting.\n\t\t\tconst runtime = new Promise((resolve) => setImmediate(resolve)).then(() => loadMcpRuntime());\n\t\t\tconst isCurrent = () => current === generation;\n\t\t\tpending = Promise.all(enabled.map((server) => startConnection(server, isCurrent, runtime)))\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (isCurrent()) reportProblems(ctx);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\t// The session may have been disposed meanwhile, which makes ctx stale.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\t\t} catch {}\n\t\t\t\t});\n\t\t});\n\n\t\t// The first prompt waits for servers whose tools are declared to the model, so they are declared\n\t\t// in its first request, but not indefinitely: a slow or hanging server must not hold up the\n\t\t// prompt. Other servers are waited for when a script or search needs them (below).\n\t\tconst waitForDirectServers = async (ctx: ExtensionContext) => {\n\t\t\tif (waitedForStartup) return;\n\t\t\twaitedForStartup = true;\n\t\t\tconst ready = servers.flatMap((server) =>\n\t\t\t\tisEnabled(server) && hasDirectTools(server.entry) && server.ready ? [server.ready] : [],\n\t\t\t);\n\t\t\tif (ready.length === 0) return;\n\t\t\tlet timer: NodeJS.Timeout | undefined;\n\t\t\tconst finished = await Promise.race([\n\t\t\t\tPromise.all(ready).then(() => true),\n\t\t\t\tnew Promise<boolean>((resolve) => {\n\t\t\t\t\ttimer = setTimeout(() => resolve(false), startupWaitMs);\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tclearTimeout(timer);\n\t\t\tif (!finished) {\n\t\t\t\tctx.ui.notify(\"MCP servers are still connecting; their tools become available once connected.\", \"info\");\n\t\t\t}\n\t\t};\n\n\t\t// Every prompt lists the servers in the `mcp_servers` section as they are when it starts. Pi\n\t\t// appends the section to the conversation when it changed, for example after a server connected.\n\t\tpi.on(\"before_agent_start\", async (event, ctx) => {\n\t\t\tawait waitForDirectServers(ctx);\n\t\t\tconst { sections } = event.systemPromptOptions;\n\t\t\tconst section = renderServersSection(servers);\n\t\t\tif (section) sections[MCP_SERVERS_SECTION] = section;\n\t\t\telse delete sections[MCP_SERVERS_SECTION];\n\t\t});\n\n\t\t// A codemode script waits for the servers it names, or for every server when it searches or\n\t\t// enumerates tools, so their tools are registered before the script runs. tool_search and the\n\t\t// resource tools reach every server, so they wait for all of them.\n\t\tpi.on(\"tool_call\", async (event, ctx) => {\n\t\t\tconst tool = pi.getAllTools().find((candidate) => candidate.name === event.toolName);\n\t\t\tif (!tool) return;\n\t\t\tconst pendingServers = servers.filter(\n\t\t\t\t(server) => isEnabled(server) && server.connection?.state !== \"connected\" && server.ready,\n\t\t\t);\n\t\t\tif (pendingServers.length === 0) return;\n\t\t\tlet waiting: McpServer[] = [];\n\t\t\tif (isCodemodeTool(tool)) {\n\t\t\t\tconst { code } = event.input as { code?: unknown };\n\t\t\t\tconst source = typeof code === \"string\" ? code : \"\";\n\t\t\t\twaiting = pendingServers.filter((server) => scriptNeedsServer(source, server.entry.name));\n\t\t\t} else if (isToolSearchTool(tool) || RESOURCE_TOOL_NAMES.has(tool.name)) {\n\t\t\t\twaiting = pendingServers;\n\t\t\t}\n\t\t\tawait waitForServers(waiting, ctx.signal);\n\t\t});\n\n\t\t// Pick up sign-ins done outside the session, such as `pi mcp login` run by the agent.\n\t\tpi.on(\"turn_start\", async (_event, ctx) => {\n\t\t\tif (tokensAtSignIn.size > 0) await reconnectSignedIn(ctx);\n\t\t});\n\n\t\t// Servers registered or unregistered during the session connect or disconnect right away.\n\t\tpi.on(\"mcp_servers_change\", async (_event, ctx) => {\n\t\t\tif (!sessionActive) return;\n\t\t\tconst current = generation;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tconst next = new Map(registered.servers.map((server) => [server.entry.name, server]));\n\t\t\t// Unregistered servers and re-registered ones with a new config are dropped; the latter come back below.\n\t\t\tconst removed = servers.filter(\n\t\t\t\t(server) =>\n\t\t\t\t\tserver.entry.scope === \"extension\" &&\n\t\t\t\t\tnext.get(server.entry.name)?.registeredConfig !== server.registeredConfig,\n\t\t\t);\n\t\t\tservers = servers.filter((server) => !removed.includes(server));\n\t\t\tfor (const server of removed) hideTools(server.entry.name);\n\t\t\tconst added = registered.servers.filter((server) => !findServer(server.entry.name));\n\t\t\tservers.push(...added);\n\t\t\temitChange();\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tawait Promise.all(removed.map((server) => server.connection?.close()));\n\t\t\tconst connecting = added.filter(isEnabled);\n\t\t\tif (current !== generation || connecting.length === 0) return;\n\t\t\ttry {\n\t\t\t\tawait Promise.all(connecting.map((server) => startConnection(server, () => current === generation)));\n\t\t\t\tif (current !== generation) {\n\t\t\t\t\tawait Promise.all(connecting.map((server) => server.connection?.close()));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (current !== generation) return;\n\t\t\treportProblems(ctx, connecting);\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async () => {\n\t\t\tsessionActive = false;\n\t\t\tgeneration++;\n\t\t\tconst closing = connections();\n\t\t\tservers = [];\n\t\t\temitChange();\n\t\t\tawait Promise.all(closing.map((connection) => connection.close()));\n\t\t});\n\n\t\tpi.registerCommand(\"mcp\", {\n\t\t\tdescription: \"Manage MCP servers: sign in, reconnect, enable or disable, and change exposure\",\n\t\t\tgetArgumentCompletions: (prefix) => {\n\t\t\t\tconst [action, server, ...rest] = prefix.trimStart().split(/\\s+/);\n\t\t\t\tif (rest.length > 0) return null;\n\t\t\t\tif (server === undefined) {\n\t\t\t\t\treturn [\"login\", \"logout\", \"reconnect\"]\n\t\t\t\t\t\t.filter((item) => item.startsWith(action ?? \"\"))\n\t\t\t\t\t\t.map((item) => ({ value: `${item} `, label: item }));\n\t\t\t\t}\n\t\t\t\tif (action !== \"login\" && action !== \"logout\" && action !== \"reconnect\") return null;\n\t\t\t\tconst items = servers\n\t\t\t\t\t.filter((candidate) =>\n\t\t\t\t\t\taction === \"reconnect\" ? candidate.connection !== undefined : usesOAuth(candidate),\n\t\t\t\t\t)\n\t\t\t\t\t.filter((candidate) => candidate.entry.name.startsWith(server))\n\t\t\t\t\t.map((candidate) => ({\n\t\t\t\t\t\tvalue: `${action} ${candidate.entry.name}`,\n\t\t\t\t\t\tlabel: candidate.entry.name,\n\t\t\t\t\t\tdescription: describeState(candidate),\n\t\t\t\t\t}));\n\t\t\t\treturn items.length > 0 ? items : null;\n\t\t\t},\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tawait pending;\n\t\t\t\tconst [action, name, ...extra] = args.trim().split(/\\s+/).filter(Boolean);\n\t\t\t\tif (action === undefined) {\n\t\t\t\t\tif (ctx.mode === \"tui\") await showMcpManager(ctx, (ui) => manage(ui, ctx));\n\t\t\t\t\telse ctx.ui.notify(formatStatus(), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (extra.length > 0) {\n\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tswitch (action) {\n\t\t\t\t\tcase \"login\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (server) await loginCommand(server, ctx);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"logout\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst removed = await signOut(server);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tremoved\n\t\t\t\t\t\t\t\t? `Signed out of MCP server \"${server.entry.name}\".`\n\t\t\t\t\t\t\t\t: `No stored credentials for MCP server \"${server.entry.name}\".`,\n\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"reconnect\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, {\n\t\t\t\t\t\t\teligible: (candidate) => candidate.connection !== undefined,\n\t\t\t\t\t\t\tpreferred: (candidate) =>\n\t\t\t\t\t\t\t\tcandidate.connection?.state === \"failed\" || candidate.connection?.state === \"disconnected\",\n\t\t\t\t\t\t\tnone: \"No enabled MCP server to reconnect.\",\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst failure = await reconnect(server);\n\t\t\t\t\t\tif (failure) ctx.ui.notify(failure, \"error\");\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tensureDiscoveryActive(ctx);\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\t`Reconnected to MCP server \"${server.entry.name}\" (${describeState(server)}).`,\n\t\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n\nfunction defaultLoadConfig(ctx: ExtensionContext): LoadedMcpConfig {\n\treturn loadMcpConfig({ agentDir: getAgentDir(), cwd: ctx.cwd, projectTrusted: ctx.isProjectTrusted() });\n}\n\nexport default createMcpExtension();\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAG1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQ9C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EACN,kBAAkB,EAElB,aAAa,EAIb,qBAAqB,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,gCAAgC,EAChC,gCAAgC,EAChC,uBAAuB,EACvB,sBAAsB,GACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,sBAAsB,EAAuB,MAAM,YAAY,CAAC;AACrH,OAAO,EAA4B,cAAc,EAAE,MAAM,SAAS,CAAC;AA4BnE,MAAM,uBAAuB,GAAG,MAAM,CAAC;AAEvC,MAAM,mBAAmB,GAAwB,IAAI,GAAG,CAAC;IACxD,uBAAuB;IACvB,gCAAgC;IAChC,sBAAsB;CACtB,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C;wBACxC,IAAI,OAAO;4BAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;6BACxC,CAAC;4BACL,qBAAqB,CAAC,GAAG,CAAC,CAAC;4BAC3B,GAAG,CAAC,EAAE,CAAC,MAAM,CACZ,8BAA8B,MAAM,CAAC,KAAK,CAAC,IAAI,MAAM,aAAa,CAAC,MAAM,CAAC,IAAI,EAC9E,MAAM,CACN,CAAC;wBACH,CAAC;wBACD,OAAO;oBACR,CAAC;oBACD;wBACC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACtC,CAAC;YACF,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAqB;IAC/C,OAAO,aAAa,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,cAAc,EAAE,GAAG,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;AACzG,CAAC;AAED,eAAe,kBAAkB,EAAE,CAAC","sourcesContent":["/**\n * Built-in MCP integration.\n *\n * Connects the servers from `mcp.json` and the servers extensions register with\n * `pi.registerMcpServer()` when a session starts, and servers registered later right away. A server\n * in `mcp.json` takes precedence over a registered server of the same name. Connections run in the\n * background: the first prompt waits only for servers with `direct` tools, and codemode scripts,\n * `tool_search`, and the resource tools wait for the servers they need when they run. Tools are\n * registered as `mcp__<server>__<tool>`. By default (`\"exposure\": \"codemode\"`) the tools are only\n * callable from codemode scripts, which keeps MCP tools out of the model's tool declarations and\n * the codemode description: scripts find the tools with `searchTools()` and the server instructions\n * with `describeNamespace()`. The codemode tool is activated for that unless `autoEnableCodemode` is\n * false. `\"deferred\"` declares the tools to the model once the `tool_search` tool loads them, and\n * activates `tool_search` instead of codemode.\n * `\"exposure\": \"direct\"` declares them to the model right away, and `\"hidden\"` makes them\n * unreachable. `toolExposure` overrides the exposure of single tools. Servers with resources are\n * reached through Codex's `list_mcp_resources`, `list_mcp_resource_templates`, and\n * `read_mcp_resource` tools (resources.ts).\n *\n * Every call runs through pi's tool pipeline, so `tool_call`/`tool_result` hooks and permission\n * extensions apply to MCP tools the same way they do to built-in tools.\n *\n * Problems found at startup (config errors, failed connections, servers that need a sign-in) are\n * reported once. `/mcp` opens a manager to sign in, reconnect, enable or disable servers, and change\n * their exposure; the last two are saved to the `mcp.json` that defines the server, or apply to the\n * current session for registered servers.\n */\n\nimport { join, resolve } from \"node:path\";\nimport type { SelectItem } from \"@earendil-works/pi-tui\";\nimport type { TSchema } from \"typebox\";\nimport { getAgentDir } from \"../../config.ts\";\nimport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tToolDefinition,\n} from \"../../core/extensions/types.ts\";\nimport { mcpNamespace } from \"../../core/mcp-servers.ts\";\nimport type { ModelRegistry } from \"../../core/model-registry.ts\";\nimport { openBrowser } from \"../../utils/open-browser.ts\";\nimport { CODEMODE_TOOL_NAME, isCodemodeTool } from \"../codemode/tool.ts\";\nimport { isToolSearchTool, TOOL_SEARCH_TOOL_NAME } from \"../tool-search/tool.ts\";\nimport {\n\tgetMcpToolExposure,\n\ttype LoadedMcpConfig,\n\tloadMcpConfig,\n\ttype McpExposure,\n\ttype McpServerConfigPatch,\n\ttype McpServerEntry,\n\tupdateMcpServerConfig,\n} from \"./config.ts\";\nimport type { McpOAuthCredentialStore, McpSignInPrompt } from \"./oauth.ts\";\nimport {\n\tcreateMcpResourceToolDefinitions,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tLIST_MCP_RESOURCES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n} from \"./resources.ts\";\nimport { loadMcpRuntime } from \"./runtime.lazy.ts\";\nimport type * as McpRuntime from \"./runtime.ts\";\nimport type { McpServerConnection, McpServerLog, McpTransportFactory } from \"./runtime.ts\";\nimport { createMcpToolDefinition, createMcpToolName, createMcpToolRenderers, type McpToolDetails } from \"./tools.ts\";\nimport { type McpMenu, type McpUi, showMcpManager } from \"./ui.ts\";\n\nexport type { McpTransportFactory } from \"./runtime.ts\";\n\nexport interface McpExtensionOptions {\n\t/** Defaults to reading `mcp.json` from the agent directory and the trusted project. */\n\tloadConfig?: (ctx: ExtensionContext) => LoadedMcpConfig;\n\t/** Defaults to stdio and streamable HTTP transports built from the server config. */\n\tcreateTransport?: McpTransportFactory;\n\t/** Defaults to `mcp-auth.json` in the agent directory. */\n\tcredentials?: McpOAuthCredentialStore;\n\t/** File server log messages are appended to. Defaults to `mcp.log` in the agent directory. */\n\tlogPath?: string;\n\t/** Opens the OAuth authorization URL. Defaults to the platform browser. */\n\topenUrl?: (url: string) => void;\n\t/**\n\t * Saves `/mcp` changes to the server's config file: its project `override` when set, else its\n\t * `source`. Defaults to editing that `mcp.json`.\n\t */\n\tupdateConfig?: (entry: McpServerEntry, patch: McpServerConfigPatch) => void;\n\t/**\n\t * How long the first prompt waits for servers with `direct` tools that are still connecting at\n\t * startup, in milliseconds. Their tools become available when they connect. Other servers are\n\t * waited for when a script or search needs them. Default: 10000.\n\t */\n\tstartupWaitMs?: number;\n}\n\nconst DEFAULT_STARTUP_WAIT_MS = 10_000;\n\nconst RESOURCE_TOOL_NAMES: ReadonlySet<string> = new Set([\n\tLIST_MCP_RESOURCES_TOOL,\n\tLIST_MCP_RESOURCE_TEMPLATES_TOOL,\n\tREAD_MCP_RESOURCE_TOOL,\n]);\n\n/** A configured server. Disabled servers have no connection. */\ninterface McpServer {\n\tentry: McpServerEntry;\n\tconnection?: McpServerConnection;\n\t/** For servers extensions registered: the config as registered, to detect re-registrations. */\n\tregisteredConfig?: string;\n\t/** Result of the last `/mcp` action that failed, shown in the manager. */\n\tmessage?: string;\n\t/** Settles when the connection started for the server connected or failed. */\n\tready?: Promise<void>;\n}\n\nconst EXPOSURE_DESCRIPTIONS: Record<Exclude<McpExposure, \"hidden\">, string> = {\n\tcodemode: \"called from codemode scripts, which find them with searchTools()\",\n\tdeferred: \"not declared until tool_search loads them, then called directly; no codemode needed\",\n\tdirect: \"declared to the model like built-in tools\",\n};\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction firstLine(text: string): string {\n\treturn text.split(\"\\n\", 1)[0] ?? \"\";\n}\n\nfunction isEnabled(server: Pick<McpServer, \"entry\">): boolean {\n\treturn server.entry.config.enabled !== false;\n}\n\nfunction exposureOf(entry: McpServerEntry): McpExposure {\n\treturn entry.config.exposure ?? \"codemode\";\n}\n\n/** Exposures the server's tools can have, known from its config before it connects. */\nfunction configuredExposures(entry: McpServerEntry): Set<McpExposure> {\n\treturn new Set([exposureOf(entry), ...Object.values(entry.config.toolExposure ?? {})]);\n}\n\n/** Whether some of the server's tools are declared to the model, so the first prompt waits for them. */\nfunction hasDirectTools(entry: McpServerEntry): boolean {\n\treturn configuredExposures(entry).has(\"direct\");\n}\n\n/** Whether some of the server's tools are reached through codemode or tool_search. */\nfunction hasIndirectTools(entry: McpServerEntry): boolean {\n\tconst exposures = configuredExposures(entry);\n\treturn exposures.has(\"codemode\") || exposures.has(\"deferred\");\n}\n\n/** Name of the system prompt section that lists the servers whose tools are not declared. */\nexport const MCP_SERVERS_SECTION = \"mcp_servers\";\n/** Characters of a server description in the section, as Codex allows for deferred namespaces. */\nconst MAX_SERVER_DESCRIPTION_CHARS = 250;\n/**\n * Characters of the whole section. Descriptions shrink to fit; when the server lines alone do not\n * fit, the last servers are left out and counted in a closing line.\n */\nexport const MAX_SERVERS_SECTION_CHARS = 4096;\n\n/** The section's first line. It explains only the ways of reaching tools that the listed servers use. */\nfunction serversSectionIntro(reaches: ReadonlySet<string>): string {\n\tlet intro = \"MCP servers whose tools are not declared to you.\";\n\tif (reaches.has(\"codemode\")) intro += \" Call the tools of `codemode` servers from codemode scripts.\";\n\tif (reaches.has(\"tool_search\")) intro += \" Load the tools of `tool_search` servers with `tool_search`.\";\n\treturn intro;\n}\n\nfunction truncate(text: string, max: number): string {\n\tif (text.length <= max) return text;\n\treturn max <= 1 ? \"\" : `${text.slice(0, max - 1).trimEnd()}…`;\n}\n\n/** What the `mcp_servers` section needs of a server. */\nexport interface McpServerListing {\n\tentry: McpServerEntry;\n\tconnection?: { instructions?: string };\n}\n\n/** First line of the configured description, or of the server instructions once connected. */\nfunction serverSummary(server: McpServerListing): string {\n\tconst text = server.entry.config.description?.trim() || server.connection?.instructions || \"\";\n\treturn (text.split(\"\\n\", 1)[0] ?? \"\").trim();\n}\n\n/**\n * The `mcp_servers` section: every enabled server with codemode or deferred tools, with how its\n * tools are reached and a one-line summary. The model learns of the servers from it, since neither\n * codemode nor tool_search lists them. Undefined when there are no such servers.\n */\nexport function renderServersSection(servers: readonly McpServerListing[]): string | undefined {\n\tconst listed = servers\n\t\t.filter((server) => isEnabled(server) && hasIndirectTools(server.entry))\n\t\t.sort((a, b) => a.entry.name.localeCompare(b.entry.name));\n\tif (listed.length === 0) return undefined;\n\tconst reaches = listed.map((server) =>\n\t\tconfiguredExposures(server.entry).has(\"codemode\") ? \"codemode\" : \"tool_search\",\n\t);\n\tconst intro = serversSectionIntro(new Set(reaches));\n\tconst heads = listed.map((server, index) => `- ${mcpNamespace(server.entry.name)} (${reaches[index]})`);\n\tconst omitted = (count: number) =>\n\t\tcount > 0 ? [`- … ${count} more server${count === 1 ? \"\" : \"s\"}; find their tools with searchTools()`] : [];\n\t// Characters of the intro, the first `kept` server lines without descriptions, and the omission line.\n\tconst size = (kept: number) => [intro, ...heads.slice(0, kept), ...omitted(listed.length - kept)].join(\"\\n\").length;\n\tlet kept = listed.length;\n\twhile (kept > 0 && size(kept) > MAX_SERVERS_SECTION_CHARS) kept--;\n\t// Each description also takes a \": \" separator.\n\tconst perServer =\n\t\tkept === 0\n\t\t\t? 0\n\t\t\t: Math.min(MAX_SERVER_DESCRIPTION_CHARS, Math.floor((MAX_SERVERS_SECTION_CHARS - size(kept)) / kept) - 2);\n\tconst lines = listed.slice(0, kept).map((server, index) => {\n\t\tconst summary = perServer > 0 ? truncate(serverSummary(server), perServer) : \"\";\n\t\treturn summary ? `${heads[index]}: ${summary}` : heads[index];\n\t});\n\treturn [intro, ...lines, ...omitted(listed.length - kept)].join(\"\\n\");\n}\n\n/**\n * Whether a codemode script needs the server: it names the server's namespace, or searches,\n * enumerates, or describes tools or namespaces, which may name the server in other forms.\n */\nfunction scriptNeedsServer(code: string, server: string): boolean {\n\tif (/\\b(searchTools|describeNamespace|describeTool|ALL_TOOLS)\\b/.test(code)) return true;\n\treturn code.includes(mcpNamespace(server));\n}\n\n/** Short state for lists and the startup report. `withError` appends the first line of a failure. */\nfunction describeState(server: McpServer, withError = true): string {\n\tif (!isEnabled(server)) return \"disabled\";\n\tconst connection = server.connection;\n\tif (!connection) return \"starting\";\n\tswitch (connection.state) {\n\t\tcase \"needs-auth\":\n\t\t\treturn \"needs sign-in\";\n\t\tcase \"failed\":\n\t\t\treturn withError ? `failed: ${firstLine(connection.error ?? \"unknown error\")}` : \"failed\";\n\t\tcase \"connected\": {\n\t\t\tconst { tools, resources } = connection;\n\t\t\tconst count = resources.length;\n\t\t\tconst resourceCount = count > 0 ? ` · ${count} resource${count === 1 ? \"\" : \"s\"}` : \"\";\n\t\t\treturn `connected · ${tools.length} tool${tools.length === 1 ? \"\" : \"s\"}${resourceCount}`;\n\t\t}\n\t\tcase \"connecting\":\n\t\t\treturn \"connecting…\";\n\t\tdefault:\n\t\t\treturn connection.state;\n\t}\n}\n\n/** Servers that need the user first. */\nfunction attentionRank(server: McpServer): number {\n\tif (!isEnabled(server)) return 5;\n\tswitch (server.connection?.state) {\n\t\tcase \"needs-auth\":\n\t\t\treturn 0;\n\t\tcase \"failed\":\n\t\t\treturn 1;\n\t\tcase \"disconnected\":\n\t\t\treturn 2;\n\t\tcase \"connected\":\n\t\t\treturn 4;\n\t\tdefault:\n\t\t\treturn 3;\n\t}\n}\n\nfunction describeTransport(entry: McpServerEntry): string {\n\tconst { config } = entry;\n\tif (\"url\" in config) return config.url;\n\treturn [config.command, ...(config.args ?? [])].join(\" \");\n}\n\nconst MCP_USAGE = \"Usage: /mcp, /mcp login [server], /mcp logout [server], /mcp reconnect [server]\";\n\nexport function createMcpExtension(options: McpExtensionOptions = {}): ExtensionFactory {\n\treturn (pi: ExtensionAPI) => {\n\t\tlet servers: McpServer[] = [];\n\t\t/** Servers from `mcp.json`, which take precedence over registered servers of the same name. */\n\t\tlet configuredEntries: McpServerEntry[] = [];\n\t\tlet configErrors: string[] = [];\n\t\t/** The trusted project's `mcp.json`, where `/mcp` saves project overrides of global servers. */\n\t\tlet projectConfig: string | undefined;\n\t\t/** Registered servers that `mcp.json` overrides, shown in `/mcp`. */\n\t\tlet overridden: string[] = [];\n\t\t/** Between session_start and session_shutdown. Registrations before that are read on session_start. */\n\t\tlet sessionActive = false;\n\t\tlet autoEnableCodemode = true;\n\t\t/** Whether the \"codemode tools unreachable\" warning was shown since the session started. */\n\t\tlet warnedUnreachable = false;\n\t\tlet pending: Promise<unknown> | undefined;\n\t\t/** Whether a prompt already waited for the startup connections since the session started. */\n\t\tlet waitedForStartup = false;\n\t\tconst startupWaitMs = options.startupWaitMs ?? DEFAULT_STARTUP_WAIT_MS;\n\t\t/** Bumped on every session start and shutdown so a runtime load that resolves late is dropped. */\n\t\tlet generation = 0;\n\t\t/** Working directory of the session, for stdio servers. */\n\t\tlet sessionCwd = process.cwd();\n\t\tlet credentials = options.credentials;\n\t\t/** The session's model registry, which resolves `auth.provider` tokens. */\n\t\tlet modelRegistry: ModelRegistry | undefined;\n\t\tlet serverLog: McpServerLog | undefined;\n\t\tconst openUrl = options.openUrl ?? openBrowser;\n\t\tconst updateConfig =\n\t\t\toptions.updateConfig ??\n\t\t\t((entry, patch) =>\n\t\t\t\tupdateMcpServerConfig(entry.override ?? entry.source, entry.name, patch, {\n\t\t\t\t\toverride: entry.override !== undefined,\n\t\t\t\t}));\n\n\t\tconst listeners = new Set<() => void>();\n\t\tconst emitChange = () => {\n\t\t\tfor (const listener of listeners) listener();\n\t\t};\n\t\tconst subscribe = (listener: () => void) => {\n\t\t\tlisteners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete(listener);\n\t\t\t};\n\t\t};\n\n\t\tconst connections = () => servers.flatMap((server) => (server.connection ? [server.connection] : []));\n\t\tconst findServer = (name: string) => servers.find((server) => server.entry.name === name);\n\n\t\t/** Servers extensions registered, except names `mcp.json` defines, which take precedence. */\n\t\tconst registeredServers = (): { servers: McpServer[]; overridden: string[] } => {\n\t\t\tconst registered: McpServer[] = [];\n\t\t\tconst overriddenNames: string[] = [];\n\t\t\tfor (const { name, config, extensionPath } of pi.getMcpServers()) {\n\t\t\t\tconst configured = configuredEntries.find((entry) => mcpNamespace(entry.name) === mcpNamespace(name));\n\t\t\t\tif (configured) {\n\t\t\t\t\toverriddenNames.push(\n\t\t\t\t\t\t`\"${name}\" registered by ${extensionPath} is overridden by \"${configured.name}\" in ${configured.source}`,\n\t\t\t\t\t);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tregistered.push({\n\t\t\t\t\tentry: { name, config, source: extensionPath, scope: \"extension\" },\n\t\t\t\t\tregisteredConfig: JSON.stringify(config),\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn { servers: registered, overridden: overriddenNames };\n\t\t};\n\n\t\tconst getCredentials = (runtime: typeof McpRuntime): McpOAuthCredentialStore => {\n\t\t\tcredentials ??= new runtime.McpOAuthCredentialStore();\n\t\t\treturn credentials;\n\t\t};\n\n\t\tconst getServerLog = (runtime: typeof McpRuntime): McpServerLog => {\n\t\t\tserverLog ??= new runtime.McpServerLog(options.logPath ?? join(getAgentDir(), \"mcp.log\"));\n\t\t\treturn serverLog;\n\t\t};\n\n\t\t/** pi tool name to the `<server>\\0<tool>` it was assigned to, so names stay unique and stable. */\n\t\tconst toolOwners = new Map<string, string>();\n\t\t/** Tool names currently offered by each server. */\n\t\tconst serverTools = new Map<string, Set<string>>();\n\t\t/** Last definition registered under each tool name, to re-register withdrawn tools as hidden. */\n\t\tconst definitions = new Map<string, ToolDefinition<TSchema, McpToolDetails>>();\n\n\t\t// A resumed session renders calls to MCP tools before their server connected, if it ever does.\n\t\tpi.registerToolRenderer((toolName, next) => {\n\t\t\tconst match = /^mcp__(.+?)__(.+)$/.exec(toolName);\n\t\t\treturn next() ?? (match ? createMcpToolRenderers(`${match[1]}/${match[2]}`) : undefined);\n\t\t});\n\n\t\tconst registerTools = (connection: McpServerConnection) => {\n\t\t\tconst server = connection.entry.name;\n\t\t\tconst entry = findServer(server)?.entry ?? connection.entry;\n\t\t\tconst description = entry.config.description?.trim();\n\t\t\tconst namespace = {\n\t\t\t\tname: mcpNamespace(server),\n\t\t\t\t...(description ? { description } : {}),\n\t\t\t\t...(connection.instructions ? { instructions: connection.instructions } : {}),\n\t\t\t};\n\t\t\tconst previous = serverTools.get(server) ?? new Set<string>();\n\t\t\tconst current = new Set<string>();\n\t\t\t// Like Codex, all tools whose names sanitize to the same name get the hash suffix, so which\n\t\t\t// one would keep the plain name does not depend on the order of the list.\n\t\t\tconst plain = [...new Set(connection.tools.map((tool) => tool.name))].map((tool) =>\n\t\t\t\tcreateMcpToolName(server, tool),\n\t\t\t);\n\t\t\tconst assignName = (tool: string, owner: string) => {\n\t\t\t\tconst name = createMcpToolName(server, tool, (candidate) => {\n\t\t\t\t\tconst existing = toolOwners.get(candidate);\n\t\t\t\t\treturn (\n\t\t\t\t\t\t(existing !== undefined && existing !== owner) ||\n\t\t\t\t\t\tcurrent.has(candidate) ||\n\t\t\t\t\t\tplain.indexOf(candidate) !== plain.lastIndexOf(candidate)\n\t\t\t\t\t);\n\t\t\t\t});\n\t\t\t\ttoolOwners.set(name, owner);\n\t\t\t\tcurrent.add(name);\n\t\t\t\treturn name;\n\t\t\t};\n\t\t\tfor (const tool of connection.tools) {\n\t\t\t\tconst definition = createMcpToolDefinition({\n\t\t\t\t\tserver,\n\t\t\t\t\ttool,\n\t\t\t\t\tname: assignName(tool.name, `${server}\\0${tool.name}`),\n\t\t\t\t\texposure: getMcpToolExposure(entry.config, tool.name),\n\t\t\t\t\tnamespace,\n\t\t\t\t\ttimeoutMs: connection.timeoutMs,\n\t\t\t\t\tgetClient: async () => connection,\n\t\t\t\t\treadableResources: () => resourceServers().includes(connection),\n\t\t\t\t});\n\t\t\t\tdefinitions.set(definition.name, definition);\n\t\t\t\tpi.registerTool(definition);\n\t\t\t}\n\t\t\tserverTools.set(server, current);\n\t\t\t// Tools cannot be unregistered, so tools the server dropped are re-registered as hidden. When\n\t\t\t// the server offers them again they are registered with their configured exposure above.\n\t\t\tfor (const name of previous) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (!current.has(name) && definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Make a disabled server's tools unreachable. */\n\t\tconst hideTools = (server: string) => {\n\t\t\tfor (const name of serverTools.get(server) ?? []) {\n\t\t\t\tconst definition = definitions.get(name);\n\t\t\t\tif (definition) pi.registerTool({ ...definition, exposure: \"hidden\" });\n\t\t\t}\n\t\t\tserverTools.set(server, new Set());\n\t\t\tsyncResourceTools();\n\t\t};\n\n\t\t/** Enabled servers with resources whose exposure is not `hidden`, which the resource tools reach. */\n\t\tconst serversWithResources = (): McpServer[] =>\n\t\t\tservers.filter(\n\t\t\t\t(server) => server.connection?.hasResources && isEnabled(server) && exposureOf(server.entry) !== \"hidden\",\n\t\t\t);\n\t\tconst resourceServers = (): McpServerConnection[] =>\n\t\t\tserversWithResources().flatMap((server) => (server.connection ? [server.connection] : []));\n\n\t\t/** Exposure the resource tools were last registered with; undefined until a server has resources. */\n\t\tlet resourceToolsExposure: McpExposure | undefined;\n\t\t/**\n\t\t * Register the resource tools with the widest exposure of the servers they reach: `direct` when\n\t\t * one of them is direct, and so on. They are hidden when no server has resources.\n\t\t */\n\t\tconst syncResourceTools = () => {\n\t\t\tconst exposures = new Set(serversWithResources().map((server) => exposureOf(server.entry)));\n\t\t\tconst exposure = ([\"direct\", \"codemode\", \"deferred\"] as const).find((candidate) => exposures.has(candidate));\n\t\t\tconst next = exposure ?? \"hidden\";\n\t\t\tif (next === resourceToolsExposure || (resourceToolsExposure === undefined && next === \"hidden\")) return;\n\t\t\tconst wasDirect = resourceToolsExposure === \"direct\";\n\t\t\tresourceToolsExposure = next;\n\t\t\tconst resourceDefinitions = createMcpResourceToolDefinitions({ exposure: next, servers: resourceServers });\n\t\t\tfor (const definition of resourceDefinitions) pi.registerTool(definition);\n\t\t\tif (wasDirect) {\n\t\t\t\tconst names = new Set(resourceDefinitions.map((definition) => definition.name));\n\t\t\t\tpi.setActiveTools(pi.getActiveTools().filter((name) => !names.has(name)));\n\t\t\t}\n\t\t};\n\n\t\t/**\n\t\t * Tools that are not declared to the model are reached through the codemode tool (scripts call\n\t\t * them) or the tool_search tool (it declares them). Either reaches every such tool. Activate the\n\t\t * one the tools' exposure asks for: codemode for `codemode` unless `autoEnableCodemode` is false,\n\t\t * tool_search for `deferred`.\n\t\t */\n\t\tconst ensureDiscoveryActive = (ctx: ExtensionContext) => {\n\t\t\t// From the config, so the tool is active before the servers connect. Resource tools share\n\t\t\t// their server's exposure.\n\t\t\tconst exposures = new Set<McpExposure>();\n\t\t\tfor (const server of servers) {\n\t\t\t\tif (isEnabled(server)) for (const exposure of configuredExposures(server.entry)) exposures.add(exposure);\n\t\t\t}\n\t\t\tconst needsCodemode = exposures.has(\"codemode\");\n\t\t\tconst needsToolSearch = exposures.has(\"deferred\");\n\t\t\tif (!needsCodemode && !needsToolSearch) return;\n\t\t\t// Other extensions' tools of the same names cannot reach MCP tools, so never activate them.\n\t\t\tconst tools = pi.getAllTools();\n\t\t\tconst hasCodemode = tools.some(isCodemodeTool);\n\t\t\tconst hasToolSearch = tools.some(isToolSearchTool);\n\t\t\tconst active = pi.getActiveTools();\n\t\t\tconst activate: string[] = [];\n\t\t\tif (needsCodemode && hasCodemode && autoEnableCodemode && !active.includes(CODEMODE_TOOL_NAME)) {\n\t\t\t\tactivate.push(CODEMODE_TOOL_NAME);\n\t\t\t}\n\t\t\tif (needsToolSearch && hasToolSearch && !active.includes(TOOL_SEARCH_TOOL_NAME)) {\n\t\t\t\tactivate.push(TOOL_SEARCH_TOOL_NAME);\n\t\t\t}\n\t\t\tif (activate.length > 0) pi.setActiveTools([...active, ...activate]);\n\t\t\tconst reachable = [...active, ...activate];\n\t\t\tif (hasCodemode && reachable.includes(CODEMODE_TOOL_NAME)) return;\n\t\t\tif (hasToolSearch && reachable.includes(TOOL_SEARCH_TOOL_NAME)) return;\n\t\t\tif (warnedUnreachable) return;\n\t\t\twarnedUnreachable = true;\n\t\t\tconst reason = needsCodemode && hasCodemode && !autoEnableCodemode ? \" (autoEnableCodemode is false)\" : \"\";\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP tools are only reachable from the codemode or tool_search tool, but neither is active${reason}; they cannot be called.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/**\n\t\t * Stored tokens of servers waiting for a sign-in, as they were when the sign-in was needed.\n\t\t * `pi mcp login` in another process (for example run by the agent) changes them.\n\t\t */\n\t\tconst tokensAtSignIn = new Map<McpServerConnection, string>();\n\t\tconst storedTokens = (connection: McpServerConnection): string => {\n\t\t\tconst url = connection.oauthUrl;\n\t\t\treturn url && credentials ? JSON.stringify(credentials.tokens(connection.name, url) ?? null) : \"null\";\n\t\t};\n\t\tconst onConnectionChange = (connection: McpServerConnection) => {\n\t\t\tif (connection.state !== \"needs-auth\") tokensAtSignIn.delete(connection);\n\t\t\telse if (!tokensAtSignIn.has(connection)) tokensAtSignIn.set(connection, storedTokens(connection));\n\t\t\temitChange();\n\t\t};\n\t\t/** Reconnect servers that need a sign-in when their credentials were stored since. */\n\t\tconst reconnectSignedIn = async (ctx: ExtensionContext) => {\n\t\t\tconst signedIn = [...tokensAtSignIn].filter(([connection, tokens]) => storedTokens(connection) !== tokens);\n\t\t\tif (signedIn.length === 0) return;\n\t\t\tfor (const [connection] of signedIn) tokensAtSignIn.delete(connection);\n\t\t\tawait Promise.allSettled(signedIn.map(([connection]) => connection.reconnect()));\n\t\t\tensureDiscoveryActive(ctx);\n\t\t};\n\n\t\t/** Create the server's connection, loading the MCP runtime on first use. */\n\t\tconst createConnection = async (server: McpServer): Promise<McpServerConnection> => {\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\tconst connection = new runtime.McpServerConnection({\n\t\t\t\tentry: server.entry,\n\t\t\t\tcwd: sessionCwd,\n\t\t\t\tcreateTransport: options.createTransport ?? runtime.createDefaultTransport,\n\t\t\t\tcredentials: getCredentials(runtime),\n\t\t\t\tproviderToken: async (provider) => modelRegistry?.getApiKeyForProvider(provider),\n\t\t\t\tlog: getServerLog(runtime),\n\t\t\t\tonTools: registerTools,\n\t\t\t\tonChange: onConnectionChange,\n\t\t\t});\n\t\t\tserver.connection = connection;\n\t\t\temitChange();\n\t\t\treturn connection;\n\t\t};\n\n\t\t/**\n\t\t * Connect the server in the background. `server.ready` settles when it connected or failed;\n\t\t * failures show in its state. It starts after `after`; `isCurrent` stops it when the session ended\n\t\t * meanwhile. The returned promise rejects when the MCP runtime cannot be loaded.\n\t\t */\n\t\tconst startConnection = (\n\t\t\tserver: McpServer,\n\t\t\tisCurrent: () => boolean,\n\t\t\tafter?: Promise<unknown>,\n\t\t): Promise<void> => {\n\t\t\tconst ready = (async () => {\n\t\t\t\tawait after;\n\t\t\t\tif (!isCurrent()) return;\n\t\t\t\tconst connection = await createConnection(server);\n\t\t\t\tif (!isCurrent()) return;\n\t\t\t\tawait connection.getClient().catch(() => undefined);\n\t\t\t})();\n\t\t\tserver.ready = ready.catch(() => undefined);\n\t\t\treturn ready;\n\t\t};\n\n\t\t/** Wait for servers still connecting, until they settle or `signal` aborts. */\n\t\tconst waitForServers = async (waiting: readonly McpServer[], signal: AbortSignal | undefined) => {\n\t\t\tconst ready = waiting.flatMap((server) => (server.ready ? [server.ready] : []));\n\t\t\tif (ready.length === 0 || signal?.aborted) return;\n\t\t\tlet onAbort: (() => void) | undefined;\n\t\t\tawait Promise.race([\n\t\t\t\tPromise.all(ready),\n\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\tonAbort = () => resolve();\n\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tif (onAbort) signal?.removeEventListener(\"abort\", onAbort);\n\t\t};\n\n\t\t/**\n\t\t * One message for everything that needs the user after startup, or only for `only`, servers\n\t\t * that connected later.\n\t\t */\n\t\tconst reportProblems = (ctx: ExtensionContext, only?: readonly McpServer[]) => {\n\t\t\tconst lines = only ? [] : configErrors.map((error) => `config: ${error}`);\n\t\t\tfor (const server of only ?? servers) {\n\t\t\t\tconst state = server.connection?.state;\n\t\t\t\tif (state === \"needs-auth\" || state === \"failed\")\n\t\t\t\t\tlines.push(`${server.entry.name}: ${describeState(server)}`);\n\t\t\t}\n\t\t\tif (lines.length === 0) return;\n\t\t\tctx.ui.notify(\n\t\t\t\t`MCP servers need attention:\\n${lines.map((line) => ` ${line}`).join(\"\\n\")}\\nRun /mcp to fix.`,\n\t\t\t\t\"warning\",\n\t\t\t);\n\t\t};\n\n\t\t/**\n\t\t * Save a config change; returns an error message when the file could not be updated. Changes to\n\t\t * registered servers only apply to the current session. `inProject` adds a project override.\n\t\t */\n\t\tconst saveConfig = (server: McpServer, patch: McpServerConfigPatch, inProject = false): string | undefined => {\n\t\t\tconst override = inProject ? projectConfig : server.entry.override;\n\t\t\tconst entry = override ? { ...server.entry, override } : server.entry;\n\t\t\tif (entry.scope !== \"extension\") {\n\t\t\t\ttry {\n\t\t\t\t\tupdateConfig(entry, patch);\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn `Could not update ${entry.override ?? entry.source}: ${errorMessage(error)}`;\n\t\t\t\t}\n\t\t\t}\n\t\t\tserver.entry = { ...entry, config: { ...entry.config, ...patch } };\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst signIn = async (server: McpServer, prompt: McpSignInPrompt): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return `MCP server \"${server.entry.name}\" does not use OAuth.`;\n\t\t\tconst runtime = await loadMcpRuntime();\n\t\t\ttry {\n\t\t\t\tawait runtime.signInMcpServer({\n\t\t\t\t\tserverUrl: url,\n\t\t\t\t\tstore: getCredentials(runtime).forServer(server.entry.name, url),\n\t\t\t\t\tsettings: connection.oauthSettings(),\n\t\t\t\t\tchallenge: connection.challenge,\n\t\t\t\t\tprompt,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof runtime.McpSignInCancelledError) return \"Sign-in cancelled.\";\n\t\t\t\treturn `Sign-in failed: ${errorMessage(error)}`;\n\t\t\t}\n\t\t\t// The challenge that asked for this sign-in (for example for more scope) is answered.\n\t\t\tconnection.challenge = undefined;\n\t\t\ttry {\n\t\t\t\tawait connection.reconnect();\n\t\t\t} catch (error) {\n\t\t\t\treturn `Signed in, but ${errorMessage(error)}`;\n\t\t\t}\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst signOut = async (server: McpServer): Promise<boolean> => {\n\t\t\tconst connection = server.connection;\n\t\t\tconst url = connection?.oauthUrl;\n\t\t\tif (!connection || !url) return false;\n\t\t\tconst removed = getCredentials(await loadMcpRuntime()).remove(server.entry.name, url);\n\t\t\tawait connection.signOut();\n\t\t\treturn removed;\n\t\t};\n\n\t\tconst reconnect = async (server: McpServer): Promise<string | undefined> => {\n\t\t\tconst connection = server.connection;\n\t\t\tif (!connection) return `MCP server \"${server.entry.name}\" is disabled.`;\n\t\t\ttry {\n\t\t\t\tawait connection.reconnect();\n\t\t\t\treturn undefined;\n\t\t\t} catch (error) {\n\t\t\t\treturn errorMessage(error);\n\t\t\t}\n\t\t};\n\n\t\t/** Returns an error message when the config could not be saved; connection errors show in the state. */\n\t\tconst setEnabled = async (\n\t\t\tserver: McpServer,\n\t\t\tenabled: boolean,\n\t\t\tinProject = false,\n\t\t): Promise<string | undefined> => {\n\t\t\tconst failed = saveConfig(server, { enabled }, inProject);\n\t\t\tif (failed) return failed;\n\t\t\tif (!enabled) {\n\t\t\t\tconst connection = server.connection;\n\t\t\t\tserver.connection = undefined;\n\t\t\t\thideTools(server.entry.name);\n\t\t\t\temitChange();\n\t\t\t\tawait connection?.close();\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tawait startConnection(server, () => true);\n\t\t\treturn undefined;\n\t\t};\n\n\t\tconst setExposure = (server: McpServer, exposure: McpExposure): string | undefined => {\n\t\t\tconst failed = saveConfig(server, { exposure });\n\t\t\tif (failed) return failed;\n\t\t\tif (server.connection?.state === \"connected\") registerTools(server.connection);\n\t\t\tsyncResourceTools();\n\t\t\t// Tools no longer exposed directly leave the declared set; direct tools are activated on registration.\n\t\t\tconst indirect = new Set(\n\t\t\t\tpi\n\t\t\t\t\t.getAllTools()\n\t\t\t\t\t.filter((tool) => tool.exposure !== \"direct\")\n\t\t\t\t\t.map((tool) => tool.name),\n\t\t\t);\n\t\t\tconst tools = serverTools.get(server.entry.name) ?? new Set<string>();\n\t\t\tpi.setActiveTools(pi.getActiveTools().filter((name) => !tools.has(name) || !indirect.has(name)));\n\t\t\temitChange();\n\t\t\treturn undefined;\n\t\t};\n\n\t\t// ---------------------------------------------------------------------------------------\n\t\t// Manager (`/mcp` in the TUI)\n\t\t// ---------------------------------------------------------------------------------------\n\n\t\tconst notices = () => [\n\t\t\t...configErrors.map((error) => `config: ${error}`),\n\t\t\t...overridden.map((line) => `overridden: ${line}`),\n\t\t];\n\n\t\tconst serversMenu = (): McpMenu => ({\n\t\t\ttitle: \"MCP servers\",\n\t\t\terror: notices().join(\"\\n\") || undefined,\n\t\t\titems: [...servers]\n\t\t\t\t.sort((a, b) => attentionRank(a) - attentionRank(b) || a.entry.name.localeCompare(b.entry.name))\n\t\t\t\t.map((server) => ({\n\t\t\t\t\tvalue: server.entry.name,\n\t\t\t\t\tlabel: server.entry.name,\n\t\t\t\t\tdescription: `${describeState(server)} · ${exposureOf(server.entry)} · ${server.entry.override ? \"global, project override\" : (server.entry.scope ?? server.entry.source)}`,\n\t\t\t\t})),\n\t\t\tempty: `No MCP servers configured. Add them to ${resolve(getAgentDir(), \"mcp.json\")} or .pi/mcp.json.`,\n\t\t\tconfirmLabel: \"manage\",\n\t\t\tcancelLabel: \"close\",\n\t\t});\n\n\t\tconst serverMenu = (name: string): McpMenu => {\n\t\t\tconst server = findServer(name);\n\t\t\tif (!server) {\n\t\t\t\treturn {\n\t\t\t\t\ttitle: name,\n\t\t\t\t\titems: [],\n\t\t\t\t\tempty: \"This server is no longer configured.\",\n\t\t\t\t\tconfirmLabel: \"\",\n\t\t\t\t\tcancelLabel: \"back\",\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst { entry, connection } = server;\n\t\t\tconst saved =\n\t\t\t\tentry.scope === \"extension\"\n\t\t\t\t\t? \"for this session\"\n\t\t\t\t\t: entry.override\n\t\t\t\t\t\t? \"saved to the project mcp.json\"\n\t\t\t\t\t\t: entry.scope\n\t\t\t\t\t\t\t? `saved to the ${entry.scope} mcp.json`\n\t\t\t\t\t\t\t: \"saved to mcp.json\";\n\t\t\t// Global servers without an override can be turned on or off for the trusted project alone.\n\t\t\tconst inProject = entry.scope === \"global\" && !entry.override && projectConfig !== undefined;\n\t\t\tconst inProjectSaved = \"saved to the project mcp.json\";\n\t\t\tconst items: SelectItem[] = [];\n\t\t\tif (!isEnabled(server)) {\n\t\t\t\titems.push({ value: \"enable\", label: \"Enable\", description: saved });\n\t\t\t\tif (inProject) {\n\t\t\t\t\titems.push({ value: \"enable-project\", label: \"Enable in this project\", description: inProjectSaved });\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst state = connection?.state;\n\t\t\t\tif (state === \"needs-auth\")\n\t\t\t\t\titems.push({ value: \"signin\", label: \"Sign in\", description: \"opens the browser\" });\n\t\t\t\tif (state === \"connected\" && connection) {\n\t\t\t\t\titems.push({ value: \"tools\", label: \"Tools\", description: `${connection.tools.length} offered` });\n\t\t\t\t}\n\t\t\t\tif (state === \"failed\" || state === \"disconnected\" || state === \"connected\" || state === \"needs-auth\") {\n\t\t\t\t\titems.push({ value: \"reconnect\", label: \"Reconnect\" });\n\t\t\t\t}\n\t\t\t\tif (state === \"connected\" && connection?.oauthUrl) {\n\t\t\t\t\titems.push({ value: \"signout\", label: \"Sign out\", description: \"deletes the stored credentials\" });\n\t\t\t\t}\n\t\t\t\titems.push({ value: \"exposure\", label: \"Exposure\", description: exposureOf(entry) });\n\t\t\t\titems.push({ value: \"disable\", label: \"Disable\", description: saved });\n\t\t\t\tif (inProject) {\n\t\t\t\t\titems.push({ value: \"disable-project\", label: \"Disable in this project\", description: inProjectSaved });\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst details = [\n\t\t\t\tdescribeTransport(entry),\n\t\t\t\t`${entry.scope ?? \"config\"}: ${entry.source}`,\n\t\t\t\t...(entry.override ? [`project override: ${entry.override}`] : []),\n\t\t\t\t`State: ${describeState(server, false)}`,\n\t\t\t];\n\t\t\tconst error = [server.message, connection?.state === \"connected\" ? undefined : connection?.error]\n\t\t\t\t.filter((line): line is string => line !== undefined)\n\t\t\t\t.join(\"\\n\");\n\t\t\treturn {\n\t\t\t\ttitle: `MCP server ${name}`,\n\t\t\t\tdetails: details.join(\"\\n\"),\n\t\t\t\terror: error || undefined,\n\t\t\t\titems,\n\t\t\t\tselected: items[0]?.value,\n\t\t\t\tconfirmLabel: \"select\",\n\t\t\t\tcancelLabel: \"back\",\n\t\t\t};\n\t\t};\n\n\t\tconst showTools = async (ui: McpUi, server: McpServer) => {\n\t\t\tconst exposure = exposureOf(server.entry);\n\t\t\tconst overridden = Object.keys(server.entry.config.toolExposure ?? {}).length > 0;\n\t\t\tawait ui.menu(() => ({\n\t\t\t\ttitle: `Tools of ${server.entry.name}`,\n\t\t\t\tdetails: `Exposure ${exposure}: ${exposure === \"hidden\" ? \"unreachable\" : EXPOSURE_DESCRIPTIONS[exposure]}${overridden ? \"\\nSome tools override it with toolExposure.\" : \"\"}`,\n\t\t\t\titems: (server.connection?.tools ?? []).map((tool) => {\n\t\t\t\t\tconst toolExposure = getMcpToolExposure(server.entry.config, tool.name);\n\t\t\t\t\tconst description = firstLine(tool.description ?? \"\");\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: tool.name,\n\t\t\t\t\t\tlabel: tool.name,\n\t\t\t\t\t\tdescription: toolExposure === exposure ? description : `[${toolExposure}] ${description}`,\n\t\t\t\t\t};\n\t\t\t\t}),\n\t\t\t\tempty: \"The server offers no tools.\",\n\t\t\t\tconfirmLabel: \"back\",\n\t\t\t\tcancelLabel: \"back\",\n\t\t\t}));\n\t\t};\n\n\t\tconst chooseExposure = async (ui: McpUi, server: McpServer): Promise<string | undefined> => {\n\t\t\tconst current = exposureOf(server.entry);\n\t\t\tconst choice = await ui.menu(() => ({\n\t\t\t\ttitle: `Exposure of ${server.entry.name}`,\n\t\t\t\tdetails:\n\t\t\t\t\tserver.entry.scope === \"extension\"\n\t\t\t\t\t\t? `Applies to this session; the server is registered by ${server.entry.source}.`\n\t\t\t\t\t\t: `Saved to ${server.entry.override ?? server.entry.source}.`,\n\t\t\t\titems: (Object.keys(EXPOSURE_DESCRIPTIONS) as (keyof typeof EXPOSURE_DESCRIPTIONS)[]).map((exposure) => ({\n\t\t\t\t\tvalue: exposure,\n\t\t\t\t\tlabel: `${exposure === current ? \"✓ \" : \" \"}${exposure}`,\n\t\t\t\t\tdescription: EXPOSURE_DESCRIPTIONS[exposure],\n\t\t\t\t})),\n\t\t\t\tselected: current,\n\t\t\t\tconfirmLabel: \"save\",\n\t\t\t\tcancelLabel: \"back\",\n\t\t\t}));\n\t\t\tif (!choice || choice === current) return undefined;\n\t\t\treturn setExposure(server, choice as McpExposure);\n\t\t};\n\n\t\t/** Sign in with the manager view's sign-in screen, which shows the URL with a copy key. */\n\t\tconst signInWithUi = (ui: McpUi, server: McpServer): Promise<string | undefined> => {\n\t\t\tconst title = `Sign in to ${server.entry.name}`;\n\t\t\tlet authorizationUrl = \"\";\n\t\t\tui.status(title, \"Contacting the authorization server…\");\n\t\t\treturn signIn(server, {\n\t\t\t\tshowAuthorizationUrl: (url) => {\n\t\t\t\t\tauthorizationUrl = url.href;\n\t\t\t\t\topenUrl(url.href);\n\t\t\t\t},\n\t\t\t\tpromptForRedirectUrl: async (signal) => {\n\t\t\t\t\tconst value = await ui.redirectUrl(title, authorizationUrl, signal);\n\t\t\t\t\tui.status(title, \"Connecting…\");\n\t\t\t\t\treturn value;\n\t\t\t\t},\n\t\t\t});\n\t\t};\n\n\t\tconst runAction = async (ui: McpUi, ctx: ExtensionContext, server: McpServer, action: string) => {\n\t\t\tconst { name } = server.entry;\n\t\t\tlet message: string | undefined;\n\t\t\tswitch (action) {\n\t\t\t\tcase \"signin\":\n\t\t\t\t\tmessage = await signInWithUi(ui, server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"reconnect\":\n\t\t\t\t\t// A failure shows as the connection's state and error.\n\t\t\t\t\tui.status(`MCP server ${name}`, \"Reconnecting…\");\n\t\t\t\t\tawait reconnect(server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"signout\":\n\t\t\t\t\tawait signOut(server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"tools\":\n\t\t\t\t\tawait showTools(ui, server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"exposure\":\n\t\t\t\t\tmessage = await chooseExposure(ui, server);\n\t\t\t\t\tbreak;\n\t\t\t\tcase \"enable\":\n\t\t\t\tcase \"disable\":\n\t\t\t\tcase \"enable-project\":\n\t\t\t\tcase \"disable-project\": {\n\t\t\t\t\tconst enable = action.startsWith(\"enable\");\n\t\t\t\t\tui.status(`MCP server ${name}`, enable ? \"Connecting…\" : \"Disconnecting…\");\n\t\t\t\t\tmessage = await setEnabled(server, enable, action.endsWith(\"-project\"));\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tserver.message = message;\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\temitChange();\n\t\t};\n\t\tconst manage = async (ui: McpUi, ctx: ExtensionContext) => {\n\t\t\tfor (;;) {\n\t\t\t\tconst name = await ui.menu(serversMenu, subscribe);\n\t\t\t\tif (!name) return;\n\t\t\t\tfor (;;) {\n\t\t\t\t\tconst action = await ui.menu(() => serverMenu(name), subscribe);\n\t\t\t\t\tconst server = findServer(name);\n\t\t\t\t\tif (!action || !server) break;\n\t\t\t\t\tawait runAction(ui, ctx, server, action);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\t// ---------------------------------------------------------------------------------------\n\t\t// Subcommands and plain status (no TUI)\n\t\t// ---------------------------------------------------------------------------------------\n\n\t\tconst formatStatus = (): string => {\n\t\t\tif (servers.length === 0 && configErrors.length === 0 && overridden.length === 0) {\n\t\t\t\treturn `No MCP servers configured. Add them to ${resolve(getAgentDir(), \"mcp.json\")} or .pi/mcp.json.`;\n\t\t\t}\n\t\t\tconst lines = servers.map((server) => {\n\t\t\t\tconst { name } = server.entry;\n\t\t\t\tconst exposure = exposureOf(server.entry);\n\t\t\t\tconst connection = server.connection;\n\t\t\t\tif (connection?.state === \"needs-auth\")\n\t\t\t\t\treturn `${name}: needs sign-in, run /mcp login ${name} (${exposure})`;\n\t\t\t\tconst tools = connection?.state === \"connected\" ? `, ${connection.tools.length} tools` : \"\";\n\t\t\t\tconst state = !isEnabled(server)\n\t\t\t\t\t? \"disabled\"\n\t\t\t\t\t: connection?.state === \"disconnected\"\n\t\t\t\t\t\t? \"disconnected, reconnects on next call\"\n\t\t\t\t\t\t: (connection?.state ?? \"starting\");\n\t\t\t\tconst error =\n\t\t\t\t\tconnection?.error && connection.state !== \"connected\"\n\t\t\t\t\t\t? `\\n ${connection.error.split(\"\\n\").join(\"\\n \")}`\n\t\t\t\t\t\t: \"\";\n\t\t\t\treturn `${name}: ${state}${tools} (${exposure})${error}`;\n\t\t\t});\n\t\t\tfor (const error of configErrors) lines.push(`config error: ${error}`);\n\t\t\tfor (const line of overridden) lines.push(`overridden: ${line}`);\n\t\t\treturn lines.join(\"\\n\");\n\t\t};\n\n\t\t/** Resolve the server for a subcommand, asking when the name is omitted and ambiguous. */\n\t\tconst pickServer = async (\n\t\t\tname: string | undefined,\n\t\t\tctx: ExtensionCommandContext,\n\t\t\toptions: { eligible: (server: McpServer) => boolean; preferred: (server: McpServer) => boolean; none: string },\n\t\t): Promise<McpServer | undefined> => {\n\t\t\tif (name) {\n\t\t\t\tconst server = findServer(name);\n\t\t\t\tif (!server) ctx.ui.notify(`No MCP server named \"${name}\".`, \"error\");\n\t\t\t\telse if (!options.eligible(server)) ctx.ui.notify(options.none, \"error\");\n\t\t\t\treturn server && options.eligible(server) ? server : undefined;\n\t\t\t}\n\t\t\tconst candidates = servers.filter(options.eligible);\n\t\t\tif (candidates.length === 0) {\n\t\t\t\tctx.ui.notify(options.none, \"info\");\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tconst preferred = candidates.filter(options.preferred);\n\t\t\tif (candidates.length === 1) return candidates[0];\n\t\t\tif (preferred.length === 1) return preferred[0];\n\t\t\tconst choice = await ctx.ui.select(\n\t\t\t\t\"MCP server\",\n\t\t\t\tcandidates.map((server) => server.entry.name),\n\t\t\t);\n\t\t\treturn candidates.find((server) => server.entry.name === choice);\n\t\t};\n\n\t\tconst usesOAuth = (server: McpServer) => server.connection?.oauthUrl !== undefined;\n\t\tconst oauthPick = {\n\t\t\teligible: usesOAuth,\n\t\t\tpreferred: (server: McpServer) => server.connection?.state === \"needs-auth\",\n\t\t\tnone: \"No enabled MCP server uses OAuth. Only HTTP servers without an Authorization header do.\",\n\t\t};\n\n\t\tconst loginCommand = async (server: McpServer, ctx: ExtensionCommandContext) => {\n\t\t\tconst { name } = server.entry;\n\t\t\tif (!ctx.hasUI) {\n\t\t\t\tctx.ui.notify(`Signing in to MCP server \"${name}\" requires interactive mode.`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tlet failure: string | undefined;\n\t\t\tif (ctx.mode === \"tui\") {\n\t\t\t\tawait showMcpManager(ctx, async (ui) => {\n\t\t\t\t\tfailure = await signInWithUi(ui, server);\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tfailure = await signIn(server, {\n\t\t\t\t\tshowAuthorizationUrl: (url) => {\n\t\t\t\t\t\tctx.ui.notify(`Sign in to MCP server \"${name}\" in your browser:\\n${url.href}`, \"info\");\n\t\t\t\t\t\topenUrl(url.href);\n\t\t\t\t\t},\n\t\t\t\t\tpromptForRedirectUrl: (signal) =>\n\t\t\t\t\t\tctx.ui.input(\n\t\t\t\t\t\t\t`Waiting for sign-in to \"${name}\". If the browser cannot reach this machine, paste the URL it was redirected to.`,\n\t\t\t\t\t\t\t\"http://127.0.0.1:.../callback?code=...\",\n\t\t\t\t\t\t\t{ signal },\n\t\t\t\t\t\t),\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (failure) {\n\t\t\t\tctx.ui.notify(failure, failure === \"Sign-in cancelled.\" ? \"info\" : \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tctx.ui.notify(`Signed in to MCP server \"${name}\" (${server.connection?.tools.length ?? 0} tools).`, \"info\");\n\t\t};\n\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tconst loaded = (options.loadConfig ?? defaultLoadConfig)(ctx);\n\t\t\tconfigErrors = loaded.errors;\n\t\t\tprojectConfig = loaded.projectConfig;\n\t\t\tautoEnableCodemode = loaded.autoEnableCodemode ?? true;\n\t\t\twarnedUnreachable = false;\n\t\t\twaitedForStartup = false;\n\t\t\tsessionCwd = ctx.cwd;\n\t\t\tmodelRegistry = ctx.modelRegistry;\n\t\t\tconst current = ++generation;\n\t\t\tsessionActive = true;\n\t\t\tconfiguredEntries = loaded.servers;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tservers = [...loaded.servers.map((entry) => ({ entry })), ...registered.servers];\n\t\t\temitChange();\n\t\t\t// Codemode or tool_search is activated from the config: the first prompt does not wait for\n\t\t\t// servers whose tools are not declared to the model, and scripts or searches wait for them.\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tconst enabled = servers.filter(isEnabled);\n\t\t\tif (enabled.length === 0) {\n\t\t\t\treportProblems(ctx);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t// The MCP client loads only now, so sessions without servers never pay for it. Waiting one\n\t\t\t// event loop turn lets the first render happen before loading and connecting.\n\t\t\tconst runtime = new Promise((resolve) => setImmediate(resolve)).then(() => loadMcpRuntime());\n\t\t\tconst isCurrent = () => current === generation;\n\t\t\tpending = Promise.all(enabled.map((server) => startConnection(server, isCurrent, runtime)))\n\t\t\t\t.then(() => {\n\t\t\t\t\tif (isCurrent()) reportProblems(ctx);\n\t\t\t\t})\n\t\t\t\t.catch((error: unknown) => {\n\t\t\t\t\t// The session may have been disposed meanwhile, which makes ctx stale.\n\t\t\t\t\ttry {\n\t\t\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\t\t} catch {}\n\t\t\t\t});\n\t\t});\n\n\t\t// The first prompt waits for servers whose tools are declared to the model, so they are declared\n\t\t// in its first request, but not indefinitely: a slow or hanging server must not hold up the\n\t\t// prompt. Other servers are waited for when a script or search needs them (below).\n\t\tconst waitForDirectServers = async (ctx: ExtensionContext) => {\n\t\t\tif (waitedForStartup) return;\n\t\t\twaitedForStartup = true;\n\t\t\tconst ready = servers.flatMap((server) =>\n\t\t\t\tisEnabled(server) && hasDirectTools(server.entry) && server.ready ? [server.ready] : [],\n\t\t\t);\n\t\t\tif (ready.length === 0) return;\n\t\t\tlet timer: NodeJS.Timeout | undefined;\n\t\t\tconst finished = await Promise.race([\n\t\t\t\tPromise.all(ready).then(() => true),\n\t\t\t\tnew Promise<boolean>((resolve) => {\n\t\t\t\t\ttimer = setTimeout(() => resolve(false), startupWaitMs);\n\t\t\t\t}),\n\t\t\t]);\n\t\t\tclearTimeout(timer);\n\t\t\tif (!finished) {\n\t\t\t\tctx.ui.notify(\"MCP servers are still connecting; their tools become available once connected.\", \"info\");\n\t\t\t}\n\t\t};\n\n\t\t// Every prompt lists the servers in the `mcp_servers` section as they are when it starts. Pi\n\t\t// appends the section to the conversation when it changed, for example after a server connected.\n\t\tpi.on(\"before_agent_start\", async (event, ctx) => {\n\t\t\tawait waitForDirectServers(ctx);\n\t\t\tconst { sections } = event.systemPromptOptions;\n\t\t\tconst section = renderServersSection(servers);\n\t\t\tif (section) sections[MCP_SERVERS_SECTION] = section;\n\t\t\telse delete sections[MCP_SERVERS_SECTION];\n\t\t});\n\n\t\t// A codemode script waits for the servers it names, or for every server when it searches or\n\t\t// enumerates tools, so their tools are registered before the script runs. tool_search and the\n\t\t// resource tools reach every server, so they wait for all of them.\n\t\tpi.on(\"tool_call\", async (event, ctx) => {\n\t\t\tconst tool = pi.getAllTools().find((candidate) => candidate.name === event.toolName);\n\t\t\tif (!tool) return;\n\t\t\tconst pendingServers = servers.filter(\n\t\t\t\t(server) => isEnabled(server) && server.connection?.state !== \"connected\" && server.ready,\n\t\t\t);\n\t\t\tif (pendingServers.length === 0) return;\n\t\t\tlet waiting: McpServer[] = [];\n\t\t\tif (isCodemodeTool(tool)) {\n\t\t\t\tconst { code } = event.input as { code?: unknown };\n\t\t\t\tconst source = typeof code === \"string\" ? code : \"\";\n\t\t\t\twaiting = pendingServers.filter((server) => scriptNeedsServer(source, server.entry.name));\n\t\t\t} else if (isToolSearchTool(tool) || RESOURCE_TOOL_NAMES.has(tool.name)) {\n\t\t\t\twaiting = pendingServers;\n\t\t\t}\n\t\t\tawait waitForServers(waiting, ctx.signal);\n\t\t});\n\n\t\t// Pick up sign-ins done outside the session, such as `pi mcp login` run by the agent.\n\t\tpi.on(\"turn_start\", async (_event, ctx) => {\n\t\t\tif (tokensAtSignIn.size > 0) await reconnectSignedIn(ctx);\n\t\t});\n\n\t\t// Servers registered or unregistered during the session connect or disconnect right away.\n\t\tpi.on(\"mcp_servers_change\", async (_event, ctx) => {\n\t\t\tif (!sessionActive) return;\n\t\t\tconst current = generation;\n\t\t\tconst registered = registeredServers();\n\t\t\toverridden = registered.overridden;\n\t\t\tconst next = new Map(registered.servers.map((server) => [server.entry.name, server]));\n\t\t\t// Unregistered servers and re-registered ones with a new config are dropped; the latter come back below.\n\t\t\tconst removed = servers.filter(\n\t\t\t\t(server) =>\n\t\t\t\t\tserver.entry.scope === \"extension\" &&\n\t\t\t\t\tnext.get(server.entry.name)?.registeredConfig !== server.registeredConfig,\n\t\t\t);\n\t\t\tservers = servers.filter((server) => !removed.includes(server));\n\t\t\tfor (const server of removed) hideTools(server.entry.name);\n\t\t\tconst added = registered.servers.filter((server) => !findServer(server.entry.name));\n\t\t\tservers.push(...added);\n\t\t\temitChange();\n\t\t\tensureDiscoveryActive(ctx);\n\t\t\tawait Promise.all(removed.map((server) => server.connection?.close()));\n\t\t\tconst connecting = added.filter(isEnabled);\n\t\t\tif (current !== generation || connecting.length === 0) return;\n\t\t\ttry {\n\t\t\t\tawait Promise.all(connecting.map((server) => startConnection(server, () => current === generation)));\n\t\t\t\tif (current !== generation) {\n\t\t\t\t\tawait Promise.all(connecting.map((server) => server.connection?.close()));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} catch (error) {\n\t\t\t\tctx.ui.notify(`MCP failed to load: ${errorMessage(error)}`, \"error\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (current !== generation) return;\n\t\t\treportProblems(ctx, connecting);\n\t\t});\n\n\t\tpi.on(\"session_shutdown\", async () => {\n\t\t\tsessionActive = false;\n\t\t\tgeneration++;\n\t\t\tconst closing = connections();\n\t\t\tservers = [];\n\t\t\temitChange();\n\t\t\tawait Promise.all(closing.map((connection) => connection.close()));\n\t\t});\n\n\t\tpi.registerCommand(\"mcp\", {\n\t\t\tdescription: \"Manage MCP servers: sign in, reconnect, enable or disable, and change exposure\",\n\t\t\tgetArgumentCompletions: (prefix) => {\n\t\t\t\tconst [action, server, ...rest] = prefix.trimStart().split(/\\s+/);\n\t\t\t\tif (rest.length > 0) return null;\n\t\t\t\tif (server === undefined) {\n\t\t\t\t\treturn [\"login\", \"logout\", \"reconnect\"]\n\t\t\t\t\t\t.filter((item) => item.startsWith(action ?? \"\"))\n\t\t\t\t\t\t.map((item) => ({ value: `${item} `, label: item }));\n\t\t\t\t}\n\t\t\t\tif (action !== \"login\" && action !== \"logout\" && action !== \"reconnect\") return null;\n\t\t\t\tconst items = servers\n\t\t\t\t\t.filter((candidate) =>\n\t\t\t\t\t\taction === \"reconnect\" ? candidate.connection !== undefined : usesOAuth(candidate),\n\t\t\t\t\t)\n\t\t\t\t\t.filter((candidate) => candidate.entry.name.startsWith(server))\n\t\t\t\t\t.map((candidate) => ({\n\t\t\t\t\t\tvalue: `${action} ${candidate.entry.name}`,\n\t\t\t\t\t\tlabel: candidate.entry.name,\n\t\t\t\t\t\tdescription: describeState(candidate),\n\t\t\t\t\t}));\n\t\t\t\treturn items.length > 0 ? items : null;\n\t\t\t},\n\t\t\thandler: async (args, ctx) => {\n\t\t\t\tawait pending;\n\t\t\t\tconst [action, name, ...extra] = args.trim().split(/\\s+/).filter(Boolean);\n\t\t\t\tif (action === undefined) {\n\t\t\t\t\tif (ctx.mode === \"tui\") await showMcpManager(ctx, (ui) => manage(ui, ctx));\n\t\t\t\t\telse ctx.ui.notify(formatStatus(), \"info\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (extra.length > 0) {\n\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tswitch (action) {\n\t\t\t\t\tcase \"login\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (server) await loginCommand(server, ctx);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"logout\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, oauthPick);\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst removed = await signOut(server);\n\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\tremoved\n\t\t\t\t\t\t\t\t? `Signed out of MCP server \"${server.entry.name}\".`\n\t\t\t\t\t\t\t\t: `No stored credentials for MCP server \"${server.entry.name}\".`,\n\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"reconnect\": {\n\t\t\t\t\t\tconst server = await pickServer(name, ctx, {\n\t\t\t\t\t\t\teligible: (candidate) => candidate.connection !== undefined,\n\t\t\t\t\t\t\tpreferred: (candidate) =>\n\t\t\t\t\t\t\t\tcandidate.connection?.state === \"failed\" || candidate.connection?.state === \"disconnected\",\n\t\t\t\t\t\t\tnone: \"No enabled MCP server to reconnect.\",\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (!server) return;\n\t\t\t\t\t\tconst failure = await reconnect(server);\n\t\t\t\t\t\tif (failure) ctx.ui.notify(failure, \"error\");\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tensureDiscoveryActive(ctx);\n\t\t\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\t\t\t`Reconnected to MCP server \"${server.entry.name}\" (${describeState(server)}).`,\n\t\t\t\t\t\t\t\t\"info\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tdefault:\n\t\t\t\t\t\tctx.ui.notify(MCP_USAGE, \"warning\");\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t};\n}\n\nfunction defaultLoadConfig(ctx: ExtensionContext): LoadedMcpConfig {\n\treturn loadMcpConfig({ agentDir: getAgentDir(), cwd: ctx.cwd, projectTrusted: ctx.isProjectTrusted() });\n}\n\nexport default createMcpExtension();\n"]}
@@ -4,7 +4,8 @@
4
4
  * Connections never start a browser flow on their own. They send the stored access token and, after
5
5
  * a 401, try the stored refresh token. When that is not possible they fail with
6
6
  * `McpOAuthAuthorizationRequiredError`, and the user signs in through `/mcp`, which runs
7
- * the authorization code flow (PKCE, dynamic client registration) against a loopback callback.
7
+ * the authorization code flow (PKCE, a Client ID Metadata Document or dynamic client registration)
8
+ * against a loopback callback.
8
9
  *
9
10
  * Credentials live in `<agent-dir>/mcp-auth.json`, keyed by server name and URL.
10
11
  */
@@ -22,6 +23,8 @@ export interface McpOAuthSettings {
22
23
  scope?: string;
23
24
  /** `client_name` for dynamic client registration. Default: `APP_NAME`. */
24
25
  clientName?: string;
26
+ /** See `McpOAuthConfig.clientRegistration`. */
27
+ clientRegistration?: "dcr" | "cimd";
25
28
  /** See `McpOAuthConfig.authServerMetadataUrl`. */
26
29
  authServerMetadataUrl?: URL;
27
30
  }
@@ -1 +1 @@
1
- {"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../../src/extensions/mcp/oauth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAY,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAIN,KAAK,aAAa,EAClB,KAAK,kBAAkB,EAIvB,KAAK,cAAc,EAInB,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,KAAK,kBAAkB,EAA0B,MAAM,4BAA4B,CAAC;AAiB7F,MAAM,WAAW,gBAAgB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wBAAwB;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,qBAAqB,CAAC,EAAE,GAAG,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