Skip to content
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

Fix SamplingFnT Type Error and Add Dynamic VSCode MCP Server URL #366

Closed

Conversation

microsoftmj
Copy link

Fix SamplingFnT Type Error and Add Dynamic VSCode MCP Server URL

Overview

This PR resolves an issue with the SamplingFnT type in the MCP client session and adds support for dynamic VSCode MCP server URLs. The changes make the assistant more robust against type variations and improve integration with VSCode.

Issue Fixed

The assistant was failing with the following error:

Exception has occurred: ImportError
cannot import name 'SamplingFnT' from 'mcp.client.session' (/workspaces/semanticworkbench/assistants/codespace-assistant/.venv/lib/python3.11/site-packages/mcp/client/session.py)

This was caused by a type mismatch where SamplingFnT in the MCP client session was using RequestContext with two type parameters, but the installed version only accepted one.

Changes Made

This PR includes five main components:

  1. Core Type Fix:

    • Modified MCPSamplingMessageHandler type to use ellipsis syntax (...) for parameters
    • Removed explicit type annotations in handler methods that were causing compatibility issues
    • Updated related files to maintain type consistency
  2. Documentation:

    • Added comprehensive documentation in SAMPLING_FN_TYPE_ERROR_FIX.md explaining the issue and solution
    • Updated dynamic URL documentation with references to the fix
  3. Dynamic VSCode MCP Server URL:

    • Added utility functions to access the global variable containing the VSCode MCP server URL
    • Implemented configuration update functions to handle dynamic URLs in assistant configurations
    • Created scripts to automatically update configuration files when the server starts or stops
  4. Package Management and Configuration Updates:

    • Updated dependencies and configuration files for better compatibility
  5. CI Build Fix:

    • Added --isolated flag to uv commands in Python makefiles to prevent locking conflicts
    • This addresses issues with concurrent package installations in CI environments

Testing

The changes have been tested by:

  1. Running the assistant with python -m assistant.chat
  2. Verifying the server is running on port 3000
  3. Testing the VSCode MCP server with the test script
  4. Confirming the VSCode MCP server is accessible via the dynamic URL

Benefits

These changes provide several benefits:

  • Makes the assistant more robust against variations in type definitions
  • Ensures the VSCode MCP server URL is always up-to-date
  • Improves the developer experience by automating configuration updates
  • Provides clear documentation for future reference
  • Fixes CI build failures due to uv locking issues

This commit adds the ability to dynamically pull the VSCode MCP server URL from the VSCode output for the semantic workbench. It includes:

1. Modifications to the VSCode MCP server extension to store the URL in a global variable
2. Utility functions in the semantic workbench to access and update the dynamic URL
3. A script to update assistant configuration files with the current URL
4. Documentation for the new feature

The feature ensures that the semantic workbench always uses the correct VSCode MCP server URL, even if the port changes.
This commit fixes a critical type error in the MCP client session related to the SamplingFnT class. The issue was that the SamplingFnT class in the mcp.client.session module was using RequestContext with two type parameters, but the installed version of RequestContext only accepted one type parameter.

Key changes:
1. Modified the MCPSamplingMessageHandler type to use a more flexible approach with the ellipsis (...) syntax for parameters
2. Updated related files to use this new approach
3. Removed explicit type annotations in handler methods

This fix ensures that the VSCode MCP server dynamic URL feature works correctly without type errors, allowing the semantic workbench to properly connect to the VSCode MCP server.
… fix

This commit adds detailed documentation explaining the SamplingFnT type error issue and its resolution. The documentation includes:

1. A clear explanation of the original error and its root cause
2. Detailed description of the changes made to fix the issue
3. Code examples showing the before and after states
4. Testing procedures used to verify the fix
5. Impact analysis of the fix on the VSCode MCP server dynamic URL feature

This documentation will help developers understand the issue if they encounter similar problems in the future, and provides a reference for the technical details of the fix.
…rror reference

This commit enhances the VSCode MCP server dynamic URL documentation by adding a reference to the SamplingFnT type error fix in the troubleshooting section. The update includes:

1. A new troubleshooting entry specifically for the SamplingFnT type error
2. A direct link to the detailed documentation (SAMPLING_FN_TYPE_ERROR_FIX.md)
3. Integration with the existing troubleshooting workflow

This update ensures that users who encounter the SamplingFnT type error while using the VSCode MCP server dynamic URL feature can quickly find the solution and understand the technical details of the fix.
This commit updates the VSCode MCP server package management and configuration files to ensure compatibility with the SamplingFnT type error fix. The changes include:

1. Switching from pnpm to npm for package management (replacing pnpm-lock.yaml with package-lock.json)
2. Updating the extension.d.ts type definitions to align with the new type system
3. Updating the ASSISTANT_CONFIG.md documentation to reflect the changes

These updates ensure that the VSCode MCP server works correctly with the new type system and maintains compatibility with the rest of the semantic workbench.
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