( input: InvokeMcpToolInput, )
| 221 | } |
| 222 | |
| 223 | export const invokeMcpTool = ( |
| 224 | input: InvokeMcpToolInput, |
| 225 | ): Effect.Effect< |
| 226 | unknown, |
| 227 | McpConnectionError | McpInvocationError | McpOAuthReauthorizationRequired |
| 228 | > => |
| 229 | Effect.gen(function* () { |
| 230 | const args = argsRecord(input.args); |
| 231 | |
| 232 | const connection = yield* Effect.acquireRelease( |
| 233 | input.connector.pipe( |
| 234 | Effect.withSpan("plugin.mcp.connection.acquire", { |
| 235 | attributes: { "plugin.mcp.transport": input.transport }, |
| 236 | }), |
| 237 | ), |
| 238 | (conn) => |
| 239 | Effect.ignore( |
| 240 | Effect.tryPromise({ |
| 241 | try: () => conn.close(), |
| 242 | catch: () => |
| 243 | new McpConnectionError({ |
| 244 | transport: input.transport, |
| 245 | message: "Failed to close MCP connection", |
| 246 | }), |
| 247 | }), |
| 248 | ), |
| 249 | ); |
| 250 | |
| 251 | return yield* useConnection( |
| 252 | connection, |
| 253 | input.toolName, |
| 254 | args, |
| 255 | input.elicit, |
| 256 | input.onToolListChanged, |
| 257 | ); |
| 258 | }).pipe( |
| 259 | Effect.scoped, |
| 260 | Effect.withSpan("plugin.mcp.invoke", { |
| 261 | attributes: { |
| 262 | "mcp.tool.name": input.toolName, |
| 263 | "plugin.mcp.tool_id": input.toolId, |
| 264 | "plugin.mcp.transport": input.transport, |
| 265 | }, |
| 266 | }), |
| 267 | ); |
no test coverage detected