@fitchmultz/pi-mcp-adapter 8.0.5 → 8.0.7

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 (88) hide show
  1. package/CHANGELOG.md +140 -7
  2. package/OAUTH.md +13 -16
  3. package/README.md +8 -8
  4. package/cli.js +67 -28
  5. package/dist/abort.js +18 -9
  6. package/dist/client-operations.js +4 -2
  7. package/dist/commands.js +77 -43
  8. package/dist/config.js +194 -105
  9. package/dist/connection-runtime.d.ts +2 -2
  10. package/dist/connection-runtime.js +29 -18
  11. package/dist/consent-manager.d.ts +2 -2
  12. package/dist/consent-manager.js +5 -2
  13. package/dist/direct-tools.d.ts +1 -1
  14. package/dist/direct-tools.js +13 -7
  15. package/dist/elicitation-handler.d.ts +2 -3
  16. package/dist/elicitation-handler.js +113 -58
  17. package/dist/gateway-arguments.d.ts +1 -1
  18. package/dist/gateway-arguments.js +90 -23
  19. package/dist/glimpse-ui.js +10 -5
  20. package/dist/host-html-template.d.ts +3 -1
  21. package/dist/host-html-template.js +9 -12
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.js +264 -119
  24. package/dist/init.d.ts +1 -3
  25. package/dist/init.js +91 -51
  26. package/dist/legacy-migration.d.ts +1 -1
  27. package/dist/legacy-migration.js +17 -12
  28. package/dist/lifecycle.d.ts +3 -3
  29. package/dist/lifecycle.js +33 -17
  30. package/dist/logger.d.ts +2 -2
  31. package/dist/logger.js +4 -2
  32. package/dist/mcp-auth-flow.js +150 -58
  33. package/dist/mcp-auth.d.ts +7 -7
  34. package/dist/mcp-auth.js +189 -138
  35. package/dist/mcp-callback-server.js +19 -8
  36. package/dist/mcp-code.js +168 -54
  37. package/dist/mcp-keyring-helper.cjs +57 -23
  38. package/dist/mcp-oauth-provider.d.ts +6 -7
  39. package/dist/mcp-oauth-provider.js +146 -72
  40. package/dist/mcp-oauth-runtime.js +29 -16
  41. package/dist/mcp-output-guard.js +193 -65
  42. package/dist/mcp-output-preview.js +41 -20
  43. package/dist/mcp-panel.d.ts +9 -9
  44. package/dist/mcp-panel.js +141 -70
  45. package/dist/mcp-script-worker.mjs +135 -43
  46. package/dist/mcp-setup-panel.d.ts +8 -8
  47. package/dist/mcp-setup-panel.js +130 -44
  48. package/dist/mcp-status.js +14 -7
  49. package/dist/mcp-trace.d.ts +10 -5
  50. package/dist/mcp-trace.js +127 -61
  51. package/dist/metadata-cache.d.ts +3 -4
  52. package/dist/metadata-cache.js +83 -43
  53. package/dist/npx-resolver.js +101 -60
  54. package/dist/onboarding-state.js +4 -2
  55. package/dist/plain-result-reader.js +78 -31
  56. package/dist/prompts.js +36 -20
  57. package/dist/proxy-modes.js +670 -193
  58. package/dist/resource-tools.js +30 -9
  59. package/dist/runtime-owner.js +36 -18
  60. package/dist/sampling-handler.d.ts +1 -2
  61. package/dist/sampling-handler.js +41 -21
  62. package/dist/search-ranking.d.ts +1 -1
  63. package/dist/search-ranking.js +67 -34
  64. package/dist/server-manager.d.ts +11 -11
  65. package/dist/server-manager.js +283 -166
  66. package/dist/session-recovery.js +113 -61
  67. package/dist/tool-approval.js +9 -3
  68. package/dist/tool-loader.js +154 -55
  69. package/dist/tool-metadata.d.ts +1 -1
  70. package/dist/tool-metadata.js +51 -23
  71. package/dist/tool-registrar.js +32 -10
  72. package/dist/tool-result-renderer.d.ts +3 -3
  73. package/dist/tool-result-renderer.js +65 -44
  74. package/dist/types.d.ts +2 -2
  75. package/dist/types.js +39 -18
  76. package/dist/ui-message-history.js +33 -13
  77. package/dist/ui-resource-handler.d.ts +3 -3
  78. package/dist/ui-resource-handler.js +37 -21
  79. package/dist/ui-server.js +101 -43
  80. package/dist/ui-session.js +66 -29
  81. package/dist/ui-stream-types.js +14 -4
  82. package/dist/ui-tool-visibility.js +12 -6
  83. package/dist/unix-socket-transport.d.ts +1 -2
  84. package/dist/unix-socket-transport.js +19 -12
  85. package/dist/utils.d.ts +2 -0
  86. package/dist/utils.js +60 -35
  87. package/package.json +29 -5
  88. package/skills/mcp-scripting/SKILL.md +6 -6
