Skip to content

Python: Bug: cannot import name 'MCPStdioPlugin' from partially initialized module 'semantic_kernel.connectors.mcp' #11779

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

Closed
uday31in opened this issue Apr 28, 2025 · 1 comment
Assignees
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel

Comments

@uday31in
Copy link

Describe the bug
cannot import name 'MCPStdioPlugin' from partially initialized module 'semantic_kernel.connectors.mcp'

To Reproduce
Steps to reproduce the behavior:

import asyncio
import os
from datetime import datetime
from pathlib import Path

from semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread
from semantic_kernel.connectors.ai import FunctionChoiceBehavior
from semantic_kernel.connectors.mcp import MCPStdioPlugin
from semantic_kernel.functions import KernelArguments
from semantic_kernel.kernel import Kernel
from semantic_kernel.connectors.openapi_plugin import OpenAPIFunctionExecutionParameters
from semantic_kernel.connectors.ai.open_ai import AzureChatCompletion


async def main():
    async with (
        MCPStdioPlugin(
            name="Github",
            description="Github Plugin",
            command="docker",
            args=["run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server"],
            env={"GITHUB_PERSONAL_ACCESS_TOKEN": os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN")},
        ) as github_plugin,
    ):
        print("Github plugin started")

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

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots

cannot import name 'MCPStdioPlugin' from partially initialized module 'semantic_kernel.connectors.mcp' (most likely due to a circular import) (/Users/uday/git/uday31in/sk-mcp-client/.venv/lib/python3.13/site-packages/semantic_kernel/connectors/mcp.py)
  File "/Users/uday/git/uday31in/sk-mcp-client/mcp.py", line 8, in <module>
    from semantic_kernel.connectors.mcp import MCPStdioPlugin
  File "/Users/uday/git/uday31in/sk-mcp-client/mcp.py", line 8, in <module>
    from semantic_kernel.connectors.mcp import MCPStdioPlugin
ImportError: cannot import name 'MCPStdioPlugin' from partially initialized module 'semantic_kernel.connectors.mcp' (most likely due to a circular import) (/Users/uday/git/uday31in/sk-mcp-client/.venv/lib/python3.13/site-packages/semantic_kernel/connectors/mcp.py)

Platform

  • Language: Python
  • Source: semantic-kernel==1.28.1
  • AI model:GPT-4o
  • IDE: VS Code
  • OS: Mac

Additional context
Add any other context about the problem here.

@uday31in uday31in added the bug Something isn't working label Apr 28, 2025
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel triage labels Apr 28, 2025
@github-actions github-actions bot changed the title Bug: cannot import name 'MCPStdioPlugin' from partially initialized module 'semantic_kernel.connectors.mcp' Python: Bug: cannot import name 'MCPStdioPlugin' from partially initialized module 'semantic_kernel.connectors.mcp' Apr 28, 2025
@moonbox3 moonbox3 self-assigned this Apr 29, 2025
@moonbox3 moonbox3 removed the triage label Apr 29, 2025
@moonbox3
Copy link
Contributor

Hello @uday31in,

Your script is named mcp.py, which shadows the installed mcp package required by Semantic Kernel.
This causes a circular import error because semantic_kernel.connectors.mcp tries to import from the real mcp package, but ends up importing your script instead.

Please rename your script (for example, rename mcp.py to mcp_client.py or main.py).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working python Pull requests for the Python Semantic Kernel
Projects
Status: No status
Development

No branches or pull requests

3 participants