Skip to content

Commit cadbf31

Browse files
fix(mcp): return tool execution error on jq failure
1 parent 79374fd commit cadbf31

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/mcp-server/src/filtering.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ export async function maybeFilter(jqFilter: unknown | undefined, response: any):
1212
async function jq(json: any, jqFilter: string) {
1313
return (await initJq).json(json, jqFilter);
1414
}
15+
16+
export function isJqError(error: any): error is Error {
17+
return error instanceof Error && 'stderr' in error;
18+
}

packages/mcp-server/src/tools/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ export async function asBinaryContentResult(response: Response): Promise<ToolCal
8787
}
8888
}
8989

90+
export function asErrorResult(message: string): ToolCallResult {
91+
return {
92+
content: [
93+
{
94+
type: 'text',
95+
text: message,
96+
},
97+
],
98+
isError: true,
99+
};
100+
}
101+
90102
export type Metadata = {
91103
resource: string;
92104
operation: 'read' | 'write';

0 commit comments

Comments
 (0)