@agimon-ai/po-mcp 0.0.0-alpha.151 → 0.0.0-alpha.152

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 (43) hide show
  1. package/dist/{directTools-CMtiNOwX.cjs → directTools-CUm1GbQZ.cjs} +23 -8
  2. package/dist/directTools-CUm1GbQZ.cjs.map +1 -0
  3. package/dist/{directTools-Dez3RjUJ.mjs → directTools-utuNMgg-.mjs} +23 -8
  4. package/dist/directTools-utuNMgg-.mjs.map +1 -0
  5. package/dist/extensions/native.mjs +8 -0
  6. package/dist/extensions/native.mjs.map +1 -1
  7. package/dist/extensions/server.cjs +113 -30
  8. package/dist/extensions/server.cjs.map +1 -1
  9. package/dist/extensions/server.mjs +99 -16
  10. package/dist/extensions/server.mjs.map +1 -1
  11. package/dist/extensions/web.mjs +8 -0
  12. package/dist/extensions/web.mjs.map +1 -1
  13. package/dist/{index-DAVKnZtv.d.mts → index-8Am_Bf4O.d.mts} +1 -1
  14. package/dist/{index-BJkh7lQ0.d.mts → index-CRU70cfK.d.mts} +2 -2
  15. package/dist/{index-BJkh7lQ0.d.mts.map → index-CRU70cfK.d.mts.map} +1 -1
  16. package/dist/index.cjs +2 -2
  17. package/dist/index.d.mts +1 -1
  18. package/dist/index.d.mts.map +1 -1
  19. package/dist/index.mjs +2 -2
  20. package/dist/localServers.d.mts +1 -1
  21. package/dist/{mcpCatalog-DlC5mMkl.cjs → mcpCatalog-CpRC4RMU.cjs} +376 -1
  22. package/dist/mcpCatalog-CpRC4RMU.cjs.map +1 -0
  23. package/dist/{mcpCatalog-vwwMhex1.mjs → mcpCatalog-Dw_-ka5_.mjs} +305 -2
  24. package/dist/mcpCatalog-Dw_-ka5_.mjs.map +1 -0
  25. package/dist/{mcpConfig-CShx27dN.d.mts → mcpConfig-8S120X75.d.mts} +6 -1
  26. package/dist/mcpConfig-8S120X75.d.mts.map +1 -0
  27. package/dist/{mcpServerConfig-D4CfVl5n.mjs → mcpServerConfig-B3c3o2WE.mjs} +11 -222
  28. package/dist/mcpServerConfig-B3c3o2WE.mjs.map +1 -0
  29. package/dist/{mcpServerConfig-MsdUdLuv.cjs → mcpServerConfig-DHpzsw4L.cjs} +11 -270
  30. package/dist/mcpServerConfig-DHpzsw4L.cjs.map +1 -0
  31. package/dist/projection.d.mts +1 -1
  32. package/dist/remoteServers.cjs +2 -2
  33. package/dist/remoteServers.d.mts +1 -1
  34. package/dist/remoteServers.mjs +2 -2
  35. package/dist/sessionServers.d.mts +1 -1
  36. package/package.json +9 -9
  37. package/dist/directTools-CMtiNOwX.cjs.map +0 -1
  38. package/dist/directTools-Dez3RjUJ.mjs.map +0 -1
  39. package/dist/mcpCatalog-DlC5mMkl.cjs.map +0 -1
  40. package/dist/mcpCatalog-vwwMhex1.mjs.map +0 -1
  41. package/dist/mcpConfig-CShx27dN.d.mts.map +0 -1
  42. package/dist/mcpServerConfig-D4CfVl5n.mjs.map +0 -1
  43. package/dist/mcpServerConfig-MsdUdLuv.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
- const require_mcpCatalog = require("./mcpCatalog-DlC5mMkl.cjs");
2
+ const require_mcpCatalog = require("./mcpCatalog-CpRC4RMU.cjs");
3
3
  let node_crypto = require("node:crypto");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
  node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises, 1);
