MCP StdioServerParameters

server_params = StdioServerParameters(
        command="npx",
        args=["-y", "@modelcontextprotocol/server-github"],
        # env={"GITHUB_PERSONAL_ACCESS_TOKEN": github_token}
    )

If I don’t specify the env parameter, the program can be executed normally.
But if I open the comment, the following error will appear after assigning a value to the env variable

‘npx’ is not recognized as an internal or external command,

operable program or batch file.

Hi @windrunnner
Thanks for reaching out and for using Agno! I’ve looped in the right engineers to help with your question. We usually respond within 48 hours, but if this is urgent, just let us know, and we’ll do our best to prioritize it.
Appreciate your patience—we’ll get back to you soon! :smile:

Hi @windrunnner thanks for reaching out. I think you are running a GitHub MCP agent right?
I would suggest first have a look at this cookbook example- agno/cookbook/tools/mcp/github.py at main · agno-agi/agno · GitHub

I tried on my system and it works, here’s the code I used with passing env

"""🐙 MCP GitHub Agent - Your Personal GitHub Explorer!

This example shows how to create a GitHub agent that uses MCP to explore,
analyze, and provide insights about GitHub repositories. The agent leverages the Model
Context Protocol (MCP) to interact with GitHub, allowing it to answer questions
about issues, pull requests, repository details and more.

Example prompts to try:
- "List open issues in the repository"
- "Show me recent pull requests"
- "What are the repository statistics?"
- "Find issues labeled as bugs"
- "Show me contributor activity"

Run: `pip install agno mcp openai` to install the dependencies
Environment variables needed:
- Create a GitHub personal access token following these steps:
    - https://github.com/modelcontextprotocol/servers/tree/main/src/github#setup
- GITHUB_TOKEN: Your GitHub personal access token
"""

import asyncio
import os
from textwrap import dedent

from agno.agent import Agent
from agno.tools.mcp import MCPTools
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client, get_default_environment


async def run_agent(message: str) -> None:
    """Run the GitHub agent with the given message."""
    github_token = os.getenv("GITHUB_TOKEN") or os.getenv(
        "GITHUB_ACCESS_TOKEN")
    if not github_token:
        raise ValueError("GITHUB_TOKEN environment variable is required")

    # Initialize the MCP server
    server_params = StdioServerParameters(
        command="npx",
        args=["-y", "@modelcontextprotocol/server-github"],
        env={'GITHUB_TOKEN': github_token},
    )

    # Create a client session to connect to the MCP server
    async with MCPTools(server_params=server_params) as mcp_tools:
        agent = Agent(
            tools=[mcp_tools],
            instructions=dedent("""\
                You are a GitHub assistant. Help users explore repositories and their activity.

                - Use headings to organize your responses
                - Be concise and focus on relevant information\
            """),
            markdown=True,
            show_tool_calls=True,
        )

        # Run the agent
        await agent.aprint_response(message, stream=True)


# Example usage
if __name__ == "__main__":
    # Pull request example
    asyncio.run(
        run_agent(
            "Tell me about payme. Github repo: https://github.com/kausmeows/payme. You can read the README for more information."
        )
    )


# More example prompts to explore:
"""
Issue queries:
1. "Find issues needing attention"
2. "Show me issues by label"
3. "What issues are being actively discussed?"
4. "Find related issues"
5. "Analyze issue resolution patterns"

Pull request queries:
1. "What PRs need review?"
2. "Show me recent merged PRs"
3. "Find PRs with conflicts"
4. "What features are being developed?"
5. "Analyze PR review patterns"

Repository queries:
1. "Show repository health metrics"
2. "What are the contribution guidelines?"
3. "Find documentation gaps"
4. "Analyze code quality trends"
5. "Show repository activity patterns"
"""

what i think is happening in your case is when you set a custom environment with just the GitHub token, the subprocess can’t find npx in the PATH since that environment variable is no longer available to the child process.

can you try this once-

from mcp.client.stdio import get_default_environment

    # Initialize the MCP server
    server_params = StdioServerParameters(
        command="npx",
        args=["-y", "@modelcontextprotocol/server-github"],
        env={**get_default_environment(), "GITHUB_TOKEN": github_token}
    )

also make sure npx is installed and is added to your PATH.

Let us know if you make it work!

Hi thanks, it worked by add **get_default_environment(). Thanks for the explanation, I will check if npx is on my environment path

env={**get_default_environment(), "GITHUB_TOKEN": github_token}