( connection: McpConnection, toolName: string, args: Record<string, unknown>, elicit: Elicit, onToolListChanged: (() => void) | undefined, )
| 155 | // --------------------------------------------------------------------------- |
| 156 | |
| 157 | const useConnection = ( |
| 158 | connection: McpConnection, |
| 159 | toolName: string, |
| 160 | args: Record<string, unknown>, |
| 161 | elicit: Elicit, |
| 162 | onToolListChanged: (() => void) | undefined, |
| 163 | ): Effect.Effect<unknown, McpInvocationError | McpOAuthReauthorizationRequired> => |
| 164 | Effect.gen(function* () { |
| 165 | installElicitationHandler(connection.client, elicit); |
| 166 | installToolListChangedHandler(connection.client, onToolListChanged); |
| 167 | return yield* Effect.tryPromise({ |
| 168 | try: () => connection.client.callTool({ name: toolName, arguments: args }), |
| 169 | catch: (cause) => { |
| 170 | if (Predicate.isTagged(cause, "McpOAuthReauthorizationRequired")) { |
| 171 | return new McpOAuthReauthorizationRequired({ |
| 172 | message: "MCP OAuth re-authorization required", |
| 173 | }); |
| 174 | } |
| 175 | const status = httpStatusFromCause(cause); |
| 176 | return new McpInvocationError({ |
| 177 | toolName, |
| 178 | message: `MCP tool call failed for ${toolName}`, |
| 179 | ...(status === undefined ? {} : { status }), |
| 180 | ...(isUnknownToolCause(cause, toolName) ? { unknownTool: true } : {}), |
| 181 | }); |
| 182 | }, |
| 183 | }).pipe( |
| 184 | Effect.withSpan("plugin.mcp.client.call_tool", { |
| 185 | attributes: { "mcp.tool.name": toolName }, |
| 186 | }), |
| 187 | ); |
| 188 | }); |
| 189 | |
| 190 | // --------------------------------------------------------------------------- |
| 191 | // Public API |
no test coverage detected