Skip to content

Conversation

@xizhibei
Copy link
Contributor

@xizhibei xizhibei commented Oct 1, 2025

Summary

  • OAuth Reconnection Flow: Implement completeOAuthAndReconnect method in ClientManager to properly handle OAuth callback completion with transport recreation
  • Session Storage Isolation: Add config-dir based session storage path handling in serveCommand for better session management
  • Event System Enhancement: Convert loading state events to enums for better type safety and consistency
  • Comprehensive Testing: Add thorough unit tests for OAuth reconnection, session storage, and loading state management

Key Changes

OAuth Callback Handling

  • New completeOAuthAndReconnect method in ClientManager that:
    • Completes OAuth flow with authorization code
    • Recreates both transport and client (required for HTTP transports)
    • Rediscovers server capabilities after reconnection
    • Handles both StreamableHTTPClientTransport and SSEClientTransport
    • Provides proper error handling and logging

Session Storage Improvements

  • Enhanced session storage path resolution in serveCommand:
    • Priority: explicit session-storage-path > config-dir/sessions > global default
    • Automatic session isolation when using config-dir
    • Maintains backward compatibility with existing configurations

Event System Type Safety

  • Convert loading state events from string literals to enums:
    • LoadingStateEvent enum in LoadingStateTracker
    • McpLoadingEvent enum in McpLoadingManager
    • Improved type safety and developer experience

Test Coverage

  • serveCommand: Add config-dir session storage isolation tests
  • ClientManager: Comprehensive OAuth reconnection tests covering success/failure scenarios
  • OAuth Routes: Updated callback tests to use new ClientManager reconnection method
  • Loading State: Enhanced test coverage for event system changes

Test Plan

  • OAuth reconnection works correctly for HTTP and SSE transports
  • Session storage isolation functions properly with config-dir
  • Loading state events maintain backward compatibility
  • Error handling covers all failure scenarios
  • All unit tests pass with new implementation

Breaking Changes

None - all changes are backward compatible and additive.

…and add tests

- Enhanced `serveCommand` to derive the session storage path based on provided options, prioritizing explicit paths over defaults.
- Added unit tests for `serveCommand` to verify correct session storage path behavior when using `config-dir` and `session-storage-path`.
- Updated `TransportFactory` to ensure client session paths align with server session paths for consistent isolation.
- Mocked dependencies in tests to prevent actual server initialization and ensure reliable test outcomes.
…teTracker and McpLoadingManager

- Added `LoadingStateEvent` enum to define event types for `LoadingStateTracker`, improving type safety and readability.
- Updated `LoadingStateEvents` interface to use the new enum for event names.
- Introduced `McpLoadingEvent` enum for `McpLoadingManager` to standardize event names and enhance maintainability.
- Refactored event emission in both classes to utilize the new enums, ensuring consistent event handling across the loading system.
- Updated OAuth routes to check for compatible transport types (HTTP or SSE) before completing the OAuth flow.
- Implemented reconnection logic after OAuth completion to establish an authenticated connection.
- Added capability discovery and instruction caching after successful reconnection.
- Enhanced unit tests to verify the new behavior and ensure proper handling of OAuth flow.
- Updated OAuth routes to validate transport types, ensuring only StreamableHTTPClientTransport and SSEClientTransport are accepted for OAuth flows.
- Removed the previous type guard for transport and replaced it with instanceof checks for better clarity and maintainability.
- Enhanced unit tests to mock transport instances correctly, ensuring they pass the instanceof checks for proper OAuth handling.
…tion

- Add `completeOAuthAndReconnect` method to `ClientManager` to handle
  OAuth completion and client reconnection for HTTP and SSE transports
- Support both `StreamableHTTPClientTransport` and `SSEClientTransport`
  in OAuth flow
- Recreate transport and client instances after OAuth completion since
  HTTP transports cannot be restarted
- Update client status and capabilities after successful reconnection
- Refactor OAuth callback route to delegate reconnection logic to
  `ClientManager`
- Add comprehensive tests for OAuth reconnection scenarios including
  success, unsupported transport, and error handling cases
- Import required transport classes and types in client manager and
  OAuth route files
@xizhibei xizhibei changed the title Fix/oauth callback feat(oauth): enhance OAuth flow with reconnect and capability discovery Oct 1, 2025
@xizhibei xizhibei merged commit 75f6f5a into main Oct 1, 2025
4 checks passed
@xizhibei xizhibei deleted the fix/oauth-callback branch October 1, 2025 14:58
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