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

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

Open
adhikasp opened this issue Nov 27, 2024 · 4 comments
Open

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

adhikasp opened this issue Nov 27, 2024 · 4 comments
Assignees

Comments

@adhikasp
Copy link

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

@dsp-ant dsp-ant self-assigned this Nov 27, 2024
@dsp-ant
Copy link
Member

dsp-ant commented Nov 27, 2024

Thank you for reporting. I take a look

@dsp-ant dsp-ant transferred this issue from modelcontextprotocol/servers Nov 27, 2024
@hemangjoshi37a
Copy link

Do we compulsorily need to use the app or we can interface with MCP with python ? this is somewhat confusing

@adhikasp
Copy link
Author

adhikasp commented Dec 2, 2024

@hemangjoshi37a yes you should be able to use MCP servers with python

Example of simple python client in here https://github.com/adhikasp/mcp-client-cli
Right now it only implement the tool calling from the spec, not the resources and other stuff

@hemangjoshi37a
Copy link

@adhikasp actually I already tried using with python but it throws so many errors

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

3 participants