@@ -88,7 +88,8 @@ async function layerCacheKey(filePath, format, originalContents, effectiveConten
88
88
  *
89
89
  * Proxy wrapper entries are stripped from `.mcp.json` layers because Po reaches
90
90
  * their upstream config directly. Entries are removed rather than marked disabled,
91
- * so a filtered stdio server is never spawned at all.
91
+ * so a filtered stdio server is never spawned at all. With `vaultFallback`, a plugin
92
+ * layer's unset `${VAR}` secrets become Vault references in the staged copy.
92
93
  */
93
94
  async function filterLayer(filePath, allowed, stagingDirectory, options) {
94
95
  const document = await readConfigDocument(filePath);
@@ -97,10 +98,18 @@ async function filterLayer(filePath, allowed, stagingDirectory, options) {
97
98
  const servers = serverDefinitions(config);
98
99
  const kept = {};
99
100
  const dropped = [];
100
- for (const [name, definition] of Object.entries(servers)) if (options.stripProxyWrappers && require_mcpCatalog.isProxyWrapper(name) || !isAllowed(name, allowed)) dropped.push(name);
101
- else kept[name] = definition;
101
+ let rewritten = false;
102
+ for (const [name, definition] of Object.entries(servers)) {
103
+ if (options.stripProxyWrappers && require_mcpCatalog.isProxyWrapper(name) || !isAllowed(name, allowed)) {
104
+ dropped.push(name);
105
+ continue;
106
+ }
107
+ const fallback = options.vaultFallback ? require_mcpCatalog.withVaultFallback(definition, options.vaultFallback) : void 0;
108
+ if (fallback?.changed) rewritten = true;
109
+ kept[name] = fallback ? fallback.definition : definition;
110
+ }
102
111
  const keptNames = Object.entries(kept).filter(([, definition]) => isEnabledDefinition(definition)).map(([name]) => name);
103
- if (dropped.length === 0) return {
112
+ if (dropped.length === 0 && !rewritten) return {
104
113
  source: {
105
114
  path: filePath,
106
115
  format: "claude",
@@ -194,7 +203,11 @@ async function buildMcpConfigGroups(input) {
194
203
  const droppedServers = [];
195
204
  const diagnostics = [];
196
205
  for (const layer of legacyLayers) {
197
- const filtered = await filterLayer(layer.path, input.allowlist?.servers, input.stagingDirectory, { stripProxyWrappers: true });
206
+ const isPlugin = layer.path !== node_path.default.join(input.repoRoot, ".mcp.json");
207
+ const filtered = await filterLayer(layer.path, input.allowlist?.servers, input.stagingDirectory, {
208
+ stripProxyWrappers: true,
209
+ ...isPlugin && input.environment ? { vaultFallback: input.environment } : {}
210
+ });
198
211
  if (!filtered) continue;
199
212
  configSources.push(filtered.source);
200
213
  serverNames.push(...filtered.kept);
@@ -218,9 +231,11 @@ async function buildMcpConfigGroups(input) {
218
231
  diagnostics.push(`Native MCP source "${source.sourceId}" was disabled: the file is missing or its content digest changed.`);
219
232
  continue;
220
233
  }
234
+ const isPlugin = source.owner !== "user" && source.owner !== "repository";
221
235
  const filtered = await filterLayer(source.configPath, input.allowlist?.servers, input.stagingDirectory, {
222
236
  stripProxyWrappers: true,
223
- sourceIdentity: `${source.sourceId}:${source.contentDigest}`
237
+ sourceIdentity: `${source.sourceId}:${source.contentDigest}`,
238
+ ...isPlugin && input.environment ? { vaultFallback: input.environment } : {}
224
239
  });
225
240
  if (!filtered) {
226
241
  diagnostics.push(`Native MCP source "${source.sourceId}" was disabled: the config could not be parsed.`);
@@ -555,4 +570,4 @@ Object.defineProperty(exports, "sessionConfigEnvironment", {
555
570
  }
556
571
  });
557
572
 
558
- //# sourceMappingURL=directTools-CMtiNOwX.cjs.map
573
+ //# sourceMappingURL=directTools-CUm1GbQZ.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directTools-CUm1GbQZ.cjs","names":["path","fs","parseYaml","PROXY_SERVER_ALIASES","createHash","stringifyYaml","isProxyWrapper","withVaultFallback","repositoryMcpScope","pluginPathMcpScope","normalizeAgentPluginMcpSource","projectedSourceMcpScope","createHash","mcpProxyPackage","MCP_APP_CLIENT_CAPABILITIES","join","homedir","readFile","path","readPoMcpSessionConfig","PO_MCP_SESSION_ENV_VAR","poMcpSessionEnvironment"],"sources":["../src/services/configSources/index.ts","../src/services/mcpRuntime/index.ts","../src/services/sessionConfig/index.ts","../src/schemas/directTools.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { normalizeAgentPluginMcpSource } from '@agimon-ai/po-config/agentPluginMcp';\nimport type { PoMcpNativeProjectionSource } from '@agimon-ai/po-core/mcpProjection';\nimport { parse as parseYaml, stringify as stringifyYaml } from 'yaml';\n\nimport type { McpConfigGroups, McpConfigGroupsInput, McpConfigSource, McpServerOrigin } from '../../types/mcpConfig';\nimport { pluginPathMcpScope, projectedSourceMcpScope, repositoryMcpScope } from '../mcpScope';\nimport { withVaultFallback } from '../mcpSecrets';\nimport { isProxyWrapper, PROXY_SERVER_ALIASES } from '../proxyWrapper';\n\n// The name check lives in `proxyWrapper` so the edge-safe server config can use it without this file's Node imports.\nexport { isProxyWrapper, PROXY_SERVER_NAME } from '../proxyWrapper';\n\nconst PRIVATE_FILE_MODE = 0o600;\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst DEFAULT_UPSTREAM_CONFIG = 'mcp-config.yaml';\nconst CONFIG_ARGUMENT = '--config';\n\ntype JsonObject = Record<string, unknown>;\n\ninterface FilteredLayer {\n source: McpConfigSource;\n kept: string[];\n dropped: string[];\n}\n\ninterface ConfigDocument {\n config: JsonObject;\n contents: string;\n}\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isYamlPath(filePath: string): boolean {\n const extension = path.extname(filePath).toLowerCase();\n return extension === '.yaml' || extension === '.yml';\n}\n\nasync function readConfigDocument(filePath: string): Promise<ConfigDocument | undefined> {\n try {\n const contents = await fs.readFile(filePath, 'utf8');\n const parsed: unknown = isYamlPath(filePath) ? parseYaml(contents) : JSON.parse(contents);\n return isObject(parsed) ? { config: parsed, contents } : undefined;\n } catch {\n return undefined;\n }\n}\n\nasync function readConfigObject(filePath: string): Promise<JsonObject | undefined> {\n return (await readConfigDocument(filePath))?.config;\n}\n\nfunction serverDefinitions(config: JsonObject | undefined): Record<string, unknown> {\n return isObject(config?.mcpServers) ? config.mcpServers : {};\n}\n\nfunction isEnabledDefinition(definition: unknown): boolean {\n return !isObject(definition) || definition.disabled !== true;\n}\n\n/**\n * Resolves the upstream config referenced by the repository proxy wrapper.\n *\n * The wrapper remains useful to Claude, Codex, and other external clients. Po\n * embeds the same client/runtime code, so it reads this path and connects each\n * declared server itself instead of starting the wrapper as a nested MCP.\n */\nasync function resolveSharedConfigPathFrom(\n repoRoot: string,\n repositoryConfigPath: string,\n): Promise<string | undefined> {\n const servers = serverDefinitions(await readConfigObject(repositoryConfigPath));\n const proxy = [...PROXY_SERVER_ALIASES]\n .map((name) => servers[name])\n .find((definition): definition is JsonObject => isObject(definition));\n const rawArgs: unknown = proxy?.args;\n const args = Array.isArray(rawArgs) ? (rawArgs as unknown[]) : [];\n const configArgumentIndex = args.indexOf(CONFIG_ARGUMENT);\n const declared = args[configArgumentIndex + 1];\n const candidate =\n configArgumentIndex >= 0 && typeof declared === 'string'\n ? path.resolve(repoRoot, declared)\n : path.join(repoRoot, DEFAULT_UPSTREAM_CONFIG);\n try {\n await fs.access(candidate);\n return candidate;\n } catch {\n return undefined;\n }\n}\n\nexport async function resolveSharedConfigPath(repoRoot: string): Promise<string | undefined> {\n return resolveSharedConfigPathFrom(repoRoot, path.join(repoRoot, '.mcp.json'));\n}\n\n/** Empty and absent allowlists both mean \"keep everything\". */\nfunction isAllowed(name: string, allowed: string[] | undefined): boolean {\n return !allowed || allowed.length === 0 || allowed.includes(name);\n}\n\nfunction stagedPath(filePath: string, contents: string, stagingDirectory: string): string {\n // The filtered bytes are part of the identity because two live sessions can\n // select different domains. Sharing a path would let the later one rewrite the\n // configuration underneath the first one's deferred startup.\n const digest = createHash('sha256').update(filePath).update('\\0').update(contents).digest('hex').slice(0, 16);\n const extension = isYamlPath(filePath) ? '.yaml' : '.json';\n return path.join(stagingDirectory, `mcp-${digest}${extension}`);\n}\n\nfunction serializeConfig(filePath: string, config: JsonObject): string {\n return isYamlPath(filePath) ? stringifyYaml(config) : `${JSON.stringify(config, null, 2)}\\n`;\n}\n\nasync function layerCacheKey(\n filePath: string,\n format: McpConfigSource['format'],\n originalContents: string,\n effectiveContents: string,\n sourceIdentity?: string,\n): Promise<string> {\n return createHash('sha256')\n .update(format)\n .update('\\0')\n .update(await fs.realpath(filePath))\n .update('\\0')\n .update(sourceIdentity ?? 'unprojected')\n .update('\\0')\n .update(originalContents)\n .update('\\0')\n .update(effectiveContents)\n .digest('hex');\n}\n\n/**\n * Rewrites one config layer with disallowed servers removed.\n *\n * Proxy wrapper entries are stripped from `.mcp.json` layers because Po reaches\n * their upstream config directly. Entries are removed rather than marked disabled,\n * so a filtered stdio server is never spawned at all. With `vaultFallback`, a plugin\n * layer's unset `${VAR}` secrets become Vault references in the staged copy.\n */\nasync function filterLayer(\n filePath: string,\n allowed: string[] | undefined,\n stagingDirectory: string,\n options: {\n stripProxyWrappers: boolean;\n sourceIdentity?: string;\n vaultFallback?: Readonly<Record<string, string | undefined>>;\n },\n): Promise<FilteredLayer | undefined> {\n const document = await readConfigDocument(filePath);\n if (!document) return undefined;\n const { config, contents: originalContents } = document;\n const servers = serverDefinitions(config);\n const kept: Record<string, unknown> = {};\n const dropped: string[] = [];\n\n let rewritten = false;\n for (const [name, definition] of Object.entries(servers)) {\n const shouldDrop = (options.stripProxyWrappers && isProxyWrapper(name)) || !isAllowed(name, allowed);\n if (shouldDrop) {\n dropped.push(name);\n continue;\n }\n const fallback = options.vaultFallback ? withVaultFallback(definition, options.vaultFallback) : undefined;\n if (fallback?.changed) rewritten = true;\n kept[name] = fallback ? fallback.definition : definition;\n }\n\n const keptNames = Object.entries(kept)\n .filter(([, definition]) => isEnabledDefinition(definition))\n .map(([name]) => name);\n if (dropped.length === 0 && !rewritten) {\n return {\n source: {\n path: filePath,\n format: 'claude',\n cacheKey: await layerCacheKey(filePath, 'claude', originalContents, originalContents, options.sourceIdentity),\n },\n kept: keptNames,\n dropped,\n };\n }\n\n await fs.mkdir(stagingDirectory, { mode: PRIVATE_DIRECTORY_MODE, recursive: true });\n const contents = serializeConfig(filePath, { ...config, mcpServers: kept });\n const target = stagedPath(filePath, contents, stagingDirectory);\n await fs.writeFile(target, contents, { mode: PRIVATE_FILE_MODE });\n return {\n source: {\n path: target,\n format: 'claude',\n cacheKey: await layerCacheKey(filePath, 'claude', originalContents, contents, options.sourceIdentity),\n },\n kept: keptNames,\n dropped,\n };\n}\n\nasync function digestMatches(source: PoMcpNativeProjectionSource): Promise<boolean> {\n try {\n const digest = createHash('sha256')\n .update(await fs.readFile(source.configPath))\n .digest('hex');\n return digest === source.contentDigest;\n } catch {\n return false;\n }\n}\n\nfunction emptyGroups(diagnostics: string[] = []): McpConfigGroups {\n return {\n shared: { configSources: [], configPaths: [], serverNames: [] },\n sessionLocal: { configSources: [], configPaths: [], serverNames: [] },\n droppedServers: [],\n diagnostics,\n serverScopes: {},\n };\n}\n\n/**\n * Resolves every config layer for this session and applies its domain allowlist.\n *\n * All returned layers go into one embedded `@agimon-ai/po-mcp-proxy` client container.\n * The package is used as a library only: its wrapper MCP never becomes a Po MCP\n * server, so status, enable/disable, resources, and OAuth stay attached to each\n * actual downstream server.\n */\nexport async function buildMcpConfigGroups(input: McpConfigGroupsInput): Promise<\n McpConfigGroups & {\n /** Internal only. Paths and revisions must not be forwarded as browser ownership claims. */\n serverOrigins?: Record<string, McpServerOrigin>;\n }\n> {\n if (input.enabled === false) return emptyGroups();\n\n const projectedSources = input.sources;\n const repositoryScope = await repositoryMcpScope(input.repoRoot);\n const legacyLayers = projectedSources\n ? []\n : [\n { path: path.join(input.repoRoot, '.mcp.json'), scope: repositoryScope },\n ...(input.pluginConfigPaths ?? []).map((candidate) => {\n const resolved = path.resolve(input.repoRoot, candidate);\n return { path: resolved, scope: pluginPathMcpScope(resolved) };\n }),\n ];\n // Walked in container order, sessionLocal then shared, so the layer that wins a name owns its credential.\n const serverScopes: Record<string, string> = {};\n const serverOrigins: Record<string, McpServerOrigin> = {};\n const claim = async (\n names: readonly string[],\n scope: string,\n owner: McpServerOrigin['owner'],\n filePath: string,\n sourceId?: string,\n ) => {\n const definitions = serverDefinitions(await readConfigObject(filePath));\n for (const name of names) {\n serverScopes[name] = scope;\n serverOrigins[name] = {\n owner,\n path: filePath,\n revision: createHash('sha256')\n .update(JSON.stringify(definitions[name]) ?? 'undefined')\n .digest('hex'),\n ...(sourceId === undefined ? {} : { sourceId }),\n };\n }\n };\n\n const configSources: McpConfigSource[] = [];\n const serverNames: string[] = [];\n const droppedServers: string[] = [];\n const diagnostics: string[] = [];\n for (const layer of legacyLayers) {\n const isPlugin = layer.path !== path.join(input.repoRoot, '.mcp.json');\n const filtered = await filterLayer(layer.path, input.allowlist?.servers, input.stagingDirectory, {\n stripProxyWrappers: true,\n ...(isPlugin && input.environment ? { vaultFallback: input.environment } : {}),\n });\n if (!filtered) continue;\n configSources.push(filtered.source);\n serverNames.push(...filtered.kept);\n await claim(\n filtered.kept,\n layer.scope,\n layer.path === path.join(input.repoRoot, '.mcp.json') ? 'repository' : 'plugin',\n layer.path,\n );\n droppedServers.push(...filtered.dropped);\n }\n\n for (const source of projectedSources ?? []) {\n if (source.format === 'agent-plugin-v1') {\n const normalized = normalizeAgentPluginMcpSource(source, {\n stagingDirectory: input.stagingDirectory,\n allowedServers: input.allowlist?.servers,\n });\n if (normalized.configSource) configSources.push(normalized.configSource);\n serverNames.push(...normalized.serverNames);\n await claim(\n normalized.serverNames,\n await projectedSourceMcpScope(source, input.repoRoot),\n 'plugin',\n normalized.configSource?.path ?? source.configPath,\n source.sourceId,\n );\n droppedServers.push(...normalized.droppedServers);\n diagnostics.push(...normalized.diagnostics);\n continue;\n }\n\n if (!(await digestMatches(source))) {\n diagnostics.push(\n `Native MCP source \"${source.sourceId}\" was disabled: the file is missing or its content digest changed.`,\n );\n continue;\n }\n const isPlugin = source.owner !== 'user' && source.owner !== 'repository';\n const filtered = await filterLayer(source.configPath, input.allowlist?.servers, input.stagingDirectory, {\n stripProxyWrappers: true,\n sourceIdentity: `${source.sourceId}:${source.contentDigest}`,\n ...(isPlugin && input.environment ? { vaultFallback: input.environment } : {}),\n });\n if (!filtered) {\n diagnostics.push(`Native MCP source \"${source.sourceId}\" was disabled: the config could not be parsed.`);\n continue;\n }\n configSources.push(filtered.source);\n serverNames.push(...filtered.kept);\n await claim(\n filtered.kept,\n await projectedSourceMcpScope(source, input.repoRoot),\n source.owner === 'user' ? 'user' : source.owner === 'repository' ? 'repository' : 'plugin',\n source.configPath,\n source.sourceId,\n );\n droppedServers.push(...filtered.dropped);\n }\n\n const repositorySource = projectedSources?.find(\n (source): source is PoMcpNativeProjectionSource => source.format === 'native' && source.owner === 'repository',\n );\n const upstreamPath = projectedSources\n ? repositorySource && (await digestMatches(repositorySource))\n ? await resolveSharedConfigPathFrom(input.repoRoot, repositorySource.configPath)\n : undefined\n : await resolveSharedConfigPath(input.repoRoot);\n const upstream = upstreamPath\n ? await filterLayer(upstreamPath, input.allowlist?.proxy, input.stagingDirectory, { stripProxyWrappers: true })\n : undefined;\n if (upstream) {\n droppedServers.push(...upstream.dropped);\n // The repository's mcp-config.yaml belongs to the repository layer.\n await claim(upstream.kept, repositoryScope, 'upstream', upstreamPath!);\n }\n\n return {\n shared: {\n configSources: upstream ? [upstream.source] : [],\n configPaths: upstream ? [upstream.source.path] : [],\n serverNames: upstream ? upstream.kept : [],\n },\n // A later layer overriding an earlier one contributes the same name twice.\n sessionLocal: {\n configSources,\n configPaths: configSources.map((source) => source.path),\n serverNames: [...new Set(serverNames)],\n },\n droppedServers: [...new Set(droppedServers)],\n diagnostics,\n serverScopes,\n serverOrigins,\n };\n}\n","import { createHash } from 'node:crypto';\nimport { readFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nimport type { PoOAuthRedirect } from '@agimon-ai/po-core/packageApi';\nimport type {\n ConfigSource,\n McpClientManagerAuthOptions,\n McpOutputSchemaWarning,\n McpSecretTarget,\n McpServerStateChange,\n McpToolInfo,\n OAuthCallbackSink,\n SharedServices,\n TokenStore,\n} from '@agimon-ai/po-mcp-proxy';\nimport mcpProxyPackage from '@agimon-ai/po-mcp-proxy/package.json' with { type: 'json' };\n\nimport { MCP_APP_CLIENT_CAPABILITIES } from '../../constants/mcp';\nimport type { McpConfigSource } from '../../types/mcpConfig';\nimport type { CachedCatalog } from '../../types/mcpRuntime';\n\n/**\n * Presents the hub's redirect surface as the proxy's callback collaborator.\n *\n * `listen` binds nothing: the hub already serves the address this advertises,\n * so opening a loopback port would only create one nobody redirects to.\n */\nexport function hubCallbackSink(redirect: PoOAuthRedirect): OAuthCallbackSink {\n return {\n redirectUri: () => redirect.redirectUri,\n getPort: () => undefined,\n listen: (preferredPort) => Promise.resolve(preferredPort),\n reserve: (state, timeoutMs) => redirect.reserve(state, timeoutMs),\n waitForCallback: (state, timeoutMs) => redirect.wait(state, timeoutMs),\n cancel: (state) => redirect.cancel(state),\n };\n}\n\nexport interface McpRuntimeOptions {\n /** Ordered config layers. Later layers override earlier ones. */\n configSources: McpConfigSource[];\n workspaceRoot?: string;\n /** Only an explicit session-only server add may start without file sources. */\n allowEmpty?: boolean;\n /** Exact session directory, independent of the checkout used for configuration. */\n executionCwd?: string;\n environment?: Readonly<Record<string, string | undefined>>;\n /**\n * Required: without one the proxy would fall back to its own file store under\n * `~/.mcp-proxy`, and Po keeps credentials only in the vault or in memory.\n */\n tokenStore: TokenStore;\n /**\n * Where OAuth redirects are received. Omitted, the proxy binds its own\n * loopback listener, which only a browser on this machine can reach.\n */\n callbackServer?: OAuthCallbackSink;\n /** Resolves `${vault:NAME}` references at connect time. Without it, every reference fails its connection. */\n resolveSecret?: (target: McpSecretTarget) => Promise<string | undefined>;\n resolveUrlCredentials?: McpClientManagerAuthOptions['resolveUrlCredentials'];\n onAuthorizationUrl?: (url: URL, serverName: string) => void;\n onServerStateChange?: (change: McpServerStateChange) => void;\n onOutputSchemaWarning?: (warning: McpOutputSchemaWarning) => void;\n}\n\nexport interface McpRuntimeHandle {\n generation: number;\n services: SharedServices;\n /** Resolves once the first connection pass settles. Never rejects. */\n connectionsSettled: Promise<void>;\n}\n\ninterface DefinitionsCacheFile {\n oneMcpVersion?: string;\n servers?: Record<string, { serverName: string; tools?: McpToolInfo[] }>;\n}\n\n/**\n * Definitions cache path shared by Po's synchronous warm reader and mcp-proxy.\n *\n * Generated staging paths are deliberately absent: projected source content must\n * invalidate a reused path, while identical portable content must survive a new\n * private staging directory. Stable source origins are carried inside each cache\n * key; format and merge behavior remain part of the ordered identity.\n */\nexport function definitionsCachePath(configSources: readonly McpConfigSource[]): string {\n if (configSources.length === 0) throw new Error('definitionsCachePath requires at least one config source');\n const digest = createHash('sha256')\n .update(\n JSON.stringify(\n configSources.map((source) => ({\n cacheKey: source.cacheKey,\n format: source.format,\n optional: source.optional ?? false,\n mergeStrategy: source.mergeStrategy ?? 'remote-priority',\n })),\n ),\n )\n .update('\\0')\n .update(mcpProxyPackage.version)\n .update('\\0')\n .update(JSON.stringify(MCP_APP_CLIENT_CAPABILITIES))\n .digest('hex');\n return join(homedir(), '.mcp-proxy', `po-${digest}.definitions-cache.json`);\n}\n\n/**\n * Reads the catalog the previous run left behind.\n *\n * Callers await the cache before registering tools. A miss is normal on a first\n * run and resolves to an empty catalog rather than an error.\n *\n * The file path is content-addressed from the current ordered layers, and its proxy\n * version is checked before any schema is registered. Servers filtered out of the\n * current configuration are also excluded later by `McpCatalog.seed`.\n */\nexport async function readCachedCatalog(\n configSources: readonly McpConfigSource[],\n cachePathFor: (sources: readonly McpConfigSource[]) => string = definitionsCachePath,\n): Promise<CachedCatalog> {\n if (configSources.length === 0) return { servers: [] };\n try {\n const cachePath = cachePathFor(configSources);\n const cache = JSON.parse(await readFile(cachePath, 'utf8')) as Partial<DefinitionsCacheFile>;\n if (cache.oneMcpVersion !== mcpProxyPackage.version) return { servers: [] };\n const servers = Object.values(cache.servers ?? {}).map((server) => ({\n name: server.serverName,\n tools: server.tools ?? [],\n }));\n return { servers };\n } catch {\n return { servers: [] };\n }\n}\n\nfunction toProxyConfigSource(source: McpConfigSource): ConfigSource {\n return {\n path: source.path,\n format: source.format,\n ...(source.optional === undefined ? {} : { optional: source.optional }),\n ...(source.mergeStrategy === undefined ? {} : { mergeStrategy: source.mergeStrategy }),\n };\n}\n\n/**\n * Owns the one live mcp-proxy container for this extension.\n *\n * Pi reloads extensions in process, so a connect that lands after a session restart\n * or a `/domains` switch would otherwise fold tools into a dead context. Every start\n * takes the next generation; anything an older generation produces is dropped and its\n * container disposed.\n */\nexport class McpRuntimeOwner {\n private generation = 0;\n private active: SharedServices | undefined;\n private unsubscribe: (() => void) | undefined;\n\n get currentGeneration(): number {\n return this.generation;\n }\n\n /** The live container, or undefined before the first start and after dispose. */\n getServices(): SharedServices | undefined {\n return this.active;\n }\n\n /**\n * Whether a container a caller captured earlier is still the live one.\n *\n * An async continuation that started under one container has to check this\n * before writing its result, or a `/domains` switch would fold stale tools into\n * the new session.\n */\n isCurrent(services: SharedServices | undefined): boolean {\n return services !== undefined && services === this.active;\n }\n\n /**\n * Starts a container for the current configuration, replacing any predecessor.\n *\n * Returns undefined when a newer generation started while this one was building,\n * which is the signal for the caller to abandon its half-finished work.\n */\n async start(options: McpRuntimeOptions): Promise<McpRuntimeHandle | undefined> {\n if (!options.tokenStore) throw new Error('The MCP runtime needs a token store.');\n const generation = ++this.generation;\n // Retired before the replacement is built so two containers never hold the same\n // stdio children open at once.\n await this.retire();\n if (options.configSources.length === 0 && !options.allowEmpty) return undefined;\n\n // The proxy container pulls in transports, OAuth, schema conversion, and\n // server implementations. Cached tool registration needs none of those, so\n // load the runtime only after session_start has yielded control to Pi.\n const { createProxyContainer } = await import('@agimon-ai/po-mcp-proxy');\n const cachePath = options.configSources.length > 0 ? definitionsCachePath(options.configSources) : undefined;\n const containerOptions = {\n configSources: options.configSources.map(toProxyConfigSource),\n workspaceRoot: options.workspaceRoot,\n executionCwd: options.executionCwd,\n environment: options.environment,\n definitionsCachePath: cachePath,\n // Never blocking: an unreachable server must not delay Pi's first prompt.\n startupMode: 'background' as const,\n clientCapabilities: MCP_APP_CLIENT_CAPABILITIES,\n outputSchemaValidation: {\n mode: 'warn' as const,\n onWarning: (warning: McpOutputSchemaWarning) => {\n if (generation === this.generation) options.onOutputSchemaWarning?.(warning);\n },\n },\n auth: {\n tokenStore: options.tokenStore,\n onAuthorizationUrl: options.onAuthorizationUrl,\n ...(options.callbackServer ? { callbackServer: options.callbackServer } : {}),\n ...(options.resolveSecret ? { resolveSecret: options.resolveSecret } : {}),\n ...(options.resolveUrlCredentials ? { resolveUrlCredentials: options.resolveUrlCredentials } : {}),\n },\n };\n const services = await createProxyContainer(containerOptions);\n\n if (generation !== this.generation) {\n await services.dispose();\n return undefined;\n }\n\n this.active = services;\n const forward = options.onServerStateChange;\n if (forward) {\n this.unsubscribe = services.clientManager.onServerStateChange((change) => {\n if (generation === this.generation) forward(change);\n });\n }\n\n return { generation, services, connectionsSettled: services.connectionsSettled };\n }\n\n /** Tears the container down and invalidates every generation still in flight. */\n async dispose(): Promise<void> {\n ++this.generation;\n await this.retire();\n }\n\n private async retire(): Promise<void> {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n const services = this.active;\n this.active = undefined;\n // A failed teardown must not leave the owner believing a dead container is live.\n if (services) await services.dispose();\n }\n}\n","import path from 'node:path';\n\nimport { PO_MCP_SESSION_ENV_VAR, poMcpSessionEnvironment, readPoMcpSessionConfig } from '@agimon-ai/po-core/mcpSession';\n\nimport type { McpAllowlist, McpSessionConfig } from '../../types/mcpConfig';\n\nfunction asStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const strings = value.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0);\n return strings.length > 0 ? strings : undefined;\n}\n\nfunction readAllowlist(value: unknown): McpAllowlist | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const { servers, proxy } = value as { servers?: unknown; proxy?: unknown };\n const allowlist: McpAllowlist = {};\n const allowedServers = asStringArray(servers);\n const allowedProxy = asStringArray(proxy);\n if (allowedServers) allowlist.servers = allowedServers;\n if (allowedProxy) allowlist.proxy = allowedProxy;\n return allowlist.servers || allowlist.proxy ? allowlist : undefined;\n}\n\n/**\n * Resolves what this session should connect to.\n *\n * Every field falls back to a working default so the extension is usable outside\n * po: a bare Pi session in a repository still gets that repository's\n * `.mcp.json` with no allowlist. A malformed value is treated as absent rather\n * than fatal, because losing MCP is better than losing the session.\n */\nexport function readSessionConfig(\n env: Readonly<Record<string, string | undefined>>,\n defaultRepoRoot: string,\n defaultStagingDirectory: string = path.join(defaultRepoRoot, '.po', 'mcp'),\n): McpSessionConfig {\n const fallback: McpSessionConfig = {\n repoRoot: defaultRepoRoot,\n stagingDirectory: defaultStagingDirectory,\n };\n\n const strict = readPoMcpSessionConfig(env);\n if (strict) {\n const { allowlist, pluginConfigPaths, ...required } = strict;\n const strictAllowlist = readAllowlist(allowlist);\n return {\n ...required,\n ...(pluginConfigPaths?.length ? { pluginConfigPaths: [...pluginConfigPaths] } : {}),\n ...(strictAllowlist ? { allowlist: strictAllowlist } : {}),\n };\n }\n\n const raw = env[PO_MCP_SESSION_ENV_VAR];\n if (!raw) return fallback;\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return fallback;\n }\n if (typeof parsed !== 'object' || parsed === null) return fallback;\n\n const { repoRoot, generatedConfigPath, pluginConfigPaths, allowlist, stagingDirectory } = parsed as Record<\n string,\n unknown\n >;\n const resolvedRoot = typeof repoRoot === 'string' && repoRoot ? repoRoot : fallback.repoRoot;\n const generatedConfig =\n typeof generatedConfigPath === 'string' && generatedConfigPath ? generatedConfigPath : undefined;\n const plugins = asStringArray(pluginConfigPaths);\n const resolvedAllowlist = readAllowlist(allowlist);\n const staging =\n typeof stagingDirectory === 'string' && stagingDirectory ? stagingDirectory : fallback.stagingDirectory;\n\n return {\n repoRoot: resolvedRoot,\n stagingDirectory: staging,\n ...(generatedConfig ? { generatedConfigPath: generatedConfig } : {}),\n ...(plugins ? { pluginConfigPaths: plugins } : {}),\n ...(resolvedAllowlist ? { allowlist: resolvedAllowlist } : {}),\n };\n}\n\n/** Serializes the configuration for the Pi child process po launches. */\nexport function sessionConfigEnvironment(config: McpSessionConfig): Record<string, string> {\n return poMcpSessionEnvironment(config);\n}\n","/** Environment variable carrying a child agent's MCP tool selection. */\nexport const DIRECT_TOOLS_ENV = 'MCP_DIRECT_TOOLS';\n\n/** Explicit \"no MCP tools\", distinct from an unset variable meaning \"no limit\". */\nexport const NO_DIRECT_TOOLS = '__none__';\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,0B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,YAAY,WAAW,WAAW,SAAS;CACpF,MAAM,kBACJ,OAAO,wBAAwB,YAAY,sBAAsB,sBAAsB,KAAA;CACzF,MAAM,UAAU,cAAc,iBAAiB;CAC/C,MAAM,oBAAoB,cAAc,SAAS;CAIjD,OAAO;EACL,UAAU;EACV,kBAJA,OAAO,qBAAqB,YAAY,mBAAmB,mBAAmB,SAAS;EAKvF,GAAI,kBAAkB,EAAE,qBAAqB,gBAAgB,IAAI,CAAC;EAClE,GAAI,UAAU,EAAE,mBAAmB,QAAQ,IAAI,CAAC;EAChD,GAAI,oBAAoB,EAAE,WAAW,kBAAkB,IAAI,CAAC;CAC9D;AACF;;AAGA,SAAgB,yBAAyB,QAAkD;CACzF,QAAA,GAAOC,8BAAAA,wBAAAA,CAAwB,MAAM;AACvC;;;;ACtFA,MAAa,mBAAmB;;AAGhC,MAAa,kBAAkB"}
@@ -1,4 +1,4 @@
1
- import { f as isProxyWrapper, g as repositoryMcpScope, h as projectedSourceMcpScope, m as pluginPathMcpScope, s as MCP_APP_CLIENT_CAPABILITIES, u as PROXY_SERVER_ALIASES } from "./mcpCatalog-vwwMhex1.mjs";
1
+ import { C as withVaultFallback, D as projectedSourceMcpScope, E as pluginPathMcpScope, O as repositoryMcpScope, f as isProxyWrapper, s as MCP_APP_CLIENT_CAPABILITIES, u as PROXY_SERVER_ALIASES } from "./mcpCatalog-Dw_-ka5_.mjs";
2
2
  import { createHash } from "node:crypto";
3
3
  import fs, { readFile } from "node:fs/promises";
4
4
  import path, { join } from "node:path";
@@ -96,7 +96,8 @@ async function layerCacheKey(filePath, format, originalContents, effectiveConten
96
96
  *
97
97
  * Proxy wrapper entries are stripped from `.mcp.json` layers because Po reaches
98
98
  * their upstream config directly. Entries are removed rather than marked disabled,
99
- * so a filtered stdio server is never spawned at all.
99
+ * so a filtered stdio server is never spawned at all. With `vaultFallback`, a plugin
100
+ * layer's unset `${VAR}` secrets become Vault references in the staged copy.
100
101
  */
101
102
  async function filterLayer(filePath, allowed, stagingDirectory, options) {
102
103
  const document = await readConfigDocument(filePath);
@@ -105,10 +106,18 @@ async function filterLayer(filePath, allowed, stagingDirectory, options) {
105
106
  const servers = serverDefinitions(config);
106
107
  const kept = {};
107
108
  const dropped = [];
108
- for (const [name, definition] of Object.entries(servers)) if (options.stripProxyWrappers && isProxyWrapper(name) || !isAllowed(name, allowed)) dropped.push(name);
109
- else kept[name] = definition;
109
+ let rewritten = false;
110
+ for (const [name, definition] of Object.entries(servers)) {
111
+ if (options.stripProxyWrappers && isProxyWrapper(name) || !isAllowed(name, allowed)) {
112
+ dropped.push(name);
113
+ continue;
114
+ }
115
+ const fallback = options.vaultFallback ? withVaultFallback(definition, options.vaultFallback) : void 0;
116
+ if (fallback?.changed) rewritten = true;
117
+ kept[name] = fallback ? fallback.definition : definition;
118
+ }
110
119
  const keptNames = Object.entries(kept).filter(([, definition]) => isEnabledDefinition(definition)).map(([name]) => name);
111
- if (dropped.length === 0) return {
120
+ if (dropped.length === 0 && !rewritten) return {
112
121
  source: {
113
122
  path: filePath,
114
123
  format: "claude",
@@ -202,7 +211,11 @@ async function buildMcpConfigGroups(input) {
202
211
  const droppedServers = [];
203
212
  const diagnostics = [];
204
213
  for (const layer of legacyLayers) {
205
- const filtered = await filterLayer(layer.path, input.allowlist?.servers, input.stagingDirectory, { stripProxyWrappers: true });
214
+ const isPlugin = layer.path !== path.join(input.repoRoot, ".mcp.json");
215
+ const filtered = await filterLayer(layer.path, input.allowlist?.servers, input.stagingDirectory, {
216
+ stripProxyWrappers: true,
217
+ ...isPlugin && input.environment ? { vaultFallback: input.environment } : {}
218
+ });
206
219
  if (!filtered) continue;
207
220
  configSources.push(filtered.source);
208
221
  serverNames.push(...filtered.kept);
@@ -226,9 +239,11 @@ async function buildMcpConfigGroups(input) {
226
239
  diagnostics.push(`Native MCP source "${source.sourceId}" was disabled: the file is missing or its content digest changed.`);
227
240
  continue;
228
241
  }
242
+ const isPlugin = source.owner !== "user" && source.owner !== "repository";
229
243
  const filtered = await filterLayer(source.configPath, input.allowlist?.servers, input.stagingDirectory, {
230
244
  stripProxyWrappers: true,
231
- sourceIdentity: `${source.sourceId}:${source.contentDigest}`
245
+ sourceIdentity: `${source.sourceId}:${source.contentDigest}`,
246
+ ...isPlugin && input.environment ? { vaultFallback: input.environment } : {}
232
247
  });
233
248
  if (!filtered) {
234
249
  diagnostics.push(`Native MCP source "${source.sourceId}" was disabled: the config could not be parsed.`);
@@ -504,4 +519,4 @@ const NO_DIRECT_TOOLS = "__none__";
504
519
  //#endregion
505
520
  export { McpRuntimeOwner as a, mcpRuntime_exports as c, __exportAll as d, sessionConfigEnvironment as i, readCachedCatalog as l, NO_DIRECT_TOOLS as n, definitionsCachePath as o, readSessionConfig as r, hubCallbackSink as s, DIRECT_TOOLS_ENV as t, buildMcpConfigGroups as u };
506
521
 
507
- //# sourceMappingURL=directTools-Dez3RjUJ.mjs.map
522
+ //# sourceMappingURL=directTools-utuNMgg-.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directTools-utuNMgg-.mjs","names":["parseYaml","stringifyYaml"],"sources":["../src/services/configSources/index.ts","../src/services/mcpRuntime/index.ts","../src/services/sessionConfig/index.ts","../src/schemas/directTools.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport fs from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { normalizeAgentPluginMcpSource } from '@agimon-ai/po-config/agentPluginMcp';\nimport type { PoMcpNativeProjectionSource } from '@agimon-ai/po-core/mcpProjection';\nimport { parse as parseYaml, stringify as stringifyYaml } from 'yaml';\n\nimport type { McpConfigGroups, McpConfigGroupsInput, McpConfigSource, McpServerOrigin } from '../../types/mcpConfig';\nimport { pluginPathMcpScope, projectedSourceMcpScope, repositoryMcpScope } from '../mcpScope';\nimport { withVaultFallback } from '../mcpSecrets';\nimport { isProxyWrapper, PROXY_SERVER_ALIASES } from '../proxyWrapper';\n\n// The name check lives in `proxyWrapper` so the edge-safe server config can use it without this file's Node imports.\nexport { isProxyWrapper, PROXY_SERVER_NAME } from '../proxyWrapper';\n\nconst PRIVATE_FILE_MODE = 0o600;\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst DEFAULT_UPSTREAM_CONFIG = 'mcp-config.yaml';\nconst CONFIG_ARGUMENT = '--config';\n\ntype JsonObject = Record<string, unknown>;\n\ninterface FilteredLayer {\n source: McpConfigSource;\n kept: string[];\n dropped: string[];\n}\n\ninterface ConfigDocument {\n config: JsonObject;\n contents: string;\n}\n\nfunction isObject(value: unknown): value is JsonObject {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isYamlPath(filePath: string): boolean {\n const extension = path.extname(filePath).toLowerCase();\n return extension === '.yaml' || extension === '.yml';\n}\n\nasync function readConfigDocument(filePath: string): Promise<ConfigDocument | undefined> {\n try {\n const contents = await fs.readFile(filePath, 'utf8');\n const parsed: unknown = isYamlPath(filePath) ? parseYaml(contents) : JSON.parse(contents);\n return isObject(parsed) ? { config: parsed, contents } : undefined;\n } catch {\n return undefined;\n }\n}\n\nasync function readConfigObject(filePath: string): Promise<JsonObject | undefined> {\n return (await readConfigDocument(filePath))?.config;\n}\n\nfunction serverDefinitions(config: JsonObject | undefined): Record<string, unknown> {\n return isObject(config?.mcpServers) ? config.mcpServers : {};\n}\n\nfunction isEnabledDefinition(definition: unknown): boolean {\n return !isObject(definition) || definition.disabled !== true;\n}\n\n/**\n * Resolves the upstream config referenced by the repository proxy wrapper.\n *\n * The wrapper remains useful to Claude, Codex, and other external clients. Po\n * embeds the same client/runtime code, so it reads this path and connects each\n * declared server itself instead of starting the wrapper as a nested MCP.\n */\nasync function resolveSharedConfigPathFrom(\n repoRoot: string,\n repositoryConfigPath: string,\n): Promise<string | undefined> {\n const servers = serverDefinitions(await readConfigObject(repositoryConfigPath));\n const proxy = [...PROXY_SERVER_ALIASES]\n .map((name) => servers[name])\n .find((definition): definition is JsonObject => isObject(definition));\n const rawArgs: unknown = proxy?.args;\n const args = Array.isArray(rawArgs) ? (rawArgs as unknown[]) : [];\n const configArgumentIndex = args.indexOf(CONFIG_ARGUMENT);\n const declared = args[configArgumentIndex + 1];\n const candidate =\n configArgumentIndex >= 0 && typeof declared === 'string'\n ? path.resolve(repoRoot, declared)\n : path.join(repoRoot, DEFAULT_UPSTREAM_CONFIG);\n try {\n await fs.access(candidate);\n return candidate;\n } catch {\n return undefined;\n }\n}\n\nexport async function resolveSharedConfigPath(repoRoot: string): Promise<string | undefined> {\n return resolveSharedConfigPathFrom(repoRoot, path.join(repoRoot, '.mcp.json'));\n}\n\n/** Empty and absent allowlists both mean \"keep everything\". */\nfunction isAllowed(name: string, allowed: string[] | undefined): boolean {\n return !allowed || allowed.length === 0 || allowed.includes(name);\n}\n\nfunction stagedPath(filePath: string, contents: string, stagingDirectory: string): string {\n // The filtered bytes are part of the identity because two live sessions can\n // select different domains. Sharing a path would let the later one rewrite the\n // configuration underneath the first one's deferred startup.\n const digest = createHash('sha256').update(filePath).update('\\0').update(contents).digest('hex').slice(0, 16);\n const extension = isYamlPath(filePath) ? '.yaml' : '.json';\n return path.join(stagingDirectory, `mcp-${digest}${extension}`);\n}\n\nfunction serializeConfig(filePath: string, config: JsonObject): string {\n return isYamlPath(filePath) ? stringifyYaml(config) : `${JSON.stringify(config, null, 2)}\\n`;\n}\n\nasync function layerCacheKey(\n filePath: string,\n format: McpConfigSource['format'],\n originalContents: string,\n effectiveContents: string,\n sourceIdentity?: string,\n): Promise<string> {\n return createHash('sha256')\n .update(format)\n .update('\\0')\n .update(await fs.realpath(filePath))\n .update('\\0')\n .update(sourceIdentity ?? 'unprojected')\n .update('\\0')\n .update(originalContents)\n .update('\\0')\n .update(effectiveContents)\n .digest('hex');\n}\n\n/**\n * Rewrites one config layer with disallowed servers removed.\n *\n * Proxy wrapper entries are stripped from `.mcp.json` layers because Po reaches\n * their upstream config directly. Entries are removed rather than marked disabled,\n * so a filtered stdio server is never spawned at all. With `vaultFallback`, a plugin\n * layer's unset `${VAR}` secrets become Vault references in the staged copy.\n */\nasync function filterLayer(\n filePath: string,\n allowed: string[] | undefined,\n stagingDirectory: string,\n options: {\n stripProxyWrappers: boolean;\n sourceIdentity?: string;\n vaultFallback?: Readonly<Record<string, string | undefined>>;\n },\n): Promise<FilteredLayer | undefined> {\n const document = await readConfigDocument(filePath);\n if (!document) return undefined;\n const { config, contents: originalContents } = document;\n const servers = serverDefinitions(config);\n const kept: Record<string, unknown> = {};\n const dropped: string[] = [];\n\n let rewritten = false;\n for (const [name, definition] of Object.entries(servers)) {\n const shouldDrop = (options.stripProxyWrappers && isProxyWrapper(name)) || !isAllowed(name, allowed);\n if (shouldDrop) {\n dropped.push(name);\n continue;\n }\n const fallback = options.vaultFallback ? withVaultFallback(definition, options.vaultFallback) : undefined;\n if (fallback?.changed) rewritten = true;\n kept[name] = fallback ? fallback.definition : definition;\n }\n\n const keptNames = Object.entries(kept)\n .filter(([, definition]) => isEnabledDefinition(definition))\n .map(([name]) => name);\n if (dropped.length === 0 && !rewritten) {\n return {\n source: {\n path: filePath,\n format: 'claude',\n cacheKey: await layerCacheKey(filePath, 'claude', originalContents, originalContents, options.sourceIdentity),\n },\n kept: keptNames,\n dropped,\n };\n }\n\n await fs.mkdir(stagingDirectory, { mode: PRIVATE_DIRECTORY_MODE, recursive: true });\n const contents = serializeConfig(filePath, { ...config, mcpServers: kept });\n const target = stagedPath(filePath, contents, stagingDirectory);\n await fs.writeFile(target, contents, { mode: PRIVATE_FILE_MODE });\n return {\n source: {\n path: target,\n format: 'claude',\n cacheKey: await layerCacheKey(filePath, 'claude', originalContents, contents, options.sourceIdentity),\n },\n kept: keptNames,\n dropped,\n };\n}\n\nasync function digestMatches(source: PoMcpNativeProjectionSource): Promise<boolean> {\n try {\n const digest = createHash('sha256')\n .update(await fs.readFile(source.configPath))\n .digest('hex');\n return digest === source.contentDigest;\n } catch {\n return false;\n }\n}\n\nfunction emptyGroups(diagnostics: string[] = []): McpConfigGroups {\n return {\n shared: { configSources: [], configPaths: [], serverNames: [] },\n sessionLocal: { configSources: [], configPaths: [], serverNames: [] },\n droppedServers: [],\n diagnostics,\n serverScopes: {},\n };\n}\n\n/**\n * Resolves every config layer for this session and applies its domain allowlist.\n *\n * All returned layers go into one embedded `@agimon-ai/po-mcp-proxy` client container.\n * The package is used as a library only: its wrapper MCP never becomes a Po MCP\n * server, so status, enable/disable, resources, and OAuth stay attached to each\n * actual downstream server.\n */\nexport async function buildMcpConfigGroups(input: McpConfigGroupsInput): Promise<\n McpConfigGroups & {\n /** Internal only. Paths and revisions must not be forwarded as browser ownership claims. */\n serverOrigins?: Record<string, McpServerOrigin>;\n }\n> {\n if (input.enabled === false) return emptyGroups();\n\n const projectedSources = input.sources;\n const repositoryScope = await repositoryMcpScope(input.repoRoot);\n const legacyLayers = projectedSources\n ? []\n : [\n { path: path.join(input.repoRoot, '.mcp.json'), scope: repositoryScope },\n ...(input.pluginConfigPaths ?? []).map((candidate) => {\n const resolved = path.resolve(input.repoRoot, candidate);\n return { path: resolved, scope: pluginPathMcpScope(resolved) };\n }),\n ];\n // Walked in container order, sessionLocal then shared, so the layer that wins a name owns its credential.\n const serverScopes: Record<string, string> = {};\n const serverOrigins: Record<string, McpServerOrigin> = {};\n const claim = async (\n names: readonly string[],\n scope: string,\n owner: McpServerOrigin['owner'],\n filePath: string,\n sourceId?: string,\n ) => {\n const definitions = serverDefinitions(await readConfigObject(filePath));\n for (const name of names) {\n serverScopes[name] = scope;\n serverOrigins[name] = {\n owner,\n path: filePath,\n revision: createHash('sha256')\n .update(JSON.stringify(definitions[name]) ?? 'undefined')\n .digest('hex'),\n ...(sourceId === undefined ? {} : { sourceId }),\n };\n }\n };\n\n const configSources: McpConfigSource[] = [];\n const serverNames: string[] = [];\n const droppedServers: string[] = [];\n const diagnostics: string[] = [];\n for (const layer of legacyLayers) {\n const isPlugin = layer.path !== path.join(input.repoRoot, '.mcp.json');\n const filtered = await filterLayer(layer.path, input.allowlist?.servers, input.stagingDirectory, {\n stripProxyWrappers: true,\n ...(isPlugin && input.environment ? { vaultFallback: input.environment } : {}),\n });\n if (!filtered) continue;\n configSources.push(filtered.source);\n serverNames.push(...filtered.kept);\n await claim(\n filtered.kept,\n layer.scope,\n layer.path === path.join(input.repoRoot, '.mcp.json') ? 'repository' : 'plugin',\n layer.path,\n );\n droppedServers.push(...filtered.dropped);\n }\n\n for (const source of projectedSources ?? []) {\n if (source.format === 'agent-plugin-v1') {\n const normalized = normalizeAgentPluginMcpSource(source, {\n stagingDirectory: input.stagingDirectory,\n allowedServers: input.allowlist?.servers,\n });\n if (normalized.configSource) configSources.push(normalized.configSource);\n serverNames.push(...normalized.serverNames);\n await claim(\n normalized.serverNames,\n await projectedSourceMcpScope(source, input.repoRoot),\n 'plugin',\n normalized.configSource?.path ?? source.configPath,\n source.sourceId,\n );\n droppedServers.push(...normalized.droppedServers);\n diagnostics.push(...normalized.diagnostics);\n continue;\n }\n\n if (!(await digestMatches(source))) {\n diagnostics.push(\n `Native MCP source \"${source.sourceId}\" was disabled: the file is missing or its content digest changed.`,\n );\n continue;\n }\n const isPlugin = source.owner !== 'user' && source.owner !== 'repository';\n const filtered = await filterLayer(source.configPath, input.allowlist?.servers, input.stagingDirectory, {\n stripProxyWrappers: true,\n sourceIdentity: `${source.sourceId}:${source.contentDigest}`,\n ...(isPlugin && input.environment ? { vaultFallback: input.environment } : {}),\n });\n if (!filtered) {\n diagnostics.push(`Native MCP source \"${source.sourceId}\" was disabled: the config could not be parsed.`);\n continue;\n }\n configSources.push(filtered.source);\n serverNames.push(...filtered.kept);\n await claim(\n filtered.kept,\n await projectedSourceMcpScope(source, input.repoRoot),\n source.owner === 'user' ? 'user' : source.owner === 'repository' ? 'repository' : 'plugin',\n source.configPath,\n source.sourceId,\n );\n droppedServers.push(...filtered.dropped);\n }\n\n const repositorySource = projectedSources?.find(\n (source): source is PoMcpNativeProjectionSource => source.format === 'native' && source.owner === 'repository',\n );\n const upstreamPath = projectedSources\n ? repositorySource && (await digestMatches(repositorySource))\n ? await resolveSharedConfigPathFrom(input.repoRoot, repositorySource.configPath)\n : undefined\n : await resolveSharedConfigPath(input.repoRoot);\n const upstream = upstreamPath\n ? await filterLayer(upstreamPath, input.allowlist?.proxy, input.stagingDirectory, { stripProxyWrappers: true })\n : undefined;\n if (upstream) {\n droppedServers.push(...upstream.dropped);\n // The repository's mcp-config.yaml belongs to the repository layer.\n await claim(upstream.kept, repositoryScope, 'upstream', upstreamPath!);\n }\n\n return {\n shared: {\n configSources: upstream ? [upstream.source] : [],\n configPaths: upstream ? [upstream.source.path] : [],\n serverNames: upstream ? upstream.kept : [],\n },\n // A later layer overriding an earlier one contributes the same name twice.\n sessionLocal: {\n configSources,\n configPaths: configSources.map((source) => source.path),\n serverNames: [...new Set(serverNames)],\n },\n droppedServers: [...new Set(droppedServers)],\n diagnostics,\n serverScopes,\n serverOrigins,\n };\n}\n","import { createHash } from 'node:crypto';\nimport { readFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { join } from 'node:path';\n\nimport type { PoOAuthRedirect } from '@agimon-ai/po-core/packageApi';\nimport type {\n ConfigSource,\n McpClientManagerAuthOptions,\n McpOutputSchemaWarning,\n McpSecretTarget,\n McpServerStateChange,\n McpToolInfo,\n OAuthCallbackSink,\n SharedServices,\n TokenStore,\n} from '@agimon-ai/po-mcp-proxy';\nimport mcpProxyPackage from '@agimon-ai/po-mcp-proxy/package.json' with { type: 'json' };\n\nimport { MCP_APP_CLIENT_CAPABILITIES } from '../../constants/mcp';\nimport type { McpConfigSource } from '../../types/mcpConfig';\nimport type { CachedCatalog } from '../../types/mcpRuntime';\n\n/**\n * Presents the hub's redirect surface as the proxy's callback collaborator.\n *\n * `listen` binds nothing: the hub already serves the address this advertises,\n * so opening a loopback port would only create one nobody redirects to.\n */\nexport function hubCallbackSink(redirect: PoOAuthRedirect): OAuthCallbackSink {\n return {\n redirectUri: () => redirect.redirectUri,\n getPort: () => undefined,\n listen: (preferredPort) => Promise.resolve(preferredPort),\n reserve: (state, timeoutMs) => redirect.reserve(state, timeoutMs),\n waitForCallback: (state, timeoutMs) => redirect.wait(state, timeoutMs),\n cancel: (state) => redirect.cancel(state),\n };\n}\n\nexport interface McpRuntimeOptions {\n /** Ordered config layers. Later layers override earlier ones. */\n configSources: McpConfigSource[];\n workspaceRoot?: string;\n /** Only an explicit session-only server add may start without file sources. */\n allowEmpty?: boolean;\n /** Exact session directory, independent of the checkout used for configuration. */\n executionCwd?: string;\n environment?: Readonly<Record<string, string | undefined>>;\n /**\n * Required: without one the proxy would fall back to its own file store under\n * `~/.mcp-proxy`, and Po keeps credentials only in the vault or in memory.\n */\n tokenStore: TokenStore;\n /**\n * Where OAuth redirects are received. Omitted, the proxy binds its own\n * loopback listener, which only a browser on this machine can reach.\n */\n callbackServer?: OAuthCallbackSink;\n /** Resolves `${vault:NAME}` references at connect time. Without it, every reference fails its connection. */\n resolveSecret?: (target: McpSecretTarget) => Promise<string | undefined>;\n resolveUrlCredentials?: McpClientManagerAuthOptions['resolveUrlCredentials'];\n onAuthorizationUrl?: (url: URL, serverName: string) => void;\n onServerStateChange?: (change: McpServerStateChange) => void;\n onOutputSchemaWarning?: (warning: McpOutputSchemaWarning) => void;\n}\n\nexport interface McpRuntimeHandle {\n generation: number;\n services: SharedServices;\n /** Resolves once the first connection pass settles. Never rejects. */\n connectionsSettled: Promise<void>;\n}\n\ninterface DefinitionsCacheFile {\n oneMcpVersion?: string;\n servers?: Record<string, { serverName: string; tools?: McpToolInfo[] }>;\n}\n\n/**\n * Definitions cache path shared by Po's synchronous warm reader and mcp-proxy.\n *\n * Generated staging paths are deliberately absent: projected source content must\n * invalidate a reused path, while identical portable content must survive a new\n * private staging directory. Stable source origins are carried inside each cache\n * key; format and merge behavior remain part of the ordered identity.\n */\nexport function definitionsCachePath(configSources: readonly McpConfigSource[]): string {\n if (configSources.length === 0) throw new Error('definitionsCachePath requires at least one config source');\n const digest = createHash('sha256')\n .update(\n JSON.stringify(\n configSources.map((source) => ({\n cacheKey: source.cacheKey,\n format: source.format,\n optional: source.optional ?? false,\n mergeStrategy: source.mergeStrategy ?? 'remote-priority',\n })),\n ),\n )\n .update('\\0')\n .update(mcpProxyPackage.version)\n .update('\\0')\n .update(JSON.stringify(MCP_APP_CLIENT_CAPABILITIES))\n .digest('hex');\n return join(homedir(), '.mcp-proxy', `po-${digest}.definitions-cache.json`);\n}\n\n/**\n * Reads the catalog the previous run left behind.\n *\n * Callers await the cache before registering tools. A miss is normal on a first\n * run and resolves to an empty catalog rather than an error.\n *\n * The file path is content-addressed from the current ordered layers, and its proxy\n * version is checked before any schema is registered. Servers filtered out of the\n * current configuration are also excluded later by `McpCatalog.seed`.\n */\nexport async function readCachedCatalog(\n configSources: readonly McpConfigSource[],\n cachePathFor: (sources: readonly McpConfigSource[]) => string = definitionsCachePath,\n): Promise<CachedCatalog> {\n if (configSources.length === 0) return { servers: [] };\n try {\n const cachePath = cachePathFor(configSources);\n const cache = JSON.parse(await readFile(cachePath, 'utf8')) as Partial<DefinitionsCacheFile>;\n if (cache.oneMcpVersion !== mcpProxyPackage.version) return { servers: [] };\n const servers = Object.values(cache.servers ?? {}).map((server) => ({\n name: server.serverName,\n tools: server.tools ?? [],\n }));\n return { servers };\n } catch {\n return { servers: [] };\n }\n}\n\nfunction toProxyConfigSource(source: McpConfigSource): ConfigSource {\n return {\n path: source.path,\n format: source.format,\n ...(source.optional === undefined ? {} : { optional: source.optional }),\n ...(source.mergeStrategy === undefined ? {} : { mergeStrategy: source.mergeStrategy }),\n };\n}\n\n/**\n * Owns the one live mcp-proxy container for this extension.\n *\n * Pi reloads extensions in process, so a connect that lands after a session restart\n * or a `/domains` switch would otherwise fold tools into a dead context. Every start\n * takes the next generation; anything an older generation produces is dropped and its\n * container disposed.\n */\nexport class McpRuntimeOwner {\n private generation = 0;\n private active: SharedServices | undefined;\n private unsubscribe: (() => void) | undefined;\n\n get currentGeneration(): number {\n return this.generation;\n }\n\n /** The live container, or undefined before the first start and after dispose. */\n getServices(): SharedServices | undefined {\n return this.active;\n }\n\n /**\n * Whether a container a caller captured earlier is still the live one.\n *\n * An async continuation that started under one container has to check this\n * before writing its result, or a `/domains` switch would fold stale tools into\n * the new session.\n */\n isCurrent(services: SharedServices | undefined): boolean {\n return services !== undefined && services === this.active;\n }\n\n /**\n * Starts a container for the current configuration, replacing any predecessor.\n *\n * Returns undefined when a newer generation started while this one was building,\n * which is the signal for the caller to abandon its half-finished work.\n */\n async start(options: McpRuntimeOptions): Promise<McpRuntimeHandle | undefined> {\n if (!options.tokenStore) throw new Error('The MCP runtime needs a token store.');\n const generation = ++this.generation;\n // Retired before the replacement is built so two containers never hold the same\n // stdio children open at once.\n await this.retire();\n if (options.configSources.length === 0 && !options.allowEmpty) return undefined;\n\n // The proxy container pulls in transports, OAuth, schema conversion, and\n // server implementations. Cached tool registration needs none of those, so\n // load the runtime only after session_start has yielded control to Pi.\n const { createProxyContainer } = await import('@agimon-ai/po-mcp-proxy');\n const cachePath = options.configSources.length > 0 ? definitionsCachePath(options.configSources) : undefined;\n const containerOptions = {\n configSources: options.configSources.map(toProxyConfigSource),\n workspaceRoot: options.workspaceRoot,\n executionCwd: options.executionCwd,\n environment: options.environment,\n definitionsCachePath: cachePath,\n // Never blocking: an unreachable server must not delay Pi's first prompt.\n startupMode: 'background' as const,\n clientCapabilities: MCP_APP_CLIENT_CAPABILITIES,\n outputSchemaValidation: {\n mode: 'warn' as const,\n onWarning: (warning: McpOutputSchemaWarning) => {\n if (generation === this.generation) options.onOutputSchemaWarning?.(warning);\n },\n },\n auth: {\n tokenStore: options.tokenStore,\n onAuthorizationUrl: options.onAuthorizationUrl,\n ...(options.callbackServer ? { callbackServer: options.callbackServer } : {}),\n ...(options.resolveSecret ? { resolveSecret: options.resolveSecret } : {}),\n ...(options.resolveUrlCredentials ? { resolveUrlCredentials: options.resolveUrlCredentials } : {}),\n },\n };\n const services = await createProxyContainer(containerOptions);\n\n if (generation !== this.generation) {\n await services.dispose();\n return undefined;\n }\n\n this.active = services;\n const forward = options.onServerStateChange;\n if (forward) {\n this.unsubscribe = services.clientManager.onServerStateChange((change) => {\n if (generation === this.generation) forward(change);\n });\n }\n\n return { generation, services, connectionsSettled: services.connectionsSettled };\n }\n\n /** Tears the container down and invalidates every generation still in flight. */\n async dispose(): Promise<void> {\n ++this.generation;\n await this.retire();\n }\n\n private async retire(): Promise<void> {\n this.unsubscribe?.();\n this.unsubscribe = undefined;\n const services = this.active;\n this.active = undefined;\n // A failed teardown must not leave the owner believing a dead container is live.\n if (services) await services.dispose();\n }\n}\n","import path from 'node:path';\n\nimport { PO_MCP_SESSION_ENV_VAR, poMcpSessionEnvironment, readPoMcpSessionConfig } from '@agimon-ai/po-core/mcpSession';\n\nimport type { McpAllowlist, McpSessionConfig } from '../../types/mcpConfig';\n\nfunction asStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const strings = value.filter((entry): entry is string => typeof entry === 'string' && entry.length > 0);\n return strings.length > 0 ? strings : undefined;\n}\n\nfunction readAllowlist(value: unknown): McpAllowlist | undefined {\n if (typeof value !== 'object' || value === null) return undefined;\n const { servers, proxy } = value as { servers?: unknown; proxy?: unknown };\n const allowlist: McpAllowlist = {};\n const allowedServers = asStringArray(servers);\n const allowedProxy = asStringArray(proxy);\n if (allowedServers) allowlist.servers = allowedServers;\n if (allowedProxy) allowlist.proxy = allowedProxy;\n return allowlist.servers || allowlist.proxy ? allowlist : undefined;\n}\n\n/**\n * Resolves what this session should connect to.\n *\n * Every field falls back to a working default so the extension is usable outside\n * po: a bare Pi session in a repository still gets that repository's\n * `.mcp.json` with no allowlist. A malformed value is treated as absent rather\n * than fatal, because losing MCP is better than losing the session.\n */\nexport function readSessionConfig(\n env: Readonly<Record<string, string | undefined>>,\n defaultRepoRoot: string,\n defaultStagingDirectory: string = path.join(defaultRepoRoot, '.po', 'mcp'),\n): McpSessionConfig {\n const fallback: McpSessionConfig = {\n repoRoot: defaultRepoRoot,\n stagingDirectory: defaultStagingDirectory,\n };\n\n const strict = readPoMcpSessionConfig(env);\n if (strict) {\n const { allowlist, pluginConfigPaths, ...required } = strict;\n const strictAllowlist = readAllowlist(allowlist);\n return {\n ...required,\n ...(pluginConfigPaths?.length ? { pluginConfigPaths: [...pluginConfigPaths] } : {}),\n ...(strictAllowlist ? { allowlist: strictAllowlist } : {}),\n };\n }\n\n const raw = env[PO_MCP_SESSION_ENV_VAR];\n if (!raw) return fallback;\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return fallback;\n }\n if (typeof parsed !== 'object' || parsed === null) return fallback;\n\n const { repoRoot, generatedConfigPath, pluginConfigPaths, allowlist, stagingDirectory } = parsed as Record<\n string,\n unknown\n >;\n const resolvedRoot = typeof repoRoot === 'string' && repoRoot ? repoRoot : fallback.repoRoot;\n const generatedConfig =\n typeof generatedConfigPath === 'string' && generatedConfigPath ? generatedConfigPath : undefined;\n const plugins = asStringArray(pluginConfigPaths);\n const resolvedAllowlist = readAllowlist(allowlist);\n const staging =\n typeof stagingDirectory === 'string' && stagingDirectory ? stagingDirectory : fallback.stagingDirectory;\n\n return {\n repoRoot: resolvedRoot,\n stagingDirectory: staging,\n ...(generatedConfig ? { generatedConfigPath: generatedConfig } : {}),\n ...(plugins ? { pluginConfigPaths: plugins } : {}),\n ...(resolvedAllowlist ? { allowlist: resolvedAllowlist } : {}),\n };\n}\n\n/** Serializes the configuration for the Pi child process po launches. */\nexport function sessionConfigEnvironment(config: McpSessionConfig): Record<string, string> {\n return poMcpSessionEnvironment(config);\n}\n","/** Environment variable carrying a child agent's MCP tool selection. */\nexport const DIRECT_TOOLS_ENV = 'MCP_DIRECT_TOOLS';\n\n/** Explicit \"no MCP tools\", distinct from an unset variable meaning \"no limit\". */\nexport const NO_DIRECT_TOOLS = '__none__';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgBA,MAAM,oBAAoB;AAC1B,MAAM,yBAAyB;AAC/B,MAAM,0BAA0B;AAChC,MAAM,kBAAkB;AAexB,SAAS,SAAS,OAAqC;CACrD,OA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OSITORY_API_PATH = "/repository";
107
107
  const MCP_DISCOVERY_API_PATH = "/repository/discover";
108
108
  const MCP_AUTHORIZATION_API_PATH = "/repository/authorize";
109
+ /** Stores one key a configured server asks for, without a session. */
110
+ const MCP_REPOSITORY_SECRETS_API_PATH = "/repository/secrets";
109
111
  /** The repository every route is asked about, and the flow segment the two flow routes carry. */
110
112
  const MCP_REPOSITORY_ID_QUERY = "repositoryId";
111
113
  const MCP_FLOW_ID_PARAM = "flowId";
@@ -167,6 +169,12 @@ const routes = {
167
169
  path: MCP_AUTHORIZATION_API_PATH,
168
170
  response: void 0
169
171
  },
172
+ /** Stores one key a configured server asks for, bound to its destination. Owner-only; never echoed. */
173
+ repositorySecret: {
174
+ method: "POST",
175
+ path: MCP_REPOSITORY_SECRETS_API_PATH,
176
+ response: void 0
177
+ },
170
178
  readAuthorization: {
171
179
  method: "GET",
172
180
  path: AUTHORIZATION_FLOW_PATH,