Skip to content

Fix duplicated 'http.response.start' event error during client session disconnection #203

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion fastapi_mcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import Dict, Optional, Any, List, Union, Callable, Awaitable, Iterable, Literal, Sequence
from typing_extensions import Annotated, Doc

from fastapi import FastAPI, Request, APIRouter, params
from fastapi import FastAPI, Request, APIRouter, params, Response
from fastapi.openapi.utils import get_openapi
from mcp.server.lowlevel.server import Server
import mcp.types as types
Expand All @@ -18,6 +18,11 @@
logger = logging.getLogger(__name__)


class VoidResponse(Response):
async def __call__(self, scope, receive, send) -> None:
pass


class LowlevelMCPServer(Server):
def call_tool(self):
"""
Expand Down Expand Up @@ -214,6 +219,7 @@ async def handle_mcp_connection(request: Request):
self.server.create_initialization_options(notification_options=None, experimental_capabilities={}),
raise_exceptions=False,
)
return VoidResponse()

def _register_mcp_messages_endpoint_sse(
self,
Expand Down