pi-mcp-extension 1.16.0 → 1.16.1
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/tool-content.ts +12 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-mcp-extension",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.1",
|
|
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-content.ts
CHANGED
|
@@ -131,17 +131,17 @@ export function buildToolAnnotations(
|
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
133
|
* Convert a callTool result into Pi content blocks, falling back to
|
|
134
|
-
* `structuredContent` when the
|
|
134
|
+
* `structuredContent` when the converted blocks contain no images or nonblank text.
|
|
135
135
|
*/
|
|
136
136
|
export function buildToolCallContent(result: ToolCallResponse): PiContent[] {
|
|
137
137
|
const content = convertMcpContent((result.content ?? []) as Array<Record<string, unknown>>);
|
|
138
|
-
if (content.length > 0 || result.structuredContent === undefined) return content;
|
|
139
138
|
const structured = result.structuredContent;
|
|
140
|
-
|
|
141
|
-
type
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
|
|
139
|
+
if (structured === undefined ||
|
|
140
|
+
content.some((block) => block.type !== "text" || block.text.trim().length > 0)) {
|
|
141
|
+
return content;
|
|
142
|
+
}
|
|
143
|
+
const text = typeof structured === "string" ? structured : JSON.stringify(structured, null, 2);
|
|
144
|
+
return typeof text === "string" && text.trim().length > 0 ? [{ type: "text", text }] : content;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/** Text blocks of a failed tool call, joined into the McpError message. */
|
|
@@ -173,13 +173,15 @@ export function buildToolCallOutcome(
|
|
|
173
173
|
structuredContent: buildMcpScriptResult(result),
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
|
-
const
|
|
176
|
+
const errorText = toolErrorText(content);
|
|
177
|
+
const hasErrorText = errorText.trim().length > 0;
|
|
178
|
+
const errorMessage = hasErrorText ? errorText : "Tool reported an error";
|
|
177
179
|
if (!supportsErrorResult) {
|
|
178
180
|
throw new McpError(errorMessage, serverName, "tool");
|
|
179
181
|
}
|
|
180
|
-
const errorContent: PiContent[] =
|
|
182
|
+
const errorContent: PiContent[] = hasErrorText
|
|
181
183
|
? content
|
|
182
|
-
: [...content, { type: "text", text: errorMessage }];
|
|
184
|
+
: [...content.filter((c) => c.type !== "text"), { type: "text", text: errorMessage }];
|
|
183
185
|
return {
|
|
184
186
|
content: errorContent,
|
|
185
187
|
details: {},
|