You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
Activity
[-]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[/+][-].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[/+]aryanyk commentedon Jan 3, 2026
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.
VedantMadane commentedon Jan 17, 2026
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.
fix(python): ensure ready_event is set on MCP connection failures
razashariff commentedon Mar 16, 2026
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).github-actions commentedon Oct 2, 2026
This issue is stale because it has been open for 90 days with no activity.
github-actions commentedon Oct 17, 2026
This issue was closed because it has been inactive for 14 days since being marked as stale.
Python: Propagate MCP initialization failures (microsoft#14095)