Skip to content

Fix - Issue #171 #235

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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Fix - Issue #171 #235

wants to merge 12 commits into from

Conversation

pablotoledo
Copy link
Contributor

This pull request enhances the AgentMCPServer by addressing issues with SSE (Server-Sent Events) transport and improving authentication handling. The most significant changes include patching the FastMCP.sse_app method to resolve ASGI errors, introducing middleware for authentication, and updating the routing logic for SSE and messaging endpoints.

Improvements to SSE Handling:

  • Patched the FastMCP.sse_app method to prevent returning a second Response after the SSE connection completes. This resolves the "Unexpected ASGI message 'http.response.start'" errors and prevents timeouts when chaining agents in server mode. (src/mcp_agent/mcp_server/agent_server.py, src/mcp_agent/mcp_server/agent_server.pyR55-R147)

Authentication Enhancements:

  • Introduced middleware for authentication, including AuthenticationMiddleware, AuthContextMiddleware, and RequireAuthMiddleware with BearerAuthBackend. This ensures secure handling of SSE and messaging endpoints. (src/mcp_agent/mcp_server/agent_server.py, src/mcp_agent/mcp_server/agent_server.pyR15-R28)
  • Added routes for authenticated SSE connections and message handling, with support for required scopes and custom Starlette routes. (src/mcp_agent/mcp_server/agent_server.py, src/mcp_agent/mcp_server/agent_server.pyR55-R147)

Documentation Update:

@pablotoledo pablotoledo marked this pull request as draft June 10, 2025 22:57
@pablotoledo
Copy link
Contributor Author

@evalstate I will test this PR tomorrow and I will update you the status ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants