MCP Python client fails to load the server
Describe the bug
I am following the documentation that shows building a Python client. I already have a sample server that works well with Claude Desktop. This server sample is https://github.com/rchaganti/azure-mcp-server. However, when I try to run the client using uv run client.py C:\\GitHub\\azure-mcp-server\\src\\azure_mcp_server\\server.py, it fails with a message:
Traceback (most recent call last):
File "C:\GitHub\azure-mcp-server\src\azure_mcp_server\server.py", line 3, in
To Reproduce Steps to reproduce the behavior:
- Go to https://modelcontextprotocol.io/quickstart/client
- Follow the procedure to create an MCP client locally
- Download the Azure MCP Server sample from https://github.com/rchaganti/azure-mcp-server
- Run the client,
uv run client.py C:\\GitHub\\azure-mcp-server\\src\\azure_mcp_server\\server.py
Expected behavior Client starts and a chatbot starts with a query prompt.
Desktop:
- OS: Windows 11
- Browser Edge
Yeah I have this bug too, unfortunately I don't know why it happens, but I hope there will be an answer soon. I will tell you once I know why it happens 🫡
Actually found a solution: server_params = StdioServerParameters( command="uv", # Executable args=["run", "../server/server.py"], # Optional command line arguments env=None, # Optional environment variables ) Use uv run as command instead of python.
Atleast thats the case for me since I was new to uv and kinda missed that :|
Interesting. @gdilillo Where are you adding the StdioServerParameters()? can you point me to your example?
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
# Create server parameters for stdio connection
server_params = StdioServerParameters(
command="uv", # Executable
args=["run", "../server/server.py"], # Optional command line arguments
env=None, # Optional environment variables
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(
read, write
) as session:
# Initialize the connection
await session.initialize()
# List available tools
tools = await session.list_tools()
print(tools)
if __name__ == "__main__":
import asyncio
asyncio.run(run())
Here is my client script, its simplified for testing reasons, but in the quickstart example its this line:
command = "python" if is_python else "node"
server_params = StdioServerParameters(
command=command,
args=[server_script_path],
env=None
)
In the async def connect_to_server(self, server_script_path: str) method. Hope this helps :)
Thank you. For me, this does not solve, but the error moved from mcp to azure!
File "C:\Github\azure-mcp-server\src\azure_mcp_server\server.py", line 11, in
Maybe you forgot to add azure in the server modules. Try doing uv add azure in the server environment
Nah! Server works with Claude Desktop! So, there is something wrong in the way the client is trying to load. Seems like it is not getting the environment.
If I don't activate the client venv and run:
uv run .\client.py c:\github\azure-mcp-server\src\azure_mcp_server\server.py
warning: VIRTUAL_ENV=C:\GitHub\azure-mcp-server\.venv does not match the project environment path .venv and will be ignored; use --active to target the active environment instead
Traceback (most recent call last):
File "c:\github\azure-mcp-server\src\azure_mcp_server\server.py", line 3, in
The Python client documentation is certainly missing some step.
Idk if this helps, but I found out, that you just need all dependencies installed in your client environment, atleast that worked for me.
@gdilillo unfortunately, no! Even if it worked, I'd still question that design.
Actually found a solution: server_params = StdioServerParameters( command="uv", # Executable args=["run", "../server/server.py"], # Optional command line arguments env=None, # Optional environment variables ) Use uv run as command instead of python.
It works for me. Thank you so much!
You will need to specify the full path for uv command.
Try the command to get the full executable path which uv, then replace that in the configuration.
uv run mcp run client.py C:\\GitHub\\azure-mcp-server\\src\\azure_mcp_server\\server.
If I don't activate the client venv and run:
uv run .\client.py c:\github\azure-mcp-server\src\azure_mcp_server\server.py warning:
VIRTUAL_ENV=C:\GitHub\azure-mcp-server\.venvdoes not match the project environment path.venvand will be ignored; use--activeto target the active environment instead Traceback (most recent call last): File "c:\github\azure-mcp-server\src\azure_mcp_server\server.py", line 3, in from mcp.server.models import InitializationOptions ModuleNotFoundError: No module named 'mcp'The Python client documentation is certainly missing some step.
same issues