Skip to content

[Bug]: Using with Langchain MultiServerMCPClient aync contextmanager does not exit #974

Description

@shivaang14

Version

latest

App

  • Cursor
  • Windsurf
  • VSCode
  • VSCode Insiders
  • Claude Desktop
  • Other

Affected Models (if applicable)

  • Claude 3.5 Sonnet
  • Claude 3.7 Sonnet
  • GPT-4a
  • o4-mini
  • Other

Bug Description

I am using following python script

import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_mcp_adapters.tools import load_mcp_tools

async def main():
    client = MultiServerMCPClient(
        {
            "mongodb": {
                "transport": "stdio",
                "command": "npx",
                "args": [
                    "-y",
                    "mongodb-mcp-server@latest",
                    "--readOnly"
                ],
                "env": {
                    "MDB_MCP_CONNECTION_STRING": "mongodb://localhost:27017"
                }
            }
        }
    )

    async with client.session("mongodb") as session:
        tools = await load_mcp_tools(session)
        print(f"Loaded {len(tools)} tools:")
        for tool in tools:
            print(f"  - {tool.name}")


asyncio.run(main())

Output

Loaded 17 tools:
  - aggregate
  - collection-indexes
  - collection-schema
  - collection-storage-size
  - connect
  - count
  - db-stats
  - explain
  - export
  - find
  - list-collections
  - list-databases
  - mongodb-logs
  - atlas-local-connect-deployment
  - atlas-local-list-deployments
  - list-knowledge-sources
  - search-knowledge

And it is stuck here.

I am using

  • Python 3.12.11
  • langchain-mcp-adapters == 0.2.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions