@fitchmultz/pi-mcp-adapter 5.0.0

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 (176) hide show
  1. package/CHANGELOG.md +750 -0
  2. package/LICENSE +21 -0
  3. package/OAUTH.md +462 -0
  4. package/README.md +820 -0
  5. package/abort.ts +34 -0
  6. package/agent-dir.ts +24 -0
  7. package/app-bridge.bundle.js +67 -0
  8. package/banner.png +0 -0
  9. package/checkpoint.ts +55 -0
  10. package/cli.js +222 -0
  11. package/commands.ts +619 -0
  12. package/config.ts +1204 -0
  13. package/consent-manager.ts +25 -0
  14. package/direct-tools.ts +408 -0
  15. package/dist/abort.d.ts +2 -0
  16. package/dist/abort.js +35 -0
  17. package/dist/agent-dir.d.ts +3 -0
  18. package/dist/agent-dir.js +21 -0
  19. package/dist/app-bridge.bundle.js +67 -0
  20. package/dist/checkpoint.d.ts +18 -0
  21. package/dist/checkpoint.js +53 -0
  22. package/dist/commands.d.ts +20 -0
  23. package/dist/commands.js +521 -0
  24. package/dist/config.d.ts +109 -0
  25. package/dist/config.js +1013 -0
  26. package/dist/consent-manager.d.ts +8 -0
  27. package/dist/consent-manager.js +21 -0
  28. package/dist/direct-tools.d.ts +10 -0
  29. package/dist/direct-tools.js +350 -0
  30. package/dist/docs/client-metadata.json +14 -0
  31. package/dist/elicitation-handler.d.ts +17 -0
  32. package/dist/elicitation-handler.js +308 -0
  33. package/dist/error-signal.d.ts +15 -0
  34. package/dist/error-signal.js +21 -0
  35. package/dist/glimpse-ui.d.ts +9 -0
  36. package/dist/glimpse-ui.js +75 -0
  37. package/dist/host-html-template.d.ts +15 -0
  38. package/dist/host-html-template.js +429 -0
  39. package/dist/index.d.ts +7 -0
  40. package/dist/index.js +840 -0
  41. package/dist/init.d.ts +25 -0
  42. package/dist/init.js +562 -0
  43. package/dist/legacy-migration.d.ts +18 -0
  44. package/dist/legacy-migration.js +45 -0
  45. package/dist/lifecycle.d.ts +40 -0
  46. package/dist/lifecycle.js +167 -0
  47. package/dist/logger.d.ts +38 -0
  48. package/dist/logger.js +102 -0
  49. package/dist/mcp-auth-flow.d.ts +113 -0
  50. package/dist/mcp-auth-flow.js +834 -0
  51. package/dist/mcp-auth.d.ts +127 -0
  52. package/dist/mcp-auth.js +658 -0
  53. package/dist/mcp-callback-server.d.ts +56 -0
  54. package/dist/mcp-callback-server.js +371 -0
  55. package/dist/mcp-code.d.ts +51 -0
  56. package/dist/mcp-code.js +366 -0
  57. package/dist/mcp-keyring-helper.cjs +89 -0
  58. package/dist/mcp-oauth-provider.d.ts +154 -0
  59. package/dist/mcp-oauth-provider.js +672 -0
  60. package/dist/mcp-output-guard.d.ts +59 -0
  61. package/dist/mcp-output-guard.js +332 -0
  62. package/dist/mcp-panel.d.ts +66 -0
  63. package/dist/mcp-panel.js +889 -0
  64. package/dist/mcp-script-worker.mjs +128 -0
  65. package/dist/mcp-setup-panel.d.ts +84 -0
  66. package/dist/mcp-setup-panel.js +561 -0
  67. package/dist/mcp-status.d.ts +11 -0
  68. package/dist/mcp-status.js +96 -0
  69. package/dist/mcp-trace.d.ts +95 -0
  70. package/dist/mcp-trace.js +233 -0
  71. package/dist/metadata-cache.d.ts +18 -0
  72. package/dist/metadata-cache.js +277 -0
  73. package/dist/npx-resolver.d.ts +6 -0
  74. package/dist/npx-resolver.js +448 -0
  75. package/dist/onboarding-state.d.ts +11 -0
  76. package/dist/onboarding-state.js +47 -0
  77. package/dist/panel-keys.d.ts +16 -0
  78. package/dist/panel-keys.js +15 -0
  79. package/dist/prompts.d.ts +56 -0
  80. package/dist/prompts.js +284 -0
  81. package/dist/proxy-modes.d.ts +38 -0
  82. package/dist/proxy-modes.js +1235 -0
  83. package/dist/resource-tools.d.ts +1 -0
  84. package/dist/resource-tools.js +14 -0
  85. package/dist/runtime-owner.d.ts +18 -0
  86. package/dist/runtime-owner.js +117 -0
  87. package/dist/sampling-handler.d.ts +15 -0
  88. package/dist/sampling-handler.js +211 -0
  89. package/dist/search-ranking.d.ts +20 -0
  90. package/dist/search-ranking.js +180 -0
  91. package/dist/server-manager.d.ts +114 -0
  92. package/dist/server-manager.js +1175 -0
  93. package/dist/session-recovery.d.ts +31 -0
  94. package/dist/session-recovery.js +310 -0
  95. package/dist/state.d.ts +63 -0
  96. package/dist/state.js +1 -0
  97. package/dist/tool-approval.d.ts +10 -0
  98. package/dist/tool-approval.js +42 -0
  99. package/dist/tool-metadata.d.ts +9 -0
  100. package/dist/tool-metadata.js +193 -0
  101. package/dist/tool-registrar.d.ts +10 -0
  102. package/dist/tool-registrar.js +64 -0
  103. package/dist/tool-result-renderer.d.ts +45 -0
  104. package/dist/tool-result-renderer.js +224 -0
  105. package/dist/ts-shape.d.ts +2 -0
  106. package/dist/ts-shape.js +147 -0
  107. package/dist/types.d.ts +516 -0
  108. package/dist/types.js +168 -0
  109. package/dist/ui-resource-handler.d.ts +17 -0
  110. package/dist/ui-resource-handler.js +209 -0
  111. package/dist/ui-server.d.ts +51 -0
  112. package/dist/ui-server.js +669 -0
  113. package/dist/ui-session.d.ts +39 -0
  114. package/dist/ui-session.js +463 -0
  115. package/dist/ui-stream-types.d.ts +104 -0
  116. package/dist/ui-stream-types.js +58 -0
  117. package/dist/ui-tool-visibility.d.ts +4 -0
  118. package/dist/ui-tool-visibility.js +26 -0
  119. package/dist/unix-socket-transport.d.ts +15 -0
  120. package/dist/unix-socket-transport.js +84 -0
  121. package/dist/utils.d.ts +30 -0
  122. package/dist/utils.js +276 -0
  123. package/docs/client-metadata.json +14 -0
  124. package/elicitation-handler.ts +349 -0
  125. package/error-signal.ts +21 -0
  126. package/glimpse-ui.ts +80 -0
  127. package/host-html-template.ts +456 -0
  128. package/index.ts +900 -0
  129. package/init.ts +627 -0
  130. package/legacy-migration.ts +47 -0
  131. package/lifecycle.ts +165 -0
  132. package/logger.ts +127 -0
  133. package/mcp-auth-flow.ts +975 -0
  134. package/mcp-auth.ts +793 -0
  135. package/mcp-callback-server.ts +450 -0
  136. package/mcp-code.ts +386 -0
  137. package/mcp-keyring-helper.cjs +89 -0
  138. package/mcp-oauth-provider.ts +774 -0
  139. package/mcp-output-guard.ts +412 -0
  140. package/mcp-panel.ts +978 -0
  141. package/mcp-script-worker.mjs +128 -0
  142. package/mcp-setup-panel.ts +666 -0
  143. package/mcp-status.ts +109 -0
  144. package/mcp-trace.ts +295 -0
  145. package/metadata-cache.ts +333 -0
  146. package/npx-resolver.ts +488 -0
  147. package/onboarding-state.ts +58 -0
  148. package/package.json +182 -0
  149. package/panel-keys.ts +37 -0
  150. package/prompts.ts +337 -0
  151. package/proxy-modes.ts +1361 -0
  152. package/resource-tools.ts +17 -0
  153. package/runtime-owner.ts +123 -0
  154. package/sampling-handler.ts +273 -0
  155. package/scripts/build.mjs +131 -0
  156. package/scripts/prepare.mjs +102 -0
  157. package/search-ranking.ts +196 -0
  158. package/server-manager.ts +1320 -0
  159. package/session-recovery.ts +316 -0
  160. package/skills/mcp-scripting/SKILL.md +38 -0
  161. package/state.ts +64 -0
  162. package/tool-approval.ts +78 -0
  163. package/tool-metadata.ts +235 -0
  164. package/tool-registrar.ts +69 -0
  165. package/tool-result-renderer.ts +286 -0
  166. package/ts-shape.ts +145 -0
  167. package/tsconfig.build.json +13 -0
  168. package/tsconfig.json +16 -0
  169. package/types.ts +810 -0
  170. package/ui-resource-handler.ts +249 -0
  171. package/ui-server.ts +808 -0
  172. package/ui-session.ts +568 -0
  173. package/ui-stream-types.ts +89 -0
  174. package/ui-tool-visibility.ts +25 -0
  175. package/unix-socket-transport.ts +85 -0
  176. package/utils.ts +309 -0
@@ -0,0 +1,26 @@
1
+ export function extractUiToolVisibility(meta) {
2
+ if (!meta || typeof meta !== "object")
3
+ return undefined;
4
+ const ui = meta.ui;
5
+ if (!ui || typeof ui !== "object" || Array.isArray(ui))
6
+ return undefined;
7
+ const visibility = ui.visibility;
8
+ if (visibility === undefined)
9
+ return undefined;
10
+ if (!Array.isArray(visibility))
11
+ return [];
12
+ const values = [];
13
+ for (const entry of visibility) {
14
+ if (entry !== "model" && entry !== "app")
15
+ return [];
16
+ if (!values.includes(entry))
17
+ values.push(entry);
18
+ }
19
+ return values;
20
+ }
21
+ export function isUiToolVisibleToModel(visibility) {
22
+ return visibility === undefined || visibility.includes("model");
23
+ }
24
+ export function isUiToolCallableByApp(visibility) {
25
+ return visibility === undefined || visibility.includes("app");
26
+ }
@@ -0,0 +1,15 @@
1
+ import type { Transport } from "@modelcontextprotocol/client";
2
+ import type { JSONRPCMessage } from "@modelcontextprotocol/client";
3
+ /** MCP JSONL transport for an explicitly configured Unix-domain socket. */
4
+ export declare class UnixSocketClientTransport implements Transport {
5
+ private readonly socketPath;
6
+ private socket;
7
+ private readonly readBuffer;
8
+ onclose?: () => void;
9
+ onerror?: (error: Error) => void;
10
+ onmessage?: (message: JSONRPCMessage) => void;
11
+ constructor(socketPath: string);
12
+ start(): Promise<void>;
13
+ close(): Promise<void>;
14
+ send(message: JSONRPCMessage): Promise<void>;
15
+ }
@@ -0,0 +1,84 @@
1
+ import { createConnection } from "node:net";
2
+ import { ReadBuffer, serializeMessage } from "@modelcontextprotocol/client";
3
+ /** MCP JSONL transport for an explicitly configured Unix-domain socket. */
4
+ export class UnixSocketClientTransport {
5
+ socketPath;
6
+ socket;
7
+ readBuffer = new ReadBuffer();
8
+ onclose;
9
+ onerror;
10
+ onmessage;
11
+ constructor(socketPath) {
12
+ this.socketPath = socketPath;
13
+ }
14
+ async start() {
15
+ if (this.socket) {
16
+ throw new Error("UnixSocketClientTransport already started");
17
+ }
18
+ await new Promise((resolve, reject) => {
19
+ const socket = createConnection(this.socketPath);
20
+ this.socket = socket;
21
+ let connected = false;
22
+ socket.once("connect", () => {
23
+ connected = true;
24
+ resolve();
25
+ });
26
+ socket.on("data", chunk => {
27
+ try {
28
+ this.readBuffer.append(chunk);
29
+ while (true) {
30
+ const message = this.readBuffer.readMessage();
31
+ if (message === null)
32
+ break;
33
+ this.onmessage?.(message);
34
+ }
35
+ }
36
+ catch (error) {
37
+ const cause = error instanceof Error ? error : new Error(String(error));
38
+ this.onerror?.(cause);
39
+ void this.close();
40
+ }
41
+ });
42
+ socket.on("error", error => {
43
+ if (!connected)
44
+ reject(error);
45
+ this.onerror?.(error);
46
+ });
47
+ socket.on("close", () => {
48
+ if (this.socket === socket)
49
+ this.socket = undefined;
50
+ this.readBuffer.clear();
51
+ this.onclose?.();
52
+ });
53
+ });
54
+ }
55
+ async close() {
56
+ const socket = this.socket;
57
+ this.socket = undefined;
58
+ this.readBuffer.clear();
59
+ if (!socket || socket.destroyed)
60
+ return;
61
+ await new Promise(resolve => {
62
+ const timeout = setTimeout(() => socket.destroy(), 2_000);
63
+ timeout.unref();
64
+ socket.once("close", () => {
65
+ clearTimeout(timeout);
66
+ resolve();
67
+ });
68
+ socket.end();
69
+ });
70
+ }
71
+ async send(message) {
72
+ const socket = this.socket;
73
+ if (!socket || socket.destroyed)
74
+ throw new Error("Unix socket is not connected");
75
+ await new Promise((resolve, reject) => {
76
+ socket.write(serializeMessage(message), error => {
77
+ if (error)
78
+ reject(error);
79
+ else
80
+ resolve();
81
+ });
82
+ });
83
+ }
84
+ }
@@ -0,0 +1,30 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import type { McpConfig, ServerEntry } from "./types.ts";
3
+ export declare function normalizeRequestTimeoutMs(timeoutMs: number | undefined): number | undefined;
4
+ export declare function openUrl(pi: ExtensionAPI, url: string, browser?: string, signal?: AbortSignal): Promise<void>;
5
+ export declare function openPath(pi: ExtensionAPI, targetPath: string): Promise<void>;
6
+ export declare function parallelLimit<T, R>(items: T[], limit: number, fn: (item: T) => Promise<R>): Promise<R[]>;
7
+ export declare function interpolateEnvVars(value: string): string;
8
+ export declare function toStringRecord(value: unknown): Record<string, string> | undefined;
9
+ export declare function interpolateEnvRecord(values: Record<string, string> | undefined): Record<string, string> | undefined;
10
+ /** Resolve a secret value, executing only a single leading `!` command marker. */
11
+ export declare function resolveCommandSecret(value: string, context: string): string;
12
+ export declare function resolveCommandSecret(value: undefined, context: string): undefined;
13
+ export declare function resolveCommandSecret(value: string | undefined, context: string): string | undefined;
14
+ /** Resolve command markers in a configured record without mutating the input. */
15
+ export declare function resolveCommandSecretsRecord(values: Record<string, string> | undefined, context: (key: string) => string): Record<string, string> | undefined;
16
+ export declare function resolveServerUrl(definition: Pick<ServerEntry, "url">): string | undefined;
17
+ export declare function resolveConfigPath(value: string | undefined): string | undefined;
18
+ export declare function resolveBearerToken(definition: Pick<ServerEntry, "bearerToken" | "bearerTokenEnv">): string | undefined;
19
+ /** Remove OSC control strings, including payloads that have no terminator. */
20
+ export declare function stripOscSequences(text: string): string;
21
+ export declare function sanitizeTerminalText(text: string): string;
22
+ export declare function formatTerminalError(error: unknown): string;
23
+ export declare function truncateAtWord(text: string, target: number): string;
24
+ export declare function normalizeDirectToolInputSchema(schema: unknown): Record<string, unknown>;
25
+ export declare function formatAuthRequiredMessage(config: Pick<McpConfig, "settings">, serverName: string, defaultMessage: string): string;
26
+ export declare function formatMcpStatus(config: Pick<McpConfig, "settings">, message: string): string | undefined;
27
+ /**
28
+ * Extract the adapter-owned UI stream mode from tool metadata.
29
+ */
30
+ export declare function extractToolUiStreamMode(toolMeta: Record<string, unknown> | undefined): "eager" | "stream-first" | undefined;
package/dist/utils.js ADDED
@@ -0,0 +1,276 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { homedir, platform } from "node:os";
3
+ import { join } from "node:path";
4
+ export function normalizeRequestTimeoutMs(timeoutMs) {
5
+ return typeof timeoutMs === "number" && Number.isFinite(timeoutMs) && timeoutMs > 0
6
+ ? timeoutMs
7
+ : undefined;
8
+ }
9
+ async function execOpen(pi, target, browser, signal) {
10
+ const os = platform();
11
+ if (os === "darwin") {
12
+ return browser
13
+ ? pi.exec("open", ["-a", browser, target], signal ? { signal } : {})
14
+ : pi.exec("open", [target], signal ? { signal } : {});
15
+ }
16
+ if (os === "win32") {
17
+ return browser
18
+ ? pi.exec("cmd", ["/c", "start", "", browser, target], signal ? { signal } : {})
19
+ : pi.exec("cmd", ["/c", "start", "", target], signal ? { signal } : {});
20
+ }
21
+ return browser
22
+ ? pi.exec(browser, [target], signal ? { signal } : {})
23
+ : pi.exec("xdg-open", [target], signal ? { signal } : {});
24
+ }
25
+ export async function openUrl(pi, url, browser, signal) {
26
+ const result = await execOpen(pi, url, browser, signal);
27
+ if (result.code !== 0) {
28
+ throw new Error(result.stderr || `Failed to open browser (exit code ${result.code})`);
29
+ }
30
+ }
31
+ export async function openPath(pi, targetPath) {
32
+ const result = await execOpen(pi, targetPath);
33
+ if (result.code !== 0) {
34
+ throw new Error(result.stderr || `Failed to open path (exit code ${result.code})`);
35
+ }
36
+ }
37
+ export async function parallelLimit(items, limit, fn) {
38
+ const results = [];
39
+ const iterator = items.entries();
40
+ async function worker() {
41
+ while (true) {
42
+ const next = iterator.next();
43
+ if (next.done)
44
+ return;
45
+ const [index, item] = next.value;
46
+ results[index] = await fn(item);
47
+ }
48
+ }
49
+ const workers = Array(Math.min(limit, items.length)).fill(null).map(() => worker());
50
+ await Promise.all(workers);
51
+ return results;
52
+ }
53
+ export function interpolateEnvVars(value) {
54
+ return value
55
+ .replace(/\$\{(\w+)\}/g, (_, name) => process.env[name] ?? "")
56
+ .replace(/\$env:(\w+)/g, (_, name) => process.env[name] ?? "")
57
+ .replace(/\{env:(\w+)\}/g, (_, name) => process.env[name] ?? "");
58
+ }
59
+ function getMissingEnvVars(value) {
60
+ const missing = new Set();
61
+ for (const match of value.matchAll(/\$\{(\w+)\}|\$env:(\w+)|\{env:(\w+)\}/g)) {
62
+ const name = match[1] ?? match[2] ?? match[3];
63
+ if (name && process.env[name] === undefined) {
64
+ missing.add(name);
65
+ }
66
+ }
67
+ return [...missing];
68
+ }
69
+ export function toStringRecord(value) {
70
+ if (!value || typeof value !== "object" || Array.isArray(value))
71
+ return undefined;
72
+ const result = {};
73
+ for (const [key, entry] of Object.entries(value)) {
74
+ if (typeof entry === "string")
75
+ result[key] = entry;
76
+ }
77
+ return Object.keys(result).length > 0 ? result : undefined;
78
+ }
79
+ function interpolateSecretExpression(value) {
80
+ if (value.startsWith("!!"))
81
+ return interpolateEnvVars(value.slice(1));
82
+ return value.startsWith("!") ? value : interpolateEnvVars(value);
83
+ }
84
+ export function interpolateEnvRecord(values) {
85
+ if (!values)
86
+ return undefined;
87
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [
88
+ key,
89
+ interpolateSecretExpression(value),
90
+ ]));
91
+ }
92
+ const COMMAND_SECRET_TIMEOUT_MS = 10_000;
93
+ const COMMAND_SECRET_MAX_OUTPUT_BYTES = 1024 * 1024;
94
+ export function resolveCommandSecret(value, context) {
95
+ if (value === undefined)
96
+ return undefined;
97
+ if (value.startsWith("!!"))
98
+ return interpolateEnvVars(value.slice(1));
99
+ if (!value.startsWith("!"))
100
+ return interpolateEnvVars(value);
101
+ let result;
102
+ try {
103
+ result = spawnSync(value.slice(1), {
104
+ shell: true,
105
+ encoding: "utf8",
106
+ timeout: COMMAND_SECRET_TIMEOUT_MS,
107
+ maxBuffer: COMMAND_SECRET_MAX_OUTPUT_BYTES,
108
+ stdio: ["ignore", "pipe", "ignore"],
109
+ windowsHide: true,
110
+ });
111
+ }
112
+ catch {
113
+ throw new Error(`Failed to resolve ${context}: command failed to start`);
114
+ }
115
+ if (result.error) {
116
+ const code = result.error.code;
117
+ const reason = code === "ETIMEDOUT"
118
+ ? "command timed out after 10 seconds"
119
+ : code === "ENOBUFS"
120
+ ? "command output exceeded 1 MiB"
121
+ : "command failed to start";
122
+ throw new Error(`Failed to resolve ${context}: ${reason}`);
123
+ }
124
+ if (result.status !== 0) {
125
+ throw new Error(`Failed to resolve ${context}: command exited with code ${result.status ?? "unknown"}`);
126
+ }
127
+ const resolved = result.stdout.trim();
128
+ if (!resolved)
129
+ throw new Error(`Failed to resolve ${context}: command returned empty output`);
130
+ return resolved;
131
+ }
132
+ /** Resolve command markers in a configured record without mutating the input. */
133
+ export function resolveCommandSecretsRecord(values, context) {
134
+ if (!values)
135
+ return undefined;
136
+ return Object.fromEntries(Object.entries(values).map(([key, value]) => [
137
+ key,
138
+ resolveCommandSecret(value, context(key)),
139
+ ]));
140
+ }
141
+ export function resolveServerUrl(definition) {
142
+ if (definition.url == null)
143
+ return undefined;
144
+ if (typeof definition.url !== "string") {
145
+ throw new Error("MCP server URL must be a string");
146
+ }
147
+ const missing = getMissingEnvVars(definition.url);
148
+ if (missing.length > 0) {
149
+ throw new Error(`Missing environment variable${missing.length === 1 ? "" : "s"} in MCP server URL: ${missing.join(", ")}`);
150
+ }
151
+ const resolved = interpolateEnvVars(definition.url);
152
+ try {
153
+ new URL(resolved);
154
+ }
155
+ catch (error) {
156
+ throw new Error(`Invalid MCP server URL after environment interpolation: ${resolved}`, { cause: error });
157
+ }
158
+ return resolved;
159
+ }
160
+ export function resolveConfigPath(value) {
161
+ if (value === undefined)
162
+ return undefined;
163
+ const resolved = interpolateEnvVars(value);
164
+ if (resolved === "~")
165
+ return homedir();
166
+ if (resolved.startsWith("~/") || resolved.startsWith("~\\")) {
167
+ return join(homedir(), resolved.slice(2));
168
+ }
169
+ return resolved;
170
+ }
171
+ export function resolveBearerToken(definition) {
172
+ if (definition.bearerToken !== undefined) {
173
+ return interpolateSecretExpression(definition.bearerToken);
174
+ }
175
+ return definition.bearerTokenEnv ? process.env[definition.bearerTokenEnv] : undefined;
176
+ }
177
+ /** Remove OSC control strings, including payloads that have no terminator. */
178
+ export function stripOscSequences(text) {
179
+ let result = "";
180
+ let index = 0;
181
+ while (index < text.length) {
182
+ const isEscOsc = text.charCodeAt(index) === 0x1b && text[index + 1] === "]";
183
+ const isC1Osc = text.charCodeAt(index) === 0x9d;
184
+ if (!isEscOsc && !isC1Osc) {
185
+ result += text[index++];
186
+ continue;
187
+ }
188
+ index += isEscOsc ? 2 : 1;
189
+ while (index < text.length) {
190
+ const code = text.charCodeAt(index++);
191
+ if (code === 0x07 || code === 0x9c)
192
+ break;
193
+ if (code === 0x1b && text[index] === "\\") {
194
+ index++;
195
+ break;
196
+ }
197
+ }
198
+ }
199
+ return result;
200
+ }
201
+ export function sanitizeTerminalText(text) {
202
+ return stripOscSequences(text)
203
+ .replace(/(?:\x1b\[[0-?]*[ -/]*[@-~]|\x1b[@-Z\\-_])/g, "")
204
+ .replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ")
205
+ .replace(/\s+/g, " ")
206
+ .trim();
207
+ }
208
+ export function formatTerminalError(error) {
209
+ const messages = [];
210
+ const seen = new Set();
211
+ const collect = (value) => {
212
+ if (seen.has(value))
213
+ return;
214
+ if ((typeof value === "object" && value !== null) || typeof value === "function")
215
+ seen.add(value);
216
+ if (value instanceof AggregateError) {
217
+ const countBefore = messages.length;
218
+ for (const nested of value.errors)
219
+ collect(nested);
220
+ if (value.cause !== undefined)
221
+ collect(value.cause);
222
+ if (messages.length === countBefore && value.message)
223
+ messages.push(value.message);
224
+ return;
225
+ }
226
+ if (value instanceof Error) {
227
+ if (value.message)
228
+ messages.push(value.message);
229
+ if (value.cause !== undefined)
230
+ collect(value.cause);
231
+ return;
232
+ }
233
+ messages.push(String(value));
234
+ };
235
+ collect(error);
236
+ return sanitizeTerminalText([...new Set(messages)].join(": "));
237
+ }
238
+ export function truncateAtWord(text, target) {
239
+ if (!text || text.length <= target)
240
+ return text;
241
+ const truncated = text.slice(0, target);
242
+ const lastSpace = truncated.lastIndexOf(" ");
243
+ if (lastSpace > target * 0.6) {
244
+ return truncated.slice(0, lastSpace) + "...";
245
+ }
246
+ return truncated + "...";
247
+ }
248
+ export function normalizeDirectToolInputSchema(schema) {
249
+ const inputSchema = schema && typeof schema === "object" && !Array.isArray(schema)
250
+ ? schema
251
+ : { type: "object", properties: {} };
252
+ const { $schema, additionalProperties, ...normalized } = inputSchema;
253
+ return normalized;
254
+ }
255
+ export function formatAuthRequiredMessage(config, serverName, defaultMessage) {
256
+ const template = config.settings?.authRequiredMessage;
257
+ return template ? template.replaceAll("${server}", serverName) : defaultMessage;
258
+ }
259
+ export function formatMcpStatus(config, message) {
260
+ if (config.settings?.mcpFooterStatus === "off")
261
+ return undefined;
262
+ return `${config.settings?.showStatusIcon === false ? "MCP: " : "🔌 MCP: "}${message}`;
263
+ }
264
+ /**
265
+ * Extract the adapter-owned UI stream mode from tool metadata.
266
+ */
267
+ export function extractToolUiStreamMode(toolMeta) {
268
+ const uiMeta = toolMeta?.ui;
269
+ if (!uiMeta || typeof uiMeta !== "object")
270
+ return undefined;
271
+ const streamMode = uiMeta["pi-mcp-adapter.streamMode"];
272
+ if (streamMode === "eager" || streamMode === "stream-first") {
273
+ return streamMode;
274
+ }
275
+ return undefined;
276
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "client_id": "https://fitchmultz.github.io/pi-mcp-adapter/client-metadata.json",
3
+ "client_name": "Fitch MCP Adapter",
4
+ "client_uri": "https://github.com/fitchmultz/pi-mcp-adapter",
5
+ "redirect_uris": [
6
+ "http://localhost:19876/callback",
7
+ "http://127.0.0.1:19876/callback",
8
+ "http://[::1]:19876/callback"
9
+ ],
10
+ "application_type": "native",
11
+ "grant_types": ["authorization_code", "refresh_token"],
12
+ "response_types": ["code"],
13
+ "token_endpoint_auth_method": "none"
14
+ }