Skip to content

feat: add and export error types for MCP #1755

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

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

utkarsh-dixit
Copy link
Collaborator

@utkarsh-dixit utkarsh-dixit commented Jul 15, 2025

TL;DR

Added specialized MCP error classes to improve error handling and provide more specific error types for MCP operations.

What changed?

  • Created a new file McpErrors.ts with specialized error classes for MCP operations:
    • McpInvalidInputError: For invalid input validation
    • McpServerExistsError: When attempting to create a server that already exists
    • McpServerNotFoundError: When a requested server is not found
    • McpOperationFailedError: When an MCP operation fails
    • McpParsingFailedError: When response parsing fails
    • McpConfigNotFoundError: When a configuration is not found
    • McpUnauthorizedError: When unauthorized access is attempted
  • Added error code constants in MCP_ERROR_CODES
  • Exported all new error classes in the main index.ts
  • Replaced generic ValidationError instances in the MCP class with the appropriate specialized error classes

How to test?

  1. Try various MCP operations with invalid inputs or edge cases
  2. Verify that the appropriate error classes are thrown
  3. Test error handling with try/catch blocks using instanceof checks:
try {
  await composio.mcp.create('', []);
} catch (error) {
  if (error instanceof McpInvalidInputError) {
    console.log('Invalid input provided');
  }
}

Why make this change?

This change improves error handling by providing more specific error types for MCP operations. This allows consumers of the SDK to:

  • Catch and handle specific error types more precisely
  • Implement better error recovery strategies based on error type
  • Get more descriptive error messages with appropriate error codes
  • Improve type safety with the McpError union type for type checking

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

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.

1 participant