package/dist/prompts.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isServerDisabled } from "./types.js";
2
- import { isServerCacheValid, loadMetadataCache, reconstructPromptMetadata } from "./metadata-cache.js";
2
+ import { isServerCacheValid, loadMetadataCache, reconstructPromptMetadata, } from "./metadata-cache.js";
3
3
  import { logger } from "./logger.js";
4
4
  import { truncateAtWord } from "./utils.js";
5
5
  /**
@@ -9,16 +9,19 @@ import { truncateAtWord } from "./utils.js";
9
9
  */
10
10
  export function resolveCachedPrompts(config, cacheEnabled = true) {
11
11
  const cache = loadMetadataCache(cacheEnabled);
12
- if (!cache?.servers)
12
+ if (!cache?.servers) {
13
13
  return [];
14
+ }
14
15
  const prefix = config.settings?.toolPrefix ?? "server";
15
16
  const specs = [];
16
17
  for (const [serverName, entry] of Object.entries(cache.servers)) {
17
18
  const definition = config.mcpServers[serverName];
18
- if (!definition || isServerDisabled(definition))
19
+ if (!definition || isServerDisabled(definition)) {
19
20
  continue;
20
- if (!entry?.prompts?.length || !isServerCacheValid(entry, definition))
21
+ }
22
+ if (!entry?.prompts?.length || !isServerCacheValid(entry, definition)) {
21
23
  continue;
24
+ }
22
25
  specs.push(...reconstructPromptMetadata(serverName, entry.prompts, prefix, definition));
23
26
  }
24
27
  return specs;
@@ -66,8 +69,9 @@ function tokenizeArgs(input) {
66
69
  }
67
70
  if (quote) {
68
71
  current += char;
69
- if (char === quote)
72
+ if (char === quote) {
70
73
  quote = null;
74
+ }
71
75
  continue;
72
76
  }
73
77
  if (char === '"' || char === "'") {
@@ -84,8 +88,9 @@ function tokenizeArgs(input) {
84
88
  }
85
89
  current += char;
86
90
  }
87
- if (current.length > 0)
91
+ if (current.length > 0) {
88
92
  tokens.push(current);
93
+ }
89
94
  return tokens;
90
95
  }
