( input: InvokeMcpToolInput, )
| 207 | } |
| 208 | |
| 209 | export const invokeMcpTool = ( |
| 210 | input: InvokeMcpToolInput, |
| 211 | ): Effect.Effect< |
| 212 | unknown, |
| 213 | McpConnectionError | McpInvocationError | McpOAuthReauthorizationRequired |
| 214 | > => |
| 215 | Effect.gen(function* () { |
| 216 | const args = argsRecord(input.args); |
| 217 | |
| 218 | const connection = yield* Effect.acquireRelease( |
| 219 | input.connector.pipe( |
| 220 | Effect.withSpan("plugin.mcp.connection.acquire", { |
| 221 | attributes: { "plugin.mcp.transport": input.transport }, |
| 222 | }), |
| 223 | ), |
| 224 | (conn) => |
| 225 | Effect.ignore( |
| 226 | Effect.tryPromise({ |
| 227 | try: () => conn.close(), |
| 228 | catch: () => |
| 229 | new McpConnectionError({ |
| 230 | transport: input.transport, |
| 231 | message: "Failed to close MCP connection", |
| 232 | }), |
| 233 | }), |
| 234 | ), |
| 235 | ); |
| 236 | |
| 237 | return yield* useConnection( |
| 238 | connection, |
| 239 | input.toolName, |
| 240 | args, |
| 241 | input.elicit, |
| 242 | input.onToolListChanged, |
| 243 | ); |
| 244 | }).pipe( |
| 245 | Effect.scoped, |
| 246 | Effect.withSpan("plugin.mcp.invoke", { |
| 247 | attributes: { |
| 248 | "mcp.tool.name": input.toolName, |
| 249 | "plugin.mcp.tool_id": input.toolId, |
| 250 | "plugin.mcp.transport": input.transport, |
| 251 | }, |
| 252 | }), |
| 253 | ); |
no test coverage detected