( url: string, args: any, extras: ToolExtras, )
| 26 | import { coerceArgsToSchema, safeParseToolCallArgs } from "./parseArgs"; |
| 27 | |
| 28 | async function callHttpTool( |
| 29 | url: string, |
| 30 | args: any, |
| 31 | extras: ToolExtras, |
| 32 | ): Promise<ContextItem[]> { |
| 33 | const response = await extras.fetch(url, { |
| 34 | method: "POST", |
| 35 | headers: { |
| 36 | "Content-Type": "application/json", |
| 37 | }, |
| 38 | body: JSON.stringify({ |
| 39 | arguments: args, |
| 40 | }), |
| 41 | }); |
| 42 | |
| 43 | const data = await response.json(); |
| 44 | |
| 45 | if (!response.ok) { |
| 46 | throw new Error(`Failed to call tool at ${url}:\n${JSON.stringify(data)}`); |
| 47 | } |
| 48 | |
| 49 | return data.output; |
| 50 | } |
| 51 | |
| 52 | export function encodeMCPToolUri(mcpId: string, toolName: string): string { |
| 53 | return `mcp://${encodeURIComponent(mcpId)}/${encodeURIComponent(toolName)}`; |
no test coverage detected