pi-mcp-extension 1.13.0 → 1.14.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.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/tool-bridge.ts +28 -2
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/images/binary blobs, `resource_link` hints, 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 and passed to Pi as structured tool `annotations` (boolean hints only), so permission extensions can inspect them
|
|
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
|
|
@@ -401,7 +401,7 @@ Implements the **MCP 2025-03-26** specification for tool and resource clients:
|
|
|
401
401
|
| `notifications/cancelled` (AbortSignal) | ✅ |
|
|
402
402
|
| `notifications/message` (structured logging) | ✅ |
|
|
403
403
|
| `isError: true` distinction (protocol vs tool errors, non-text filtered on error) | ✅ |
|
|
404
|
-
| Tool annotations (`readOnlyHint`, `destructiveHint`, etc.) | ✅ |
|
|
404
|
+
| Tool annotations (`readOnlyHint`, `destructiveHint`, etc.) in descriptions and as structured Pi `annotations` | ✅ |
|
|
405
405
|
|
|
406
406
|
## Contributing / Architecture
|
|
407
407
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mcp-extension",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
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": [
|
package/src/tool-bridge.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* - Paginated tools/list (cursor loop per spec)
|
|
6
6
|
* - JSON Schema → TypeBox conversion (common types + Type.Any() fallback)
|
|
7
7
|
* - Tool name sanitization (Pi-compatible identifiers)
|
|
8
|
-
* - Tool annotations → description hints
|
|
8
|
+
* - Tool annotations → description hints + structured Pi `annotations`
|
|
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)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import { createHash } from "node:crypto";
|
|
16
16
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
17
17
|
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
18
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import type { ExtensionAPI, ToolAnnotations } from "@earendil-works/pi-coding-agent";
|
|
19
19
|
import { McpError, AuthCancelledError } from "./errors.js";
|
|
20
20
|
import type { Settings } from "./config.js";
|
|
21
21
|
import { isCancellationError, isOAuthUnauthorizedError, isSdkTimeoutError } from "./connect-policy.js";
|
|
@@ -173,6 +173,30 @@ function buildToolDescription(
|
|
|
173
173
|
return hints.length > 0 ? `${description} [${hints.join(", ")}]` : description;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
+
const ANNOTATION_HINT_KEYS = [
|
|
177
|
+
"readOnlyHint",
|
|
178
|
+
"destructiveHint",
|
|
179
|
+
"idempotentHint",
|
|
180
|
+
"openWorldHint",
|
|
181
|
+
] as const;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Build the structured `annotations` Pi reads from a registered tool, so permission extensions
|
|
185
|
+
* can inspect the hints. Copies only the four boolean hints (keeping `false`), ignores `title`
|
|
186
|
+
* and non-boolean values, and returns `undefined` when none apply so the field is omitted.
|
|
187
|
+
*/
|
|
188
|
+
function buildToolAnnotations(
|
|
189
|
+
annotations: McpToolDefinition["annotations"],
|
|
190
|
+
): ToolAnnotations | undefined {
|
|
191
|
+
if (!annotations) return undefined;
|
|
192
|
+
const result: ToolAnnotations = {};
|
|
193
|
+
for (const key of ANNOTATION_HINT_KEYS) {
|
|
194
|
+
const value = annotations[key];
|
|
195
|
+
if (typeof value === "boolean") result[key] = value;
|
|
196
|
+
}
|
|
197
|
+
return Object.keys(result).length > 0 ? result : undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
176
200
|
/** Call tools/call through the typed helper when present, else a raw JSON-RPC request. */
|
|
177
201
|
function callToolWithClient(
|
|
178
202
|
client: Client,
|
|
@@ -484,6 +508,7 @@ export class ToolBridge {
|
|
|
484
508
|
): void {
|
|
485
509
|
const annotations = tool.annotations;
|
|
486
510
|
const description = buildToolDescription(tool, annotations);
|
|
511
|
+
const toolAnnotations = buildToolAnnotations(annotations);
|
|
487
512
|
const runTool = (params: unknown, signal: AbortSignal | undefined) =>
|
|
488
513
|
this._executeToolCall(serverName, tool.name, client, params, signal);
|
|
489
514
|
// WHY: `execute` runs with `this` bound to the registered-tool literal rather than the
|
|
@@ -497,6 +522,7 @@ export class ToolBridge {
|
|
|
497
522
|
description,
|
|
498
523
|
promptSnippet: description.slice(0, 120),
|
|
499
524
|
parameters: convertJsonSchemaToTypebox(tool.inputSchema),
|
|
525
|
+
...(toolAnnotations ? { annotations: toolAnnotations } : {}),
|
|
500
526
|
|
|
501
527
|
async execute(_toolCallId, params, signal, _onUpdate, _ctx) {
|
|
502
528
|
try {
|