pi-mcp-extension 1.5.1 → 1.5.3
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.
- package/package.json +1 -1
- package/src/server-manager.ts +25 -11
- package/src/tool-bridge.ts +9 -5
package/package.json
CHANGED
package/src/server-manager.ts
CHANGED
|
@@ -369,20 +369,19 @@ export class ServerManager {
|
|
|
369
369
|
try { await client.ping(); }
|
|
370
370
|
catch {
|
|
371
371
|
if (signal.aborted) return;
|
|
372
|
-
|
|
373
|
-
await this._shutdown(server);
|
|
374
|
-
if (server.generation === recoveryGeneration) {
|
|
375
|
-
// An external stop during cleanup increments the generation again.
|
|
376
|
-
queueMicrotask(() => {
|
|
377
|
-
if (server.generation !== recoveryGeneration) return;
|
|
378
|
-
void this.startServer(server.name, cwd).catch((error) => {
|
|
379
|
-
server.lastError = error instanceof Error ? error : new Error(String(error));
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
}
|
|
372
|
+
await this._recover(server, cwd);
|
|
383
373
|
}
|
|
384
374
|
}, server.config.healthCheckIntervalMs);
|
|
385
375
|
}
|
|
376
|
+
// Unexpected transport close (e.g. the server subprocess crashes
|
|
377
|
+
// mid-session). Without this the state would stay "ready" and tools
|
|
378
|
+
// would remain active against a dead server. Deliberate closes abort
|
|
379
|
+
// the signal first, so they are ignored here.
|
|
380
|
+
client.onclose = () => {
|
|
381
|
+
if (signal.aborted || server.client !== client) return;
|
|
382
|
+
console.error(`[pi-mcp] Server ${server.name} closed unexpectedly, reconnecting`);
|
|
383
|
+
void this._recover(server, cwd);
|
|
384
|
+
};
|
|
386
385
|
} catch (err) {
|
|
387
386
|
try { await client.close(); } catch { /* best effort */ }
|
|
388
387
|
if (server.client === client) { server.client = null; server.childPid = null; }
|
|
@@ -410,6 +409,21 @@ export class ServerManager {
|
|
|
410
409
|
}
|
|
411
410
|
}
|
|
412
411
|
|
|
412
|
+
/** Tear down a server that died or stopped responding, then reconnect. */
|
|
413
|
+
private async _recover(server: ManagedServer, cwd: string): Promise<void> {
|
|
414
|
+
const recoveryGeneration = (server.generation ?? 0) + 1;
|
|
415
|
+
await this._shutdown(server);
|
|
416
|
+
if (server.generation === recoveryGeneration) {
|
|
417
|
+
// An external stop during cleanup increments the generation again.
|
|
418
|
+
queueMicrotask(() => {
|
|
419
|
+
if (server.generation !== recoveryGeneration) return;
|
|
420
|
+
void this.startServer(server.name, cwd).catch((error) => {
|
|
421
|
+
server.lastError = error instanceof Error ? error : new Error(String(error));
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
413
427
|
private async _shutdown(server: ManagedServer): Promise<void> {
|
|
414
428
|
server.controller?.abort();
|
|
415
429
|
server.generation = (server.generation ?? 0) + 1;
|
package/src/tool-bridge.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - AbortSignal → SDK's built-in cancellation (notifications/cancelled)
|
|
10
10
|
* - Protocol error vs tool execution error distinction
|
|
11
11
|
* - Activate/deactivate pattern (register once, toggle on server state change)
|
|
12
|
-
* - Image
|
|
12
|
+
* - Image content → ImageContent passthrough; audio/resource → text description
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
@@ -224,8 +224,9 @@ export function buildToolName(prefix: string, serverName: string, toolName: stri
|
|
|
224
224
|
// ─── Content Conversion ───────────────────────────────────────────────────────
|
|
225
225
|
|
|
226
226
|
type PiTextContent = { type: "text"; text: string };
|
|
227
|
+
type PiImageContent = { type: "image"; data: string; mimeType: string };
|
|
227
228
|
|
|
228
|
-
function convertMcpContent(items: unknown[]): PiTextContent[] {
|
|
229
|
+
function convertMcpContent(items: unknown[]): (PiTextContent | PiImageContent)[] {
|
|
229
230
|
return items.map((item: any) => {
|
|
230
231
|
if (!item || typeof item !== "object") {
|
|
231
232
|
return { type: "text", text: String(item) };
|
|
@@ -235,8 +236,9 @@ function convertMcpContent(items: unknown[]): PiTextContent[] {
|
|
|
235
236
|
return { type: "text", text: String(item.text ?? "") };
|
|
236
237
|
case "image":
|
|
237
238
|
return {
|
|
238
|
-
type: "
|
|
239
|
-
|
|
239
|
+
type: "image",
|
|
240
|
+
data: String(item.data ?? ""),
|
|
241
|
+
mimeType: String(item.mimeType ?? "image/png"),
|
|
240
242
|
};
|
|
241
243
|
case "audio":
|
|
242
244
|
return {
|
|
@@ -445,7 +447,9 @@ export class ToolBridge {
|
|
|
445
447
|
|
|
446
448
|
// Tool execution errors (isError: true) — distinct from protocol errors
|
|
447
449
|
if (result.isError) {
|
|
448
|
-
const errorText = content
|
|
450
|
+
const errorText = content
|
|
451
|
+
.map((c) => (c.type === "text" ? c.text : ""))
|
|
452
|
+
.join("\n");
|
|
449
453
|
throw new McpError(
|
|
450
454
|
errorText || "Tool reported an error",
|
|
451
455
|
serverName,
|