microsoft / microsoft/semantic-kernel

Python: Bug: MCPStreamableHttpPlugin.__aenter__() method doesn't treat HTTP 401/403 as fatal errors

Open
#13,414 3 comments 0 reactions 1 assignee View on GitHub

@aryanyk is already working on this.

Since Apr 29, 2026.

.NET bug python
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

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:

  1. connect() creates a background task running _inner_connect() and waits for ready_event
  2. _inner_connect() calls session.initialize(), which makes the HTTP request to the MCP server
  3. MCP server returns HTTP 401 Unauthorized
  4. session.initialize() raises an exception
  5. The exception handler in _inner_connect() raises KernelPluginInvalidConfigurationError
  6. BUG: The exception handler does NOT call ready_event.set()
  7. Meanwhile, connect() is still waiting at await ready_event.wait()
  8. Since ready_event is never set, connect() hangs forever (until PromptFlow's 30-second timeout)
  9. The exception is trapped in the background task and never propagates to our code

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.