91
96
  function findUnquotedEquals(token) {
@@ -93,19 +98,24 @@ function findUnquotedEquals(token) {
93
98
  for (let i = 0; i < token.length; i++) {
94
99
  const ch = token[i];
95
100
  if (quote) {
96
- if (ch === quote)
101
+ if (ch === quote) {
97
102
  quote = null;
103
+ }
98
104
  continue;
99
105
  }
100
- if (ch === '"' || ch === "'")
106
+ if (ch === '"' || ch === "'") {
101
107
  quote = ch;
102
- else if (ch === "=")
108
+ }
109
+ else if (ch === "=") {
103
110
  return i;
111
+ }
104
112
  }
105
113
  return -1;
106
114
  }
107
115
  function stripQuotes(value) {
108
- if (value.length >= 2 && (value.startsWith('"') || value.startsWith("'")) && value.endsWith(value.charAt(0))) {
116
+ if (value.length >= 2 &&
117
+ (value.startsWith('"') || value.startsWith("'")) &&
118
+ value.endsWith(value.charAt(0))) {
109
119
  return value.slice(1, -1);
110
120
  }
111
121
  return value;
@@ -130,10 +140,11 @@ export function resolvePromptArgs(metadata, parsed) {
130
140
  // permissive schemas still receive them. The MCP spec allows arbitrary
131
141
  // string key/values in `prompts/get` params.arguments.
132
142
  for (const [key, value] of Object.entries(parsed.named)) {
133
- if (!(key in args))
143
+ if (!(key in args)) {
134
144
  args[key] = value;
145
+ }
135
146
  }
136
- const missing = declared.filter(a => a.required && (args[a.name] === undefined || args[a.name] === ""));
147
+ const missing = declared.filter((a) => a.required && (args[a.name] === undefined || args[a.name] === ""));
137
148
  if (missing.length > 0) {
138
149
  return { ok: false, error: buildUsageMessage(metadata, missing) };
139
150
  }
@@ -141,9 +152,9 @@ export function resolvePromptArgs(metadata, parsed) {
141
152
  }
142
153
  function buildUsageMessage(metadata, missing) {
143
154
  const usage = metadata.arguments
144
- .map(a => (a.required ? `<${a.name}>` : `[${a.name}]`))
155
+ .map((a) => (a.required ? `<${a.name}>` : `[${a.name}]`))
145
156
  .join(" ");
146
- const missingList = missing.map(a => a.name).join(", ");
157
+ const missingList = missing.map((a) => a.name).join(", ");
147
158
  return `Missing required argument${missing.length > 1 ? "s" : ""}: ${missingList}.\nUsage: /${metadata.commandName} ${usage}`.trim();
148
159
  }
149
160
  /**
@@ -157,8 +168,9 @@ export function formatPromptResult(result) {
157
168
  const lines = [];
158
169
  for (const message of result.messages) {
159
170
  const text = extractMessageText(message);
160
- if (!text)
171
+ if (!text) {
161
172
  continue;
173
+ }
162
174
  if (message.role === "user" && result.messages.length === 1) {
163
175
  lines.push(text);
164
176
  }
@@ -170,15 +182,17 @@ export function formatPromptResult(result) {
170
182
  }
171
183
  function extractMessageText(message) {
172
184
  const content = message.content;
173
- if (!content || typeof content !== "object")
185
+ if (!content || typeof content !== "object") {
174
186
  return "";
187
+ }
175
188
  switch (content.type) {
176
189
  case "text":
177
190
  return content.text ?? "";
178
191
  case "resource": {
179
192
  const resource = content.resource;
180
- if (!resource)
193
+ if (!resource) {
181
194
  return "";
195
+ }
182
196
  if ("text" in resource && typeof resource.text === "string") {
183
197
  return `[resource ${resource.uri}]\n${resource.text}`;
184
198
  }
@@ -206,8 +220,9 @@ export function createPromptCommand(pi, getState, metadata) {
206
220
  handler: async (args, ctx) => {
207
221
  const state = getState();
208
222
  if (!state) {
209
- if (ctx.hasUI)
223
+ if (ctx.hasUI) {
210
224
  ctx.ui.notify("MCP not initialized", "error");
225
+ }
211
226
  return;
212
227
  }
213
228
  const liveMetadata = findLivePromptMetadata(state, metadata.serverName, metadata.originalName);
@@ -221,8 +236,9 @@ export function createPromptCommand(pi, getState, metadata) {
221
236
  const parsed = parsePromptArgs(args ?? "");
222
237
  const resolved = resolvePromptArgs(live, parsed);
223
238
  if (!resolved.ok) {
224
- if (ctx.hasUI)
239
+ if (ctx.hasUI) {
225
240
  ctx.ui.notify(resolved.error ?? "Invalid prompt arguments", "error");
241
+ }
226
242
  return;
227
243
  }
228
244
  const promptArgs = resolved.args ?? {};
@@ -276,7 +292,7 @@ export function createPromptCommand(pi, getState, metadata) {
276
292
  };
277
293
  }
278
294
  function findLivePromptMetadata(state, serverName, originalName) {
279
- return state.promptMetadata?.get(serverName)?.find(p => p.originalName === originalName);
295
+ return state.promptMetadata?.get(serverName)?.find((p) => p.originalName === originalName);
280
296
  }
281
297
  function buildCommandDescription(metadata) {
282
298
  const base = metadata.description || metadata.title || `MCP prompt from ${metadata.serverName}`;