pi-mcp-extension 1.16.6 → 1.16.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.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/mcp-servers-prompt.ts +23 -3
package/README.md
CHANGED
|
@@ -237,7 +237,7 @@ Large MCP servers advertise 30–80 tools (GitHub, Supabase, Linear, Playwright,
|
|
|
237
237
|
|
|
238
238
|
Resolution follows Pi: an exact `toolExposure` key wins, then the first matching `*` pattern in declaration order, then the server's `exposure`, then `direct`. Patterns are keyed by the **raw MCP tool name** (`tools/list`), not the Pi identifier, and `*` is the only wildcard — `get_*` matches `get_users`, while `.`, `+`, `(` and friends are literal. Matching is linear, so a pathological pattern in a shared `mcp.json` cannot hang the session.
|
|
239
239
|
|
|
240
|
-
**System-prompt discovery, disconnect hiding, and backwards compatibility.** Pi's own MCP client defaults an omitted `exposure` to `codemode`; this extension keeps `direct`, so an existing `mcp.json` that says nothing about exposure keeps activating every discovered tool (and on Pi `< 1.3.0`, `isError: true` continues rejecting with `McpError`). Because `codemode` and `tool_search` do not inline MCP server lists in their own tool descriptions, `before_agent_start` populates `systemPromptOptions.sections["mcp_servers"]` (capped at 4,096 characters) with enabled or connected indirect servers, how to reach each (`codemode` vs `tool_search`, falling back symmetrically when only one is active and omitting the section when neither is active), `not connected — mcp_connect "<name>"` hints for lazy/stopped servers (omitting disconnected servers if `mcp_connect` itself is inactive), and a sanitized one-line summary (`description`, or the connected server's first handshake `instructions` line). Server `namespace` identifiers and `<mcp_servers>` bullet headers are deterministically disambiguated across peer servers when distinct server names sanitize or project to the same script identifier (for example `my-srv` vs `my_srv`, `1srv` vs `_srv`, or `a` vs `_a`), while `mcp_connect "<name>"` hints
|
|
240
|
+
**System-prompt discovery, disconnect hiding, and backwards compatibility.** Pi's own MCP client defaults an omitted `exposure` to `codemode`; this extension keeps `direct`, so an existing `mcp.json` that says nothing about exposure keeps activating every discovered tool (and on Pi `< 1.3.0`, `isError: true` continues rejecting with `McpError`). Because `codemode` and `tool_search` do not inline MCP server lists in their own tool descriptions, `before_agent_start` populates `systemPromptOptions.sections["mcp_servers"]` (capped at 4,096 characters) with enabled or connected indirect servers, how to reach each (`codemode` vs `tool_search`, falling back symmetrically when only one is active and omitting the section when neither is active), `not connected — mcp_connect "<name>"` hints for lazy/stopped servers (omitting disconnected servers if `mcp_connect` itself is inactive), and a sanitized one-line summary (`description`, or the connected server's first handshake `instructions` line). Server `namespace` identifiers and `<mcp_servers>` bullet headers are deterministically disambiguated across peer servers when distinct server names sanitize or project to the same script identifier (for example `my-srv` vs `my_srv`, `1srv` vs `_srv`, or `a` vs `_a`), while `mcp_connect "<name>"` hints name the server only when sanitization leaves the configured name unchanged, because `mcp_connect` needs the exact configured name; a secret-shaped name, control characters, surrounding whitespace, or more than 120 characters would be rewritten, so the hint sends the model to `mcp_status` for the exact name (or, when `mcp_status` is inactive, only tells it to connect with `mcp_connect`). Reaching discovery tools (`codemode` / `tool_search`) are pre-activated at session start for all enabled or connected indirect servers (eager, lazy, and manually started `enabled: false`) so connecting a lazy server mid-session does not churn active tools, and restored after `/tree` (`session_tree`) without re-activating inactive `direct` tools; indirect tools activated during a session are also preserved across `--continue`, `/resume`, `/fork`, `/tree`, and `/reload`. When indirect tools (`deferred` or `codemode`) are present and neither `tool_search` nor `codemode` ends up active — or when Pi's `--tools` / `--exclude-tools` filter removes all of a server's indirect tools — Pi surfaces a session warning. Stopping, removing, or withdrawing a server's tool re-registers it as `hidden` and rejects stale calls until the server reconnects, so `tool_search` and `codemode` never surface disconnected tools. A server whose tools are all deferred or hidden is working as configured, not broken: `mcp_connect` verifies configured `direct` tools and rejects if `--tools` / `--exclude-tools` filtered out all indirect tools, while `/mcp <name>` plus `mcp_status` report `tools: { discovered, active, expected, inactiveDirect?, indirectFiltered? }` — `expected` being the number of `direct` tools, with `inactiveDirect` set when configured `direct` tools on a ready server are missing from Pi's active set and `indirectFiltered: true` when `--tools` / `--exclude-tools` filtered out all indirect tools. `/mcp <name>` appends `(N configured direct)` — plus `, M direct inactive` or `, indirect filtered by --tools / --exclude-tools` when applicable — to the `Tools:` line whenever exposure narrows the discovered set.
|
|
241
241
|
|
|
242
242
|
> [!NOTE]
|
|
243
243
|
> Pi 1.3.0's `--tools` CLI allowlist only auto-exempts `mcp__*` (double-underscore) identifiers. Because this extension names tools `<toolPrefix>_<server>_<tool>` (`mcp_*` by default), include `mcp_*` (or `<toolPrefix>_*`) when passing `--tools` on the CLI so deferred and codemode MCP tools remain registered for `tool_search` and `codemode` (for example: `--tools read,codemode,mcp_*`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mcp-extension",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.7",
|
|
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": [
|
|
@@ -38,6 +38,9 @@ const MAX_SAFE_SERVER_NAME_CHARS = 120;
|
|
|
38
38
|
/** Management tool name required to connect lazy/stopped servers from the prompt. */
|
|
39
39
|
const MCP_CONNECT_TOOL_NAME = "mcp_connect";
|
|
40
40
|
|
|
41
|
+
/** Management tool name that reports every configured server name verbatim. */
|
|
42
|
+
const MCP_STATUS_TOOL_NAME = "mcp_status";
|
|
43
|
+
|
|
41
44
|
export type IndirectReachMode = "codemode" | "tool_search";
|
|
42
45
|
|
|
43
46
|
export interface McpPromptServerEntry {
|
|
@@ -67,6 +70,7 @@ interface ReachAvailability {
|
|
|
67
70
|
codemode: boolean;
|
|
68
71
|
toolSearch: boolean;
|
|
69
72
|
mcpConnect: boolean;
|
|
73
|
+
mcpStatus: boolean;
|
|
70
74
|
}
|
|
71
75
|
|
|
72
76
|
function isReachingAvailable(
|
|
@@ -87,6 +91,7 @@ function resolveReachAvailability(
|
|
|
87
91
|
codemode: isReachingAvailable(active, allTools, CODEMODE_TOOL_NAME),
|
|
88
92
|
toolSearch: isReachingAvailable(active, allTools, TOOL_SEARCH_TOOL_NAME),
|
|
89
93
|
mcpConnect: active ? active.has(MCP_CONNECT_TOOL_NAME) : true,
|
|
94
|
+
mcpStatus: active ? active.has(MCP_STATUS_TOOL_NAME) : true,
|
|
90
95
|
};
|
|
91
96
|
}
|
|
92
97
|
|
|
@@ -135,17 +140,32 @@ function resolveServerSummary(entry: McpPromptServerEntry, maxLength: number): s
|
|
|
135
140
|
return pickFirstSummaryLine(entry.instructions, maxLength);
|
|
136
141
|
}
|
|
137
142
|
|
|
143
|
+
function formatDisconnectedConnectHint(entryName: string, hasMcpStatus: boolean): string {
|
|
144
|
+
const safeName = sanitizeNamespaceText(entryName, MAX_SAFE_SERVER_NAME_CHARS);
|
|
145
|
+
// WHY: `sanitizeNamespaceText` strips terminal escapes, trims, redacts secret-shaped text and
|
|
146
|
+
// truncates, so its output only matches `manager.getServer(name)` when it left the name intact.
|
|
147
|
+
// A redacted or truncated name is an argument `mcp_connect` rejects as unknown, while
|
|
148
|
+
// `mcp_status` returns every configured name verbatim (#342).
|
|
149
|
+
if (safeName === entryName) {
|
|
150
|
+
return `not connected — mcp_connect ${JSON.stringify(safeName)}`;
|
|
151
|
+
}
|
|
152
|
+
return hasMcpStatus
|
|
153
|
+
? "not connected — check mcp_status for the exact name and call mcp_connect"
|
|
154
|
+
: "not connected — connect with mcp_connect";
|
|
155
|
+
}
|
|
156
|
+
|
|
138
157
|
function buildServerHead(
|
|
139
158
|
entry: McpPromptServerEntry,
|
|
140
159
|
namespace: string,
|
|
141
160
|
modes: readonly IndirectReachMode[],
|
|
161
|
+
hasMcpStatus: boolean,
|
|
142
162
|
): string {
|
|
143
163
|
const reachTag = modes.join(", ");
|
|
144
164
|
if (entry.connected) {
|
|
145
165
|
return `- ${namespace} (${reachTag})`;
|
|
146
166
|
}
|
|
147
|
-
const
|
|
148
|
-
return `- ${namespace} (${reachTag},
|
|
167
|
+
const hint = formatDisconnectedConnectHint(entry.name, hasMcpStatus);
|
|
168
|
+
return `- ${namespace} (${reachTag}, ${hint})`;
|
|
149
169
|
}
|
|
150
170
|
|
|
151
171
|
function buildSectionIntro(
|
|
@@ -221,7 +241,7 @@ function preparePromptServers(
|
|
|
221
241
|
prepared.push({
|
|
222
242
|
entry,
|
|
223
243
|
modes,
|
|
224
|
-
head: buildServerHead(entry, namespace, modes),
|
|
244
|
+
head: buildServerHead(entry, namespace, modes, available.mcpStatus),
|
|
225
245
|
});
|
|
226
246
|
}
|
|
227
247
|
return prepared.sort((a, b) => compareCodePoints(a.entry.name, b.entry.name));
|