Gavin Wiggins


LangChain MCP Client without LSP Warnings

Published on April 25, 2026
Tagged with python, langchain, ai, mcp

The LangChain documentation gives an example of using multiple MCP servers with an agent by defining a MultiServerMCPClient (see below). The example defines the MCP connections as a dictionary to the MultiServerMCPClient but this triggers LSP warnings about invalid argument types.

client = MultiServerMCPClient(
    {
        "math": {
            "transport": "stdio",
            "command": "python",
            "args": ["/path/to/math_server.py"],
        },
        "weather": {
            "transport": "http",
            "url": "http://localhost:8000/mcp",
        }
    }
)

To fix the LSP warnings, you can define the connections explicitly then pass them to the MultiServerMCPClient as shown below.

import asyncio

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_mcp_adapters.sessions import StreamableHttpConnection, StdioConnection
from langchain.agents import create_agent


async def main():
    http_conn: StreamableHttpConnection = {
        "transport": "streamable_http",
        "url": "http://localhost:8000/mcp",
    }

    stdio_conn: StdioConnection = {
        "transport": "stdio",
        "command": "python",
        "args": ["path/to/math_server.py"],
    }

    client = MultiServerMCPClient({"math": stdio_conn, "weather": http_conn})

    tools = await client.get_tools()
    agent = create_agent("claude-sonnet-4-6", tools)

    math_response = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "what's (3 + 5) x 12?"}]}
    )

    weather_response = await agent.ainvoke(
        {"messages": [{"role": "user", "content": "what is the weather in nyc?"}]}
    )

    print(math_response)
    print(weather_response)


if __name__ == "__main__":
    asyncio.run(main())

Gavin Wiggins © 2026
Made on a Mac with Genja. Hosted on GitHub Pages.