Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot start client with npx #240

Open
nmoeller opened this issue Mar 4, 2025 · 1 comment
Open

Cannot start client with npx #240

nmoeller opened this issue Mar 4, 2025 · 1 comment

Comments

@nmoeller
Copy link

nmoeller commented Mar 4, 2025

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())
@dsp-ant
Copy link
Member

dsp-ant commented Mar 6, 2025

I would try providing the absolute path to NPX. If that works then the culprit would be path handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants