Skip to content

Conversation

@alexa-perlov
Copy link
Contributor

Fixes

Summary

Was getting the following error when testing the Nova sample:

clients.client_server - ERROR - Error in generate_image: As of langchain-mcp-adapters 0.1.0, MultiServerMCPClient cannot be used as a context manager (e.g., async with MultiServerMCPClient(...)). Instead, you can do one of the following:

  1. client = MultiServerMCPClient(...)
    tools = await client.get_tools()
  2. client = MultiServerMCPClient(...)
    async with client.session(server_name) as session:
    tools = await load_mcp_tools(session)

Changes

Went with the first approach and updated the code to tools = await client.get_tools()

Please provide a summary of what's being changed

User experience

Please share what the user experience looks like before and after this change

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • I have reviewed the contributing guidelines
  • I have performed a self-review of this change
  • Changes have been tested
  • Changes are documented

Is this a breaking change? (Y/N)

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@alexa-perlov alexa-perlov changed the title fix: Update MultiServerMCPClient usage for langchain-mcp-adapters 0.1.0 fix(samples): Update MultiServerMCPClient usage for langchain-mcp-adapters 0.1.0 May 23, 2025
@alexa-perlov alexa-perlov marked this pull request as ready for review May 23, 2025 20:47
@alexa-perlov alexa-perlov requested a review from a team as a code owner May 23, 2025 20:47
@alexa-perlov alexa-perlov enabled auto-merge May 23, 2025 20:48
@alexa-perlov alexa-perlov added the code-review This is code in-review label May 27, 2025
@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.48%. Comparing base (6c6e512) to head (4f1aad3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #410   +/-   ##
=======================================
  Coverage   82.48%   82.48%           
=======================================
  Files         170      170           
  Lines       12101    12101           
  Branches     1842     1842           
=======================================
  Hits         9982     9982           
  Misses       1497     1497           
  Partials      622      622           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@awslabs-mcp awslabs-mcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review

Summary

This PR addresses an issue in the MultiServerMCPClient usage in two sample applications. The issue is due to a breaking change in the langchain-mcp-adapters 0.1.0 library where MultiServerMCPClient can no longer be used as a context manager.

Changes Analysis

The PR updates two client server implementations:
1.
2.

Both files had the same issue where they were using context manager pattern which is no longer supported. The PR removes the context manager and directly uses the mcp_client instance with .

The change follows option #1 in the error message:

Code Review

  • ✅ The implementation follows the recommended approach from the langchain-mcp-adapters error message
  • ✅ Code indentation is maintained consistently after removing the context manager block
  • ✅ Error handling is preserved
  • ✅ No functional changes other than the required MultiServerMCPClient usage pattern change
  • ✅ All existing functionality appears to be maintained

Tests

All checks are passing on the PR, and the code change is properly scoped to only what's necessary to fix the issue.

Recommendations

Approved - these changes appropriately address the breaking change in the langchain-mcp-adapters library and should allow the sample applications to work correctly again.

Run ID: 15280314994

awslabs-mcp
awslabs-mcp previously approved these changes May 27, 2025
Copy link
Collaborator

@awslabs-mcp awslabs-mcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review

Summary

This PR addresses an issue in the MultiServerMCPClient usage in two sample applications. The issue is due to a breaking change in the langchain-mcp-adapters 0.1.0 library where MultiServerMCPClient can no longer be used as a context manager.

Changes Analysis

The PR updates two client server implementations:

  1. samples/mcp-integration-with-kb/clients/client_server.py
  2. samples/mcp-integration-with-nova-canvas/clients/client_server.py

Both files had the same issue where they were using the context manager pattern which is no longer supported. The PR removes the context manager and directly uses the mcp_client instance with the awaited get_tools method.

The change follows option #1 in the error message from the library.

Code Review

  • ✅ The implementation follows the recommended approach from the langchain-mcp-adapters error message
  • ✅ Code indentation is maintained consistently after removing the context manager block
  • ✅ Error handling is preserved
  • ✅ No functional changes other than the required MultiServerMCPClient usage pattern change
  • ✅ All existing functionality appears to be maintained

Tests

All checks are passing on the PR, and the code change is properly scoped to only what is necessary to fix the issue.

Recommendations

Approved - these changes appropriately address the breaking change in the langchain-mcp-adapters library and should allow the sample applications to work correctly again.

Run ID: 15280314994

Copy link
Collaborator

@awslabs-mcp awslabs-mcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Review

Overview

This pull request addresses an issue with the MultiServerMCPClient usage in two sample applications. The problem stemmed from a breaking change in the langchain-mcp-adapters 0.1.0 library, which no longer allows MultiServerMCPClient to be used as a context manager.

Files Analyzed

  1. samples/mcp-integration-with-kb/clients/client_server.py
  2. samples/mcp-integration-with-nova-canvas/clients/client_server.py

Code Changes Assessment

The changes in both files follow the same pattern:

  1. Removal of context manager: Removed the async with mcp_client as client context manager pattern
  2. Direct client usage: Changed from client.get_tools() to await mcp_client.get_tools()
  3. Code indentation adjustment: Reduced the indentation level of the affected code blocks

The changes properly follow option #1 from the error message mentioned in the PR description:

client = MultiServerMCPClient(...)
tools = await client.get_tools()

Quality Assessment

  • Code correctness: The changes correctly implement the recommended approach for using MultiServerMCPClient with version 0.1.0+
  • Code style: Proper indentation is maintained throughout the modified sections
  • Error handling: All exception handling is preserved with the same structure
  • Functional equivalence: The changes maintain the same functionality, only modifying how the MCP client is initialized and used
  • Scope of changes: Changes are appropriately limited to only what's necessary to fix the issue

Test Results

All CI checks are passing, indicating that the changes do not introduce any regressions or new issues. The code coverage remains at 82.48%, unchanged from the base branch.

Recommendation

I approve this pull request as it:

  1. Correctly addresses the breaking change in the langchain-mcp-adapters library
  2. Makes minimal and focused changes to fix the issue
  3. Maintains all existing functionality
  4. Follows good coding practices
  5. Passes all automated checks

This change will ensure the sample applications continue to work correctly with the updated langchain-mcp-adapters library.

Run ID: 15285849697

@alexa-perlov alexa-perlov added this pull request to the merge queue May 27, 2025
Merged via the queue into main with commit c31173f May 27, 2025
133 checks passed
@alexa-perlov alexa-perlov deleted the fix/nova-canvas-sample branch May 27, 2025 21:34
hashimsharkh pushed a commit to hashimsharkh/mcp that referenced this pull request May 29, 2025
…pters 0.1.0 (awslabs#410)

* fix: Update MultiServerMCPClient usage for langchain-mcp-adapters 0.1.0

* fix: Update MultiServerMCPClient usage for langchain-mcp-adapters 0.1.0 for kb sample

* chore: cleaning up repetitive logs + vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code-review This is code in-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants