(
name: string,
params: Record<string, unknown>,
toolMetadata?: Record<string, unknown>,
runAsTask?: boolean,
)
| 1019 | }; |
| 1020 | |
| 1021 | const callTool = async ( |
| 1022 | name: string, |
| 1023 | params: Record<string, unknown>, |
| 1024 | toolMetadata?: Record<string, unknown>, |
| 1025 | runAsTask?: boolean, |
| 1026 | ): Promise<CompatibilityCallToolResult> => { |
| 1027 | lastToolCallOriginTabRef.current = currentTabRef.current; |
| 1028 | |
| 1029 | try { |
| 1030 | // Find the tool schema to clean parameters properly |
| 1031 | const tool = tools.find((t) => t.name === name); |
| 1032 | const cleanedParams = tool?.inputSchema |
| 1033 | ? cleanParams(params, tool.inputSchema as JsonSchemaType) |
| 1034 | : params; |
| 1035 | |
| 1036 | // Merge general metadata with tool-specific metadata |
| 1037 | // Tool-specific metadata takes precedence over general metadata |
| 1038 | const mergedMetadata = { |
| 1039 | ...metadata, // General metadata |
| 1040 | progressToken: progressTokenRef.current++, |
| 1041 | ...toolMetadata, // Tool-specific metadata |
| 1042 | }; |
| 1043 | |
| 1044 | const request: ClientRequest = { |
| 1045 | method: "tools/call" as const, |
| 1046 | params: { |
| 1047 | name, |
| 1048 | arguments: cleanedParams, |
| 1049 | _meta: mergedMetadata, |
| 1050 | }, |
| 1051 | }; |
| 1052 | |
| 1053 | if (runAsTask) { |
| 1054 | request.params = { |
| 1055 | ...request.params, |
| 1056 | task: { |
| 1057 | ttl: getMCPTaskTtl(config), |
| 1058 | }, |
| 1059 | }; |
| 1060 | } |
| 1061 | |
| 1062 | const response = await sendMCPRequest( |
| 1063 | request, |
| 1064 | CompatibilityCallToolResultSchema, |
| 1065 | "tools", |
| 1066 | ); |
| 1067 | |
| 1068 | // Check if this was a task-augmented request that returned a task reference |
| 1069 | // The server returns { task: { taskId, status, ... } } when a task is created |
| 1070 | const isTaskResult = ( |
| 1071 | res: unknown, |
| 1072 | ): res is { |
| 1073 | task: { taskId: string; status: string; pollInterval: number }; |
| 1074 | } => |
| 1075 | !!res && |
| 1076 | typeof res === "object" && |
| 1077 | "task" in res && |
| 1078 | !!res.task && |
no test coverage detected