@humain/terminal 0.0.3-beta.2 → 0.0.4-beta.1

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 (136) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/bun/cli.d.ts.map +1 -1
  3. package/dist/bun/cli.js +0 -1
  4. package/dist/bun/cli.js.map +1 -1
  5. package/dist/core/agent-session.d.ts.map +1 -1
  6. package/dist/core/agent-session.js +7 -1
  7. package/dist/core/agent-session.js.map +1 -1
  8. package/dist/core/sdk.d.ts.map +1 -1
  9. package/dist/core/sdk.js +1 -1
  10. package/dist/core/sdk.js.map +1 -1
  11. package/dist/core/session-manager.d.ts +4 -0
  12. package/dist/core/session-manager.d.ts.map +1 -1
  13. package/dist/core/session-manager.js +46 -22
  14. package/dist/core/session-manager.js.map +1 -1
  15. package/dist/core/tools/index.d.ts +2 -1
  16. package/dist/core/tools/index.d.ts.map +1 -1
  17. package/dist/core/tools/index.js +9 -1
  18. package/dist/core/tools/index.js.map +1 -1
  19. package/dist/core/tools/subagent.d.ts +82 -0
  20. package/dist/core/tools/subagent.d.ts.map +1 -0
  21. package/dist/core/tools/subagent.js +980 -0
  22. package/dist/core/tools/subagent.js.map +1 -0
  23. package/dist/humain/bedrock-provider/vendor/index.bundle.d.mts +3 -0
  24. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +1509 -0
  25. package/dist/humain/index.d.ts.map +1 -1
  26. package/dist/humain/index.js +3 -0
  27. package/dist/humain/index.js.map +1 -1
  28. package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +36 -0
  29. package/dist/humain/mcp-adapter/vendor/README.md +47 -5
  30. package/dist/humain/mcp-adapter/vendor/cli.js +163 -1
  31. package/dist/humain/mcp-adapter/vendor/commands.ts +128 -22
  32. package/dist/humain/mcp-adapter/vendor/config.ts +25 -7
  33. package/dist/humain/mcp-adapter/vendor/direct-tools.ts +5 -4
  34. package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +1663 -458
  35. package/dist/humain/mcp-adapter/vendor/index.ts +219 -32
  36. package/dist/humain/mcp-adapter/vendor/init.ts +36 -4
  37. package/dist/humain/mcp-adapter/vendor/lifecycle.ts +315 -24
  38. package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +39 -6
  39. package/dist/humain/mcp-adapter/vendor/mcp-bearer-store.ts +387 -0
  40. package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +27 -3
  41. package/dist/humain/mcp-adapter/vendor/mcp-code.ts +4 -0
  42. package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +42 -13
  43. package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +32 -21
  44. package/dist/humain/mcp-adapter/vendor/package-mcp-loader.ts +168 -0
  45. package/dist/humain/mcp-adapter/vendor/package.json +179 -177
  46. package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +5 -4
  47. package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +31 -37
  48. package/dist/humain/mcp-adapter/vendor/search-ranking.ts +92 -22
  49. package/dist/humain/mcp-adapter/vendor/server-manager.ts +140 -2
  50. package/dist/humain/mcp-adapter/vendor/session-recovery.ts +7 -0
  51. package/dist/humain/mcp-adapter/vendor/tool-approval.ts +15 -2
  52. package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +44 -4
  53. package/dist/humain/mcp-adapter/vendor/types.ts +2 -0
  54. package/dist/humain/mcp-adapter/vendor/ui-server.ts +18 -16
  55. package/dist/humain/mcp-adapter/vendor/utils.ts +70 -0
  56. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
  57. package/dist/humain/web-access/vendor/anysearch.js +3 -2
  58. package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
  59. package/dist/humain/web-access/vendor/brave.d.ts.map +1 -1
  60. package/dist/humain/web-access/vendor/brave.js +14 -4
  61. package/dist/humain/web-access/vendor/brave.js.map +1 -1
  62. package/dist/humain/web-access/vendor/curator-page.d.ts +3 -0
  63. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  64. package/dist/humain/web-access/vendor/curator-page.js +4 -1
  65. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  66. package/dist/humain/web-access/vendor/curator-server.d.ts +3 -0
  67. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  68. package/dist/humain/web-access/vendor/curator-server.js +6 -0
  69. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  70. package/dist/humain/web-access/vendor/exa.d.ts.map +1 -1
  71. package/dist/humain/web-access/vendor/exa.js +16 -7
  72. package/dist/humain/web-access/vendor/exa.js.map +1 -1
  73. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  74. package/dist/humain/web-access/vendor/extract.js +31 -3
  75. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  76. package/dist/humain/web-access/vendor/gemini-search.d.ts +2 -2
  77. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  78. package/dist/humain/web-access/vendor/gemini-search.js +25 -4
  79. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  80. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  81. package/dist/humain/web-access/vendor/index.js +36 -49
  82. package/dist/humain/web-access/vendor/index.js.map +1 -1
  83. package/dist/humain/web-access/vendor/page-query.d.ts +1 -2
  84. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  85. package/dist/humain/web-access/vendor/page-query.js +5 -2
  86. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  87. package/dist/humain/web-access/vendor/parallel-mcp.d.ts +10 -0
  88. package/dist/humain/web-access/vendor/parallel-mcp.d.ts.map +1 -0
  89. package/dist/humain/web-access/vendor/parallel-mcp.js +224 -0
  90. package/dist/humain/web-access/vendor/parallel-mcp.js.map +1 -0
  91. package/dist/humain/web-access/vendor/parallel.d.ts +1 -0
  92. package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -1
  93. package/dist/humain/web-access/vendor/parallel.js +2 -2
  94. package/dist/humain/web-access/vendor/parallel.js.map +1 -1
  95. package/dist/humain/web-access/vendor/query-rewrite.d.ts +3 -0
  96. package/dist/humain/web-access/vendor/query-rewrite.d.ts.map +1 -0
  97. package/dist/humain/web-access/vendor/query-rewrite.js +42 -0
  98. package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -0
  99. package/dist/humain/web-access/vendor/serper.d.ts +4 -0
  100. package/dist/humain/web-access/vendor/serper.d.ts.map +1 -0
  101. package/dist/humain/web-access/vendor/serper.js +206 -0
  102. package/dist/humain/web-access/vendor/serper.js.map +1 -0
  103. package/dist/humain/web-access/vendor/summary-model-scope.d.ts +5 -0
  104. package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -1
  105. package/dist/humain/web-access/vendor/summary-model-scope.js +10 -5
  106. package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -1
  107. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
  108. package/dist/humain/web-access/vendor/summary-review.js +40 -14
  109. package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
  110. package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -1
  111. package/dist/humain/web-access/vendor/tavily.js +14 -4
  112. package/dist/humain/web-access/vendor/tavily.js.map +1 -1
  113. package/dist/humain/web-access/vendor/utils.d.ts +10 -0
  114. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  115. package/dist/humain/web-access/vendor/utils.js +70 -0
  116. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  117. package/dist/humain/web-access/vendor/valyu.d.ts +6 -0
  118. package/dist/humain/web-access/vendor/valyu.d.ts.map +1 -0
  119. package/dist/humain/web-access/vendor/valyu.js +194 -0
  120. package/dist/humain/web-access/vendor/valyu.js.map +1 -0
  121. package/docs/extensions.md +1 -1
  122. package/examples/extensions/README.md +1 -1
  123. package/examples/extensions/subagent/README.md +24 -147
  124. package/npm-shrinkwrap.json +7 -2
  125. package/package.json +7 -2
  126. package/src/humain/mcp-adapter/UPSTREAM.md +1 -1
  127. package/src/humain/mcp-adapter/upstream.json +3 -3
  128. package/src/humain/mcp-adapter/vendor/CHANGELOG.md +36 -0
  129. package/src/humain/web-access/UPSTREAM.md +1 -1
  130. package/src/humain/web-access/upstream.json +4 -4
  131. package/dist/bun/register-bedrock.d.ts +0 -2
  132. package/dist/bun/register-bedrock.d.ts.map +0 -1
  133. package/dist/bun/register-bedrock.js +0 -4
  134. package/dist/bun/register-bedrock.js.map +0 -1
  135. package/examples/extensions/subagent/agents.ts +0 -126
  136. package/examples/extensions/subagent/index.ts +0 -1015
@@ -0,0 +1,168 @@
1
+ import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
2
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
3
+ import stripJsonComments from "strip-json-comments";
4
+ import { getAgentDir, getConfigDirName } from "./agent-dir.ts";
5
+ import type { McpConfig, ServerEntry } from "./types.ts";
6
+
7
+ interface PackageSetting {
8
+ source: string;
9
+ }
10
+
11
+ interface PackageManifest {
12
+ name?: unknown;
13
+ pi?: { mcp?: unknown };
14
+ }
15
+
16
+ export function loadPackageMcpConfigs(cwd = process.cwd()): McpConfig {
17
+ const mcpServers: Record<string, ServerEntry> = {};
18
+ const seen = new Set<string>();
19
+
20
+ for (const packageRoot of getConfiguredPackageRoots(cwd)) {
21
+ const manifest = readPackageManifest(packageRoot);
22
+ if (!manifest || typeof manifest.name !== "string" || !manifest.name) continue;
23
+ const paths = getManifestMcpPaths(manifest.pi?.mcp, manifest.name);
24
+ if (!paths) continue;
25
+
26
+ const packagePrefix = formatPackageName(manifest.name);
27
+ const packageServers = new Set<string>();
28
+ for (const path of paths) {
29
+ const configPath = resolvePackageConfigPath(packageRoot, path);
30
+ if (!configPath) {
31
+ console.warn(`Pi package ${manifest.name} skips MCP config ${path}: file must stay inside the package`);
32
+ continue;
33
+ }
34
+
35
+ const config = readMcpConfig(configPath, manifest.name);
36
+ if (!config) continue;
37
+ for (const [serverName, server] of Object.entries(config.mcpServers)) {
38
+ const normalizedName = `${packagePrefix}__${formatServerName(serverName)}`;
39
+ if (packageServers.has(normalizedName) || seen.has(normalizedName)) {
40
+ console.warn(`Pi package ${manifest.name} skips duplicate normalized MCP server ${normalizedName}`);
41
+ continue;
42
+ }
43
+ packageServers.add(normalizedName);
44
+ seen.add(normalizedName);
45
+ mcpServers[normalizedName] = server;
46
+ }
47
+ }
48
+ }
49
+
50
+ return { mcpServers };
51
+ }
52
+
53
+ function getConfiguredPackageRoots(cwd: string): string[] {
54
+ const roots: string[] = [];
55
+ for (const [settingsPath, scope] of [
56
+ [join(cwd, getConfigDirName(), "settings.json"), "project"],
57
+ [join(getAgentDir(), "settings.json"), "user"],
58
+ ] as const) {
59
+ const settings = readOptionalJson(settingsPath, `${scope} Pi settings`);
60
+ if (settings === undefined) continue;
61
+ if (typeof settings !== "object" || settings === null || Array.isArray(settings)) {
62
+ throw new Error(`${scope} Pi settings ${settingsPath} must be a JSON object`);
63
+ }
64
+ const packages = (settings as { packages?: unknown }).packages;
65
+ if (packages === undefined) continue;
66
+ if (!Array.isArray(packages)) throw new Error(`${scope} Pi settings ${settingsPath} packages must be an array`);
67
+ for (const entry of packages) {
68
+ const source = typeof entry === "string"
69
+ ? entry
70
+ : entry && typeof entry === "object" && !Array.isArray(entry) && typeof (entry as PackageSetting).source === "string"
71
+ ? (entry as PackageSetting).source
72
+ : undefined;
73
+ if (!source) throw new Error(`${scope} Pi settings ${settingsPath} package entries must be strings or objects with a string source`);
74
+ const root = resolvePackageRoot(source, scope, cwd);
75
+ if (root && !roots.includes(root)) roots.push(root);
76
+ }
77
+ }
78
+ return roots;
79
+ }
80
+
81
+ function resolvePackageRoot(source: string, scope: "user" | "project", cwd: string): string | null {
82
+ const baseDir = scope === "user" ? getAgentDir() : join(cwd, getConfigDirName());
83
+ if (source.startsWith("npm:")) {
84
+ const name = source.slice(4).trim().match(/^(@?[^@]+(?:\/[^@]+)?)/)?.[1];
85
+ return name ? resolveContainedPath(join(baseDir, "npm", "node_modules"), name) : null;
86
+ }
87
+ const gitSource = source.startsWith("git:")
88
+ ? source.slice(4).trim()
89
+ : /^(?:(?:https?|ssh):\/\/|git@[^:]+:)/.test(source) ? source : null;
90
+ if (gitSource) {
91
+ const value = gitSource
92
+ .replace(/^ssh:\/\/git@/, "")
93
+ .replace(/^git@([^:]+):/, "$1/")
94
+ .replace(/^[a-z]+:\/\//i, "");
95
+ const path = value.replace(/@[^/]+$/, "").replace(/\.git$/, "");
96
+ return path && !path.startsWith("/") ? resolveContainedPath(join(baseDir, "git"), path) : null;
97
+ }
98
+ return isAbsolute(source) ? resolve(source) : resolve(baseDir, source);
99
+ }
100
+
101
+ function readPackageManifest(packageRoot: string): PackageManifest | null {
102
+ const manifest = readOptionalJson(join(packageRoot, "package.json"), `Pi package manifest ${packageRoot}`);
103
+ return manifest && typeof manifest === "object" && !Array.isArray(manifest) ? manifest as PackageManifest : null;
104
+ }
105
+
106
+ function getManifestMcpPaths(value: unknown, packageName: string): string[] | null {
107
+ const paths = typeof value === "string" ? [value] : Array.isArray(value) && value.every((path): path is string => typeof path === "string") ? value : null;
108
+ if (value !== undefined && !paths) console.warn(`Pi package ${packageName} ignores invalid pi.mcp manifest entry`);
109
+ return paths;
110
+ }
111
+
112
+ function readMcpConfig(path: string, packageName: string): McpConfig | null {
113
+ const config = readRequiredJson(path, `Pi package ${packageName} MCP config`);
114
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
115
+ throw new Error(`Pi package ${packageName} MCP config ${path} must be a JSON object`);
116
+ }
117
+ const servers = (config as { mcpServers?: unknown }).mcpServers;
118
+ if (!servers || typeof servers !== "object" || Array.isArray(servers)) {
119
+ throw new Error(`Pi package ${packageName} MCP config ${path} must contain a JSON object mcpServers field`);
120
+ }
121
+ const mcpServers: Record<string, ServerEntry> = {};
122
+ for (const [name, server] of Object.entries(servers)) {
123
+ if (!server || typeof server !== "object" || Array.isArray(server)) {
124
+ throw new Error(`Pi package ${packageName} MCP config ${path} server ${name} must be a JSON object`);
125
+ }
126
+ mcpServers[name] = server as ServerEntry;
127
+ }
128
+ return { mcpServers };
129
+ }
130
+
131
+ function readRequiredJson(path: string, description: string): unknown {
132
+ try {
133
+ return JSON.parse(stripJsonComments(readFileSync(path, "utf8"), { trailingCommas: true }));
134
+ } catch (error) {
135
+ throw new Error(`${description} ${path} contains invalid JSON: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
136
+ }
137
+ }
138
+
139
+ function readOptionalJson(path: string, description: string): unknown | undefined {
140
+ if (!existsSync(path)) return undefined;
141
+ return readRequiredJson(path, description);
142
+ }
143
+
144
+ function resolveContainedPath(root: string, path: string): string | null {
145
+ const resolved = resolve(root, path);
146
+ const rel = relative(root, resolved);
147
+ return rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep) && !isAbsolute(rel)) ? resolved : null;
148
+ }
149
+
150
+ function resolvePackageConfigPath(packageRoot: string, path: string): string | null {
151
+ const lexicalPath = resolveContainedPath(packageRoot, path);
152
+ if (!lexicalPath || !existsSync(lexicalPath) || !statSync(lexicalPath).isFile()) return null;
153
+ try {
154
+ const realPackageRoot = realpathSync(packageRoot);
155
+ const realConfigPath = realpathSync(lexicalPath);
156
+ return resolveContainedPath(realPackageRoot, realConfigPath);
157
+ } catch {
158
+ return null;
159
+ }
160
+ }
161
+
162
+ function formatPackageName(name: string): string {
163
+ return name.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "package";
164
+ }
165
+
166
+ function formatServerName(name: string): string {
167
+ return name.replace(/[^A-Za-z0-9_-]+/g, "_").replace(/^[_-]+|[_-]+$/g, "") || "server";
168
+ }
@@ -1,179 +1,181 @@
1
1
  {
2
- "name": "pi-mcp-adapter",
3
- "version": "2.26.0",
4
- "description": "MCP (Model Context Protocol) adapter extension for Pi coding agent",
5
- "type": "module",
6
- "types": "./index.ts",
7
- "exports": {
8
- ".": {
9
- "types": "./index.ts",
10
- "import": "./index.ts",
11
- "default": "./index.ts"
12
- },
13
- "./types": {
14
- "types": "./types.ts",
15
- "import": "./types.ts",
16
- "default": "./types.ts"
17
- },
18
- "./oauth": {
19
- "types": "./oauth.ts",
20
- "import": "./oauth.ts",
21
- "default": "./oauth.ts"
22
- }
23
- },
24
- "license": "MIT",
25
- "author": "Nico Bailon",
26
- "engines": {
27
- "node": ">=20"
28
- },
29
- "bin": {
30
- "pi-mcp-adapter": "cli.js"
31
- },
32
- "scripts": {
33
- "typecheck": "tsc --noEmit",
34
- "test": "vitest run",
35
- "test:watch": "vitest",
36
- "test:coverage": "vitest run --coverage",
37
- "test:oauth": "PI_MCP_ADAPTER_TEST_AUTH_STORE=memory PI_MCP_ADAPTER_DISABLE_AUTH_CACHE=1 node --import tsx --test --test-concurrency=1 oauth-public-api.test.ts mcp-auth.test.ts mcp-auth-flow.test.ts mcp-callback-server.test.ts mcp-oauth-provider.test.ts",
38
- "test:oauth-provider": "PI_MCP_ADAPTER_TEST_AUTH_STORE=memory PI_MCP_ADAPTER_DISABLE_AUTH_CACHE=1 node --import tsx --test mcp-oauth-provider.test.ts",
39
- "test:conformance": "bash conformance/run.sh"
40
- },
41
- "repository": {
42
- "type": "git",
43
- "url": "git+https://github.com/nicobailon/pi-mcp-adapter.git"
44
- },
45
- "keywords": [
46
- "pi-package",
47
- "pi",
48
- "mcp",
49
- "model-context-protocol",
50
- "ai",
51
- "coding-agent",
52
- "extension",
53
- "claude",
54
- "llm"
55
- ],
56
- "pi": {
57
- "extensions": [
58
- "./index.ts"
59
- ],
60
- "skills": [
61
- "./skills"
62
- ],
63
- "video": "https://github.com/nicobailon/pi-mcp-adapter/raw/refs/heads/main/pi-mcp.mp4"
64
- },
65
- "files": [
66
- "cli.js",
67
- "agent-dir.ts",
68
- "index.ts",
69
- "error-signal.ts",
70
- "state.ts",
71
- "utils.ts",
72
- "abort.ts",
73
- "runtime-owner.ts",
74
- "tool-metadata.ts",
75
- "ts-shape.ts",
76
- "search-ranking.ts",
77
- "tool-approval.ts",
78
- "init.ts",
79
- "ui-session.ts",
80
- "proxy-modes.ts",
81
- "direct-tools.ts",
82
- "commands.ts",
83
- "prompts.ts",
84
- "onboarding-state.ts",
85
- "mcp-setup-panel.ts",
86
- "types.ts",
87
- "ui-stream-types.ts",
88
- "ui-tool-visibility.ts",
89
- "ui-app-bridge-helpers.ts",
90
- "config.ts",
91
- "server-manager.ts",
92
- "request-headers-command.ts",
93
- "unix-socket-transport.ts",
94
- "json-schema-validator.ts",
95
- "session-recovery.ts",
96
- "sampling-handler.ts",
97
- "elicitation-handler.ts",
98
- "tool-registrar.ts",
99
- "tool-result-renderer.ts",
100
- "mcp-output-guard.ts",
101
- "mcp-code.ts",
102
- "mcp-script-worker.mjs",
103
- "mcp-probe.ts",
104
- "agent-plugin-loader.ts",
105
- "resource-tools.ts",
106
- "lifecycle.ts",
107
- "mcp-status.ts",
108
- "metadata-cache.ts",
109
- "host-html-template.ts",
110
- "ui-resource-handler.ts",
111
- "consent-manager.ts",
112
- "ui-server.ts",
113
- "glimpse-ui.ts",
114
- "npx-resolver.ts",
115
- "oauth-handler.ts",
116
- "oauth.ts",
117
- "mcp-auth.ts",
118
- "mcp-keyring-helper.cjs",
119
- "mcp-oauth-provider.ts",
120
- "mcp-callback-server.ts",
121
- "mcp-auth-flow.ts",
122
- "mcp-panel.ts",
123
- "panel-keys.ts",
124
- "mcp-trace.ts",
125
- "logger.ts",
126
- "errors.ts",
127
- "app-bridge.bundle.js",
128
- "banner.png",
129
- "skills",
130
- "README.md",
131
- "CHANGELOG.md",
132
- "LICENSE"
133
- ],
134
- "dependencies": {
135
- "@modelcontextprotocol/client": "2.0.0",
136
- "@modelcontextprotocol/core": "2.0.0",
137
- "@modelcontextprotocol/ext-apps": "^1.2.2",
138
- "@napi-rs/keyring": "^1.3.0",
139
- "ajv": "^8.17.1",
140
- "ajv-formats": "^3.0.1",
141
- "cross-spawn": "^7.0.6",
142
- "open": "^10.2.0",
143
- "recheck": "^4.5.0",
144
- "smol-toml": "^1.6.1",
145
- "strip-json-comments": "^5.0.3",
146
- "zod": "^3.25.0 || ^4.0.0"
147
- },
148
- "peerDependencies": {
149
- "@earendil-works/pi-ai": "^0.84.1",
150
- "@earendil-works/pi-tui": "*",
151
- "typebox": "*",
152
- "zod": "^3.25.0 || ^4.0.0"
153
- },
154
- "peerDependenciesMeta": {
155
- "@earendil-works/pi-ai": {
156
- "optional": true
157
- },
158
- "@earendil-works/pi-tui": {
159
- "optional": true
160
- },
161
- "typebox": {
162
- "optional": true
163
- }
164
- },
165
- "devDependencies": {
166
- "@earendil-works/pi-ai": "^0.84.1",
167
- "@earendil-works/pi-coding-agent": "0.84.1",
168
- "@earendil-works/pi-tui": "^0.84.1",
169
- "@modelcontextprotocol/conformance": "0.1.16",
170
- "@types/bun": "^1.0.0",
171
- "@types/cross-spawn": "6.0.6",
172
- "@types/node": "20.19.43",
173
- "@types/open": "^6.2.1",
174
- "tsx": "^4.21.0",
175
- "typebox": "1.3.3",
176
- "typescript": "5.9.3",
177
- "vitest": "^3.0.0"
178
- }
2
+ "name": "pi-mcp-adapter",
3
+ "version": "2.27.0",
4
+ "description": "MCP (Model Context Protocol) adapter extension for Pi coding agent",
5
+ "type": "module",
6
+ "types": "./index.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.ts",
10
+ "import": "./index.ts",
11
+ "default": "./index.ts"
12
+ },
13
+ "./types": {
14
+ "types": "./types.ts",
15
+ "import": "./types.ts",
16
+ "default": "./types.ts"
17
+ },
18
+ "./oauth": {
19
+ "types": "./oauth.ts",
20
+ "import": "./oauth.ts",
21
+ "default": "./oauth.ts"
22
+ }
23
+ },
24
+ "license": "MIT",
25
+ "author": "Nico Bailon",
26
+ "engines": {
27
+ "node": ">=20"
28
+ },
29
+ "bin": {
30
+ "pi-mcp-adapter": "cli.js"
31
+ },
32
+ "scripts": {
33
+ "typecheck": "tsc --noEmit",
34
+ "test": "vitest run",
35
+ "test:watch": "vitest",
36
+ "test:coverage": "vitest run --coverage",
37
+ "test:oauth": "PI_MCP_ADAPTER_TEST_AUTH_STORE=memory PI_MCP_ADAPTER_DISABLE_AUTH_CACHE=1 node --import tsx --test --test-concurrency=1 oauth-public-api.test.ts mcp-auth.test.ts mcp-auth-flow.test.ts mcp-callback-server.test.ts mcp-oauth-provider.test.ts",
38
+ "test:oauth-provider": "PI_MCP_ADAPTER_TEST_AUTH_STORE=memory PI_MCP_ADAPTER_DISABLE_AUTH_CACHE=1 node --import tsx --test mcp-oauth-provider.test.ts",
39
+ "test:conformance": "bash conformance/run.sh"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/nicobailon/pi-mcp-adapter.git"
44
+ },
45
+ "keywords": [
46
+ "pi-package",
47
+ "pi",
48
+ "mcp",
49
+ "model-context-protocol",
50
+ "ai",
51
+ "coding-agent",
52
+ "extension",
53
+ "claude",
54
+ "llm"
55
+ ],
56
+ "pi": {
57
+ "extensions": [
58
+ "./index.ts"
59
+ ],
60
+ "skills": [
61
+ "./skills"
62
+ ],
63
+ "video": "https://github.com/nicobailon/pi-mcp-adapter/raw/refs/heads/main/pi-mcp.mp4"
64
+ },
65
+ "files": [
66
+ "cli.js",
67
+ "agent-dir.ts",
68
+ "index.ts",
69
+ "error-signal.ts",
70
+ "state.ts",
71
+ "utils.ts",
72
+ "abort.ts",
73
+ "runtime-owner.ts",
74
+ "tool-metadata.ts",
75
+ "ts-shape.ts",
76
+ "search-ranking.ts",
77
+ "tool-approval.ts",
78
+ "init.ts",
79
+ "ui-session.ts",
80
+ "proxy-modes.ts",
81
+ "direct-tools.ts",
82
+ "commands.ts",
83
+ "prompts.ts",
84
+ "onboarding-state.ts",
85
+ "mcp-setup-panel.ts",
86
+ "types.ts",
87
+ "ui-stream-types.ts",
88
+ "ui-tool-visibility.ts",
89
+ "ui-app-bridge-helpers.ts",
90
+ "config.ts",
91
+ "package-mcp-loader.ts",
92
+ "server-manager.ts",
93
+ "request-headers-command.ts",
94
+ "unix-socket-transport.ts",
95
+ "json-schema-validator.ts",
96
+ "session-recovery.ts",
97
+ "sampling-handler.ts",
98
+ "elicitation-handler.ts",
99
+ "tool-registrar.ts",
100
+ "tool-result-renderer.ts",
101
+ "mcp-output-guard.ts",
102
+ "mcp-code.ts",
103
+ "mcp-script-worker.mjs",
104
+ "mcp-probe.ts",
105
+ "agent-plugin-loader.ts",
106
+ "resource-tools.ts",
107
+ "lifecycle.ts",
108
+ "mcp-status.ts",
109
+ "metadata-cache.ts",
110
+ "host-html-template.ts",
111
+ "ui-resource-handler.ts",
112
+ "consent-manager.ts",
113
+ "ui-server.ts",
114
+ "glimpse-ui.ts",
115
+ "npx-resolver.ts",
116
+ "oauth-handler.ts",
117
+ "oauth.ts",
118
+ "mcp-auth.ts",
119
+ "mcp-bearer-store.ts",
120
+ "mcp-keyring-helper.cjs",
121
+ "mcp-oauth-provider.ts",
122
+ "mcp-callback-server.ts",
123
+ "mcp-auth-flow.ts",
124
+ "mcp-panel.ts",
125
+ "panel-keys.ts",
126
+ "mcp-trace.ts",
127
+ "logger.ts",
128
+ "errors.ts",
129
+ "app-bridge.bundle.js",
130
+ "banner.png",
131
+ "skills",
132
+ "README.md",
133
+ "CHANGELOG.md",
134
+ "LICENSE"
135
+ ],
136
+ "dependencies": {
137
+ "@modelcontextprotocol/client": "2.0.0",
138
+ "@modelcontextprotocol/core": "2.0.0",
139
+ "@modelcontextprotocol/ext-apps": "^1.2.2",
140
+ "@napi-rs/keyring": "^1.3.0",
141
+ "ajv": "^8.17.1",
142
+ "ajv-formats": "^3.0.1",
143
+ "cross-spawn": "^7.0.6",
144
+ "open": "^10.2.0",
145
+ "recheck": "^4.5.0",
146
+ "smol-toml": "^1.6.1",
147
+ "strip-json-comments": "^5.0.3",
148
+ "zod": "^3.25.0 || ^4.0.0"
149
+ },
150
+ "peerDependencies": {
151
+ "@earendil-works/pi-ai": "^0.84.1",
152
+ "@earendil-works/pi-tui": "*",
153
+ "typebox": "*",
154
+ "zod": "^3.25.0 || ^4.0.0"
155
+ },
156
+ "peerDependenciesMeta": {
157
+ "@earendil-works/pi-ai": {
158
+ "optional": true
159
+ },
160
+ "@earendil-works/pi-tui": {
161
+ "optional": true
162
+ },
163
+ "typebox": {
164
+ "optional": true
165
+ }
166
+ },
167
+ "devDependencies": {
168
+ "@earendil-works/pi-ai": "^0.84.1",
169
+ "@earendil-works/pi-coding-agent": "0.84.1",
170
+ "@earendil-works/pi-tui": "^0.84.1",
171
+ "@modelcontextprotocol/conformance": "0.1.16",
172
+ "@types/bun": "^1.0.0",
173
+ "@types/cross-spawn": "6.0.6",
174
+ "@types/node": "20.19.43",
175
+ "@types/open": "^6.2.1",
176
+ "tsx": "^4.21.0",
177
+ "typebox": "1.3.3",
178
+ "typescript": "5.9.3",
179
+ "vitest": "^3.0.0"
180
+ }
179
181
  }
@@ -13,7 +13,7 @@ import { reconstructPromptMetadata } from "./metadata-cache.ts";
13
13
  import { resolveMcpResultContent, transformMcpContent, transformMcpResourceContents } from "./tool-registrar.ts";
14
14
  import { guardMcpOutput, guardedMcpDetails, resolveMcpOutputGuardOptions } from "./mcp-output-guard.ts";
15
15
  import { maybeStartUiSession, summarizeUiSessionResult, type UiSessionRuntime } from "./ui-session.ts";
16
- import { formatAuthRequiredMessage, formatMcpStatus, resolveServerUrl, truncateAtWord } from "./utils.ts";
16
+ import { formatAuthRequiredMessage, formatMcpStatus, normalizeToolArguments, resolveServerUrl, truncateAtWord } from "./utils.ts";
17
17
  import { authenticate, completeAuthFromInput, startAuth, supportsOAuth } from "./mcp-auth-flow.ts";
18
18
  import { SessionRecoveryAuthRequiredError, withSessionRecovery } from "./session-recovery.ts";
19
19
  import { paginate, rankSuggestions, rankToolMatches, resolveSearchKeywords } from "./search-ranking.ts";
@@ -1136,11 +1136,12 @@ export async function executeCall(
1136
1136
  return disabledCallResult(serverName, toolMeta);
1137
1137
  }
1138
1138
 
1139
+ const normalizedArgs = toolMeta.resourceUri ? args ?? {} : normalizeToolArguments(args);
1139
1140
  const approval = await ensureToolCallApproved(
1140
1141
  state,
1141
1142
  serverName,
1142
1143
  toolMeta,
1143
- args,
1144
+ normalizedArgs,
1144
1145
  ownedSignal,
1145
1146
  origin ?? (toolMeta.resourceUri ? "resource" : "proxy"),
1146
1147
  );
@@ -1217,7 +1218,7 @@ export async function executeCall(
1217
1218
  ? await maybeStartUiSession(state, {
1218
1219
  serverName,
1219
1220
  toolName: toolMeta.originalName,
1220
- toolArgs: args ?? {},
1221
+ toolArgs: normalizedArgs,
1221
1222
  uiResourceUri: toolMeta.uiResourceUri,
1222
1223
  ...(toolMeta.uiStreamMode !== undefined ? { streamMode: toolMeta.uiStreamMode } : {}),
1223
1224
  ...(signal ? { signal } : {}),
@@ -1235,7 +1236,7 @@ export async function executeCall(
1235
1236
  serverName,
1236
1237
  (conn) => abortable(conn.client.callTool({
1237
1238
  name: toolMeta.originalName,
1238
- arguments: args ?? {},
1239
+ arguments: normalizedArgs,
1239
1240
  _meta: uiSession?.requestMeta,
1240
1241
  }, requestOptions), ownedSignal),
1241
1242
  );