pi-mcp-extension 1.12.3 → 1.12.4
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/README.md +3 -5
- package/package.json +2 -1
- package/src/resource-bridge.ts +9 -4
- package/src/tool-bridge.ts +30 -10
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
- **Stable tool names** — Sanitized, collision-avoiding names (`<prefix>_<server>_<tool>`, max 64 chars) that stay constant across reconnects
|
|
28
28
|
- **No tool churn** — Activate/deactivate pattern ensures tools don't flicker during reconnection
|
|
29
29
|
- **Layered config & trust boundary** — Global `<agent dir>/mcp.json`, project `.pi/mcp.json` (loaded only in trusted projects, including Pi 1.3.0 partial overrides), and Pi 1.x extension-registered servers (`pi.registerMcpServer()`)
|
|
30
|
-
- **Rich tool results & annotations** — MCP `text`, `image` (`ImageContent`), `structuredContent`, embedded `resource` text/blobs, and `audio` fallback descriptions, plus `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint` surfaced in tool descriptions
|
|
30
|
+
- **Rich tool results & annotations** — MCP `text`, `image` (`ImageContent`), `structuredContent`, embedded `resource` text/images/binary blobs, `resource_link` hints, and `audio` fallback descriptions, plus `readOnlyHint`, `destructiveHint`, `idempotentHint`, and `openWorldHint` surfaced in tool descriptions
|
|
31
31
|
- **On-demand agent tools & commands** — `mcp_status`, `mcp_connect`, `mcp_list_resources`, and `mcp_read_resource` agent tools plus `/mcp`, `/mcp <name>` (with config provenance and failure hints), `/mcp:start`, `/mcp:stop`, `/mcp:auth`, and `/mcp:resources` slash commands with server-name autocomplete
|
|
32
32
|
- **Structured error handling** — Distinct error codes (`config`, `connection`, `auth`, `timeout`, `protocol`, `tool`) and actionable failure hints
|
|
33
33
|
- **Redacted debug logging** — Opt-in `PI_MCP_DEBUG=1` JSON Lines log (`<agent dir>/logs/pi-mcp.log`, `0600`, ~2 MB rotation) with automatic secret masking and zero TUI `stderr` noise
|
|
@@ -366,7 +366,7 @@ flowchart TD
|
|
|
366
366
|
2. **Eager servers connect** at `session_start` via `ConnectionCoordinator` (offering a sequential `Authorize now` / `Not now` prompt when an eager OAuth server needs authorization in an interactive session); lazy servers wait for `mcp_connect`, `/mcp:start`, or `/mcp:auth`
|
|
367
367
|
3. **Tools are discovered** via paginated `tools/list` calls (cursor-based, up to 100 pages) before a server enters `ready`
|
|
368
368
|
4. **JSON Schema → TypeBox** conversion registers tools with Pi-compatible parameter schemas (preserving nullable union ordering, resolving `$ref`s cycle-safely, and inferring/flattening `allOf` object schemas)
|
|
369
|
-
5. **Pi tools are registered** as `<prefix>_<server>_<tool>` (sanitized `[a-zA-Z0-9_]`, max 64 chars with an 8-char SHA-256 suffix on truncation or collision) and convert MCP `text`, `image` (`ImageContent`), `structuredContent`, `resource`, and `audio` results
|
|
369
|
+
5. **Pi tools are registered** as `<prefix>_<server>_<tool>` (sanitized `[a-zA-Z0-9_]`, max 64 chars with an 8-char SHA-256 suffix on truncation or collision) and convert MCP `text`, `image` (`ImageContent`), `structuredContent`, `resource`, `resource_link`, and `audio` results. Embedded image resources become image blocks, binary resources include MIME type and byte count, and resource links include a `mcp_read_resource` hint.
|
|
370
370
|
6. **Tools activate/deactivate** automatically as servers connect/disconnect
|
|
371
371
|
7. **AbortSignal** is wired through to `notifications/cancelled` for clean cancellation
|
|
372
372
|
8. **Reconnection & recovery** uses a fixed delay schedule with configurable max retries on initial failure, health check failure, or unexpected transport close/error (`client.onclose` / `client.onerror`), while mid-session HTTP `401` / `403 insufficient_scope` invalidates stale tokens and surfaces a re-authorization hint
|
|
@@ -388,15 +388,13 @@ Implements the **MCP 2025-03-26** specification for tool and resource clients:
|
|
|
388
388
|
| Cursor-based `resources/list` and `resources/templates/list` pagination | ✅ |
|
|
389
389
|
| `resources/read` with text, image blobs, and binary size summaries | ✅ |
|
|
390
390
|
| `notifications/resources/list_changed` (catalog invalidation) | ✅ |
|
|
391
|
-
| `tools/call` with parameters, `image` (`ImageContent`), `structuredContent`, and `
|
|
391
|
+
| `tools/call` with parameters, `image` (`ImageContent`), `structuredContent`, `resource`, and `resource_link` conversion | ✅ |
|
|
392
392
|
| `roots/list` capability (workspace root) | ✅ |
|
|
393
393
|
| `notifications/tools/list_changed` (live refresh) | ✅ |
|
|
394
394
|
| `notifications/cancelled` (AbortSignal) | ✅ |
|
|
395
395
|
| `notifications/message` (structured logging) | ✅ |
|
|
396
396
|
| `isError: true` distinction (protocol vs tool errors, non-text filtered on error) | ✅ |
|
|
397
397
|
| Tool annotations (`readOnlyHint`, `destructiveHint`, etc.) | ✅ |
|
|
398
|
-
| Prompts bridge | ⏳ v2 |
|
|
399
|
-
| Sampling | ⏳ v2 |
|
|
400
398
|
|
|
401
399
|
## Contributing / Architecture
|
|
402
400
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mcp-extension",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.4",
|
|
4
4
|
"description": "Full-featured, lightweight MCP extension for the Pi coding agent: stdio, SSE & Streamable HTTP transports, OAuth 2.1 (PKCE + DCR), lazy/eager lifecycles — minimal dependencies, zero bloat.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"typebox": "*"
|
|
44
44
|
},
|
|
45
45
|
"overrides": {
|
|
46
|
+
"minimatch": "^11.0.4",
|
|
46
47
|
"undici": "^8.12.3"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
package/src/resource-bridge.ts
CHANGED
|
@@ -261,7 +261,12 @@ export function convertResourceContents(contents: readonly unknown[]): PiResourc
|
|
|
261
261
|
return contents.map(convertResourceContent);
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
-
function
|
|
264
|
+
function resolveResourceUri(raw: unknown): string {
|
|
265
|
+
const trimmed = typeof raw === "string" ? raw.trim() : "";
|
|
266
|
+
return trimmed.length > 0 ? trimmed : "unknown";
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function convertResourceContent(item: unknown): PiResourceContent {
|
|
265
270
|
if (typeof item !== "object" || item === null) {
|
|
266
271
|
return { type: "text", text: String(item) };
|
|
267
272
|
}
|
|
@@ -274,7 +279,7 @@ function convertResourceContent(item: unknown): PiResourceContent {
|
|
|
274
279
|
if (typeof entry["blob"] === "string") {
|
|
275
280
|
return convertBlobResource(entry);
|
|
276
281
|
}
|
|
277
|
-
return { type: "text", text: `[Resource: ${
|
|
282
|
+
return { type: "text", text: `[Resource: ${resolveResourceUri(entry["uri"])}]` };
|
|
278
283
|
}
|
|
279
284
|
|
|
280
285
|
function resolveBlobMimeType(raw: unknown): string {
|
|
@@ -283,9 +288,9 @@ function resolveBlobMimeType(raw: unknown): string {
|
|
|
283
288
|
}
|
|
284
289
|
|
|
285
290
|
function convertBlobResource(entry: Record<string, unknown>): PiResourceContent {
|
|
286
|
-
const uri =
|
|
291
|
+
const uri = resolveResourceUri(entry["uri"]);
|
|
287
292
|
const mimeType = resolveBlobMimeType(entry["mimeType"]);
|
|
288
|
-
const blob =
|
|
293
|
+
const blob = entry["blob"] as string;
|
|
289
294
|
if (mimeType.startsWith("image/")) {
|
|
290
295
|
return { type: "image", data: blob, mimeType };
|
|
291
296
|
}
|
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
|
-
* -
|
|
12
|
+
* - Images and embedded image resources → ImageContent; resource links → read hints
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
@@ -21,6 +21,7 @@ import type { Settings } from "./config.js";
|
|
|
21
21
|
import { isCancellationError, isOAuthUnauthorizedError, isSdkTimeoutError } from "./connect-policy.js";
|
|
22
22
|
import { convertJsonSchemaToTypebox } from "./schema-convert.js";
|
|
23
23
|
import { listAllTools, type McpToolDefinition } from "./tool-discovery.js";
|
|
24
|
+
import { convertResourceContent } from "./resource-bridge.js";
|
|
24
25
|
|
|
25
26
|
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
26
27
|
|
|
@@ -69,13 +70,31 @@ export function buildToolName(
|
|
|
69
70
|
type PiTextContent = { type: "text"; text: string };
|
|
70
71
|
type PiImageContent = { type: "image"; data: string; mimeType: string };
|
|
71
72
|
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
function pickNonEmptyText(value: unknown): string | undefined {
|
|
74
|
+
if (typeof value !== "string") return undefined;
|
|
75
|
+
const trimmed = value.trim();
|
|
76
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function convertResourceLink(obj: Record<string, unknown>): PiTextContent {
|
|
80
|
+
const uri = pickNonEmptyText(obj["uri"]) ?? "unknown";
|
|
81
|
+
const title = pickNonEmptyText(obj["title"]) ?? pickNonEmptyText(obj["name"]);
|
|
82
|
+
const label = title ? ` ${JSON.stringify(title)}` : "";
|
|
83
|
+
const details: string[] = [];
|
|
84
|
+
const mimeType = pickNonEmptyText(obj["mimeType"]);
|
|
85
|
+
if (mimeType) {
|
|
86
|
+
details.push(mimeType);
|
|
87
|
+
}
|
|
88
|
+
if (typeof obj["size"] === "number" && Number.isSafeInteger(obj["size"]) && obj["size"] >= 0) {
|
|
89
|
+
details.push(`${obj["size"]} bytes`);
|
|
90
|
+
}
|
|
91
|
+
const metadata = details.length > 0 ? ` (${details.join(", ")})` : "";
|
|
92
|
+
const descriptionText = pickNonEmptyText(obj["description"]);
|
|
93
|
+
const description = descriptionText ? `\n${descriptionText}` : "";
|
|
94
|
+
return {
|
|
95
|
+
type: "text",
|
|
96
|
+
text: `[Resource link: ${uri}${label}${metadata} — Use mcp_read_resource to read]${description}`,
|
|
97
|
+
};
|
|
79
98
|
}
|
|
80
99
|
|
|
81
100
|
function convertNonTextContent(obj: Record<string, unknown>): PiImageContent | PiTextContent | undefined {
|
|
@@ -93,9 +112,10 @@ function convertNonTextContent(obj: Record<string, unknown>): PiImageContent | P
|
|
|
93
112
|
};
|
|
94
113
|
}
|
|
95
114
|
if (obj["type"] === "resource") {
|
|
96
|
-
|
|
115
|
+
const resource = obj["resource"];
|
|
116
|
+
return convertResourceContent(typeof resource === "object" && resource !== null ? resource : {});
|
|
97
117
|
}
|
|
98
|
-
return undefined;
|
|
118
|
+
return obj["type"] === "resource_link" ? convertResourceLink(obj) : undefined;
|
|
99
119
|
}
|
|
100
120
|
|
|
101
121
|
function convertMcpContentItem(item: unknown): PiTextContent | PiImageContent {
|