fix(mcp): comprehensive improvements for MCP client setup and compatibility #274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The MCP example in
cookbook/mcp/agent_http.pyhad several issues preventing it from running properly:MultiServerMCPClientwas usingasync withsyntax which is no longer supported inlangchain-mcp-adapters0.1.0+GIGACHAT_BASE_URLin.env.examplewas causing 401 Unauthorized errorsrequirements.txtwith pinned versions for reproducible setupThis was causing a
NotImplementedError:As of langchain-mcp-adapters 0.1.0, MultiServerMCPClient cannot be used as a context manager (e.g., async with MultiServerMCPClient(...)).
Solution
This PR provides comprehensive fixes:
🔧 MCP Client Compatibility
async withusage forMultiServerMCPClientawait client.get_tools()🔐 Authentication Fix
GIGACHAT_BASE_URLfrom.env.examplethat was causing auth errors📦 Dependency Management
requirements.txtwith pinned package versions:langchain-gigachat==0.3.11langchain-mcp-adapters==0.1.8langgraph==0.5.1rich==14.0.0📖 Documentation Updates
requirements.txtfor installationGIGACHAT_BASE_URLremovalpip install -r requirements.txtand manual installation optionsTesting
NotImplementedErrorrequirements.txtFiles Changed
cookbook/mcp/agent_http.py: Fixed MCP client instantiation patterncookbook/mcp/.env.example: Removed problematicGIGACHAT_BASE_URLcookbook/mcp/requirements.txt: Added pinned dependencies (new file)cookbook/mcp/README.md: Updated installation and setup instructionsImpact
This fixes the MCP example to work properly with current versions of all dependencies and provides a better setup experience for users.