-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Describe the bug
The semantic_kernel MCPStreamableHttpPlugin.aenter() method has a bug - it doesn't treat HTTP 401/403 as fatal errors. It just logs them and keeps waiting.
I think the bug is in the _inner_connect() method of the semantic kernel mcp.py file you shared above.
Python
async def _inner_connect(self, ready_event: asyncio.Event) -> None:
try:
await session.initialize()
except Exception as ex:
await self._exit_stack.aclose()
raise KernelPluginInvalidConfigurationError(
"Failed to initialize session. Please check your configuration."
) from ex
The Bug:
- connect() creates a background task running _inner_connect() and waits for ready_event
- _inner_connect() calls session.initialize(), which makes the HTTP request to the MCP server
- MCP server returns HTTP 401 Unauthorized
- session.initialize() raises an exception
- The exception handler in _inner_connect() raises KernelPluginInvalidConfigurationError
- BUG: The exception handler does NOT call ready_event.set()
- Meanwhile, connect() is still waiting at await ready_event.wait()
- Since ready_event is never set, connect() hangs forever (until PromptFlow's 30-second timeout)
- The exception is trapped in the background task and never propagates to our code
To Reproduce
Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Platform
- Language: [e.g. C#, Python]
- Source: [e.g. NuGet package version 0.1.0, pip package version 0.1.0, main branch of repository]
- AI model: [e.g. OpenAI:GPT-4o-mini(2024-07-18)]
- IDE: [e.g. Visual Studio, VS Code]
- OS: [e.g. Windows, Mac]
Additional context
Add any other context about the problem here.