Skip to content

GitHub MCP server doesn't work in Python SDK #76

Closed
@adhikasp

Description

@adhikasp

The @modelcontextprotocol/server-github doesn't work with python SDK. Here is code to reproduce

import os
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
import dotenv

dotenv.load_dotenv()

async def main():
    server_params = StdioServerParameters(
        command="npx",
        args=["-y", "@modelcontextprotocol/server-github"],
        env={
            "GITHUB_PERSONAL_ACCESS_TOKEN": os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN"),
            "PATH": os.getenv("PATH")
        }
    )

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

            # Example: Call tool to list repositories
            repos = await session.call_tool(
                "search_repositories",
                arguments={"query": "user:adhikasp"}
            )
            print("Repositories:", repos)

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

Output

$ python repro_github.py 
GitHub MCP Server running on stdio
Traceback (most recent call last):
  File "/mnt/e/Workspace/mcp-exploration/repro_github.py", line 26, in main
    repos = await session.call_tool(
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/e/Workspace/mcp-exploration/.venv/lib/python3.12/site-packages/mcp/client/session.py", line 163, in call_tool
    return await self.send_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/e/Workspace/mcp-exploration/.venv/lib/python3.12/site-packages/mcp/shared/session.py", line 177, in send_request
    return result_type.model_validate(response_or_error.result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/e/Workspace/mcp-exploration/.venv/lib/python3.12/site-packages/pydantic/main.py", line 627, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for CallToolResult
content
  Field required [type=missing, input_value={'toolResult': {'total_co...ault_branch': 'main'}]}}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/missing

The server does work in inspector. Probably it have something to do with the Tool Result (Legacy) and the python sdk cannot parse legacy response?

image

Metadata

Metadata

Assignees

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