Skip to content

Conversation

@xy200303
Copy link

…o FastMCP, implement RootsListChangedNotification handling, simplify capability check logic, and optimize the use of the TRANSPORTS variable

This PR improves code maintainability and functionality by adding a public mcp_server property to FastMCP, implementing server-side handling for RootsListChangedNotification, simplifying the check_client_capability method, and optimizing the use of the TRANSPORTS variable in the run method.

Motivation and Context

The changes address several issues:

  1. Direct access to private _mcp_server property in InMemoryTransport causing type checking warnings
  2. Missing server-side handling for RootsListChangedNotification, making the client method effectively unusable
  3. Complex and redundant capability check logic that was hard to maintain
  4. Unsafe access to private __args__ property of Literal type in the run method

These improvements enhance code maintainability, readability, and robustness while maintaining backward compatibility.

How Has This Been Tested?

All changes have been thoroughly tested using the project's existing test suite:

  • Client tests: 167 passed, 3 skipped, 1 xfailed (expected failure unrelated to changes)
  • Server tests: 443 passed, 1 skipped, 1 failed (failure unrelated to changes)
  • Shared module tests: 146 passed, 1 skipped

The tests cover various scenarios including:

  • In-memory transport functionality with FastMCP
  • Server session initialization and capability checking
  • Client notification handling
  • Various transport protocols (stdio, sse, streamable-http)

Breaking Changes

No breaking changes. All modifications maintain backward compatibility and follow existing code patterns.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the https://modelcontextprotocol.io
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

The changes were implemented with a focus on:

  1. Improving code maintainability by reducing complexity and removing unsafe practices
  2. Enhancing functionality by implementing missing server-side handling
  3. Maintaining backward compatibility to ensure existing applications continue to work
  4. Following the project's existing architectural patterns and conventions

…o FastMCP, implement RootsListChangedNotification handling, simplify capability check logic, and optimize the use of the TRANSPORTS variable
…o FastMCP, implement RootsListChangedNotification handling, simplify capability check logic, and optimize the use of the TRANSPORTS variable
…o FastMCP, implement RootsListChangedNotification handling, simplify capability check logic, and optimize the use of the TRANSPORTS variable
…o FastMCP, implement RootsListChangedNotification handling, simplify capability check logic, and optimize the use of the TRANSPORTS variable
…o FastMCP, implement RootsListChangedNotification handling, simplify capability check logic, and optimize the use of the TRANSPORTS variable
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