Skip to content

Rethrow if there's an MCP error #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025
Merged

Conversation

heyitsaamir
Copy link
Contributor

I added logging if there was an MCP error, but I also need to rethrow it. Added that and a test.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that errors from the MCP tool handler are not only logged but also propagated, and it adds a corresponding unit test.

  • Added throw e after logging the error in the catch block.
  • Introduced a test to verify that errors are logged and rethrown by the handler.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
external/mcpclient/src/mcp-client-plugin.ts Rethrow error in catch block after logging
external/mcpclient/src/mcp-client-plugin.spec.ts Added test to assert logging and propagation of errors
Comments suppressed due to low confidence (2)

external/mcpclient/src/mcp-client-plugin.ts:126

  • [nitpick] Use catch (e: unknown) instead of untyped catch (e) to improve type safety and enforce explicit error handling.
} catch (e) {

external/mcpclient/src/mcp-client-plugin.spec.ts:384

  • The test verifies logging and rethrow but doesn’t assert that client.close() is still called in the finally block on error. Consider mocking the client and adding an assertion to ensure resources are always cleaned up.
await expect(functions[0].handler({})).rejects.toThrow('Tool failed');

@heyitsaamir heyitsaamir merged commit cbc3ae3 into main May 23, 2025
5 checks passed
@heyitsaamir heyitsaamir deleted the aamirj/rethrowOnMcpError branch May 23, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants