Closed
Description
MCP client code using StdioServerParameters with npx
command is not working (with any MCP server) when its env
parameter is set to something other than None
.
Demo code:
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command="npx",
args=["-y", "@modelcontextprotocol/server-filesystem", "/home"],
env={} # fail
# env=None # no fail
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
tools = await session.list_tools()
if __name__ == "__main__":
import asyncio
asyncio.run(run())
Fail output:
sh: 1: mcp-server-filesystem: not found
***hangs***
No fail output:
Secure MCP Filesystem Server running on stdio
Allowed directories: [ '/home' ]
Interestingly, running npm i @modelcontextprotocol/server-filesystem
and using node directly works fine:
server_params = StdioServerParameters(
command="node",
args=["/home/user/node_modules/@modelcontextprotocol/server-filesystem/dist/index.js", "/home"],
env={} # no fail
)
Desktop:
- OS: Tested on Gentoo and Ubuntu 24.04.2 LTS
- Version: mcp-1.4.1
Metadata
Metadata
Assignees
Labels
No labels