Skip to content

Cannot start client with npx #240

Closed
Closed
@nmoeller

Description

@nmoeller

Describe the bug
I wanted to try running the client sample with the server-everything mcp server.
Unfortunatly i always have the issue that i get the following error message :

[[WinError 2] The system cannot find the file specified](https://discuss.python.org/t/filenotfounderror-winerror-2-the-system-cannot-find-the-file-specified/9757)

The issues seems to be related that it cannot find npx, but i have installed node,npm and npx.
When i am running npx -v in a standalone console it responds with 10.8.0. Also when debugging the get_default_environment() contains my Path variable which contains the path to node / npx.

Do you have any idea of what could be wrong ? Could somebody verify that this works on other Machines as expected and it's due to my machine ?

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from mcp import types

# Create server parameters for stdio connection
server_params = StdioServerParameters(
    command="npx", # Executable
    args=["-y @modelcontextprotocol/server-everything"], # Optional command line arguments
    env=None # Optional environment variables
)

# Optional: create a sampling callback
async def handle_sampling_message(message: types.CreateMessageRequestParams) -> types.CreateMessageResult:
    return types.CreateMessageResult(
        role="assistant",
        content=types.TextContent(
            type="text",
            text="Hello, world! from model",
        ),
        model="gpt-3.5-turbo",
        stopReason="endTurn",
    )

async def run():
    async with stdio_client(server_params) as (read, write):
        async with ClientSession(read, write, sampling_callback=handle_sampling_message) as session:
            # Initialize the connection
            await session.initialize()

            # List available prompts
            prompts = await session.list_prompts()

            # Get a prompt
            prompt = await session.get_prompt("example-prompt", arguments={"arg1": "value"})

            # List available resources
            resources = await session.list_resources()

            # List available tools
            tools = await session.list_tools()

            # Read a resource
            content, mime_type = await session.read_resource("file://some/path")

            # Call a tool
            result = await session.call_tool("tool-name", arguments={"arg1": "value"})

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

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