Skip to content

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

Closed as not planned

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.

Activity

  1. added
    .NETIssue or Pull requests regarding .NET code
    pythonPull requests for the Python Semantic Kernel
    on Dec 9, 2025
  2. changed the title [-]Bug: MCPStreamableHttpPlugin.__aenter__() method doesn't treat HTTP 401/403 as fatal errors[/-] [+].Net: Bug: MCPStreamableHttpPlugin.__aenter__() method doesn't treat HTTP 401/403 as fatal errors[/+] on Dec 9, 2025
  3. changed the title [-].Net: Bug: MCPStreamableHttpPlugin.__aenter__() method doesn't treat HTTP 401/403 as fatal errors[/-] [+]Python: Bug: MCPStreamableHttpPlugin.__aenter__() method doesn't treat HTTP 401/403 as fatal errors[/+] on Dec 9, 2025
  4. aryanyk commented on Jan 3, 2026

    @aryanyk

    Hi Swati Bararia (@bararia-swati) , Evan Mattson (@moonbox3)

    I would like to work on this. I can implement the status code check in aenter to raise an explicit exception for 401/403 errors.

  5. VedantMadane commented on Jan 17, 2026

    @VedantMadane

    I'm taking this issue and have a local fix in progress to treat HTTP 401/403 as fatal in MCPStreamableHttpPlugin.aenter with accompanying tests. I'll open a PR shortly.

  6. razashariff commented on Mar 16, 2026

    @razashariff

    Silently continuing on 401/403 is a fail-open pattern that masks authentication failures. MCPS (MCP Secure) takes the opposite approach — fail-closed by design. The secureMCP() middleware rejects any message without a valid ECDSA P-256 signature. No valid signature = no processing, no silent fallback.

    MCPS also provides a layer independent of HTTP status codes — per-message signing means authentication is verified at the message level, not the transport level. Even if the HTTP layer returns 200, a tampered or unsigned message body is rejected.

    Published as an IETF Internet-Draft and available on npm as mcp-secure (zero dependencies).

  7. github-actions commented on Oct 2, 2026

    @github-actions
    Contributor

    This issue is stale because it has been open for 90 days with no activity.

  8. added
    staleIssue is stale because it has been open for a while and has no activity
    on Oct 2, 2026
  9. github-actions commented on Oct 17, 2026

    @github-actions
    Contributor

    This issue was closed because it has been inactive for 14 days since being marked as stale.

  10. added a commit that references this issue on Nov 2, 2026
    9e683ce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETIssue or Pull requests regarding .NET codebugSomething isn't workingpythonPull requests for the Python Semantic KernelstaleIssue is stale because it has been open for a while and has no activity

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions