Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MCP client with npx not working when env parameter of StdioServerParameters is set #326

Copy link
Copy link
@maxguru

Description

@maxguru
Issue body actions

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
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.