Skip to content

Upgrades the mcp package dependency to 1.8.1 #137

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

Merged
merged 1 commit into from
May 18, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.4]

Updates the `mcp` dependency to `1.8.1`.

## [0.3.3]

Fixes the broken release from 0.3.2.
Expand Down
7 changes: 4 additions & 3 deletions fastapi_mcp/transport/sse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from anyio.streams.memory import MemoryObjectSendStream
from fastapi import Request, Response, BackgroundTasks, HTTPException
from fastapi.responses import JSONResponse
from mcp.shared.message import SessionMessage
from pydantic import ValidationError
from mcp.server.sse import SseServerTransport
from mcp.types import JSONRPCMessage, JSONRPCError, ErrorData
Expand Down Expand Up @@ -87,7 +88,7 @@ async def handle_fastapi_post_message(self, request: Request) -> Response:

# Create background task to send message
background_tasks = BackgroundTasks()
background_tasks.add_task(self._send_message_safely, writer, message)
background_tasks.add_task(self._send_message_safely, writer, SessionMessage(message))
logger.debug("Accepting message, will send in background")

# Return response with background task
Expand All @@ -96,7 +97,7 @@ async def handle_fastapi_post_message(self, request: Request) -> Response:
return response

async def _send_message_safely(
self, writer: MemoryObjectSendStream[JSONRPCMessage], message: Union[JSONRPCMessage, ValidationError]
self, writer: MemoryObjectSendStream[SessionMessage], message: Union[SessionMessage, ValidationError]
):
"""Send a message to the writer, avoiding ASGI race conditions"""

Expand All @@ -115,7 +116,7 @@ async def _send_message_safely(
id="unknown", # We don't know the ID from the invalid request
error=error_data,
)
error_message = JSONRPCMessage(root=json_rpc_error)
error_message = SessionMessage(JSONRPCMessage(root=json_rpc_error))
await writer.send(error_message)
else:
await writer.send(message)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "fastapi-mcp"
version = "0.3.3"
version = "0.3.4"
description = "Automatic MCP server generator for FastAPI applications - converts FastAPI endpoints to MCP tools for LLM integration"
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -29,7 +29,7 @@ dependencies = [
"fastapi>=0.100.0",
"typer>=0.9.0",
"rich>=13.0.0",
"mcp>=1.6.0",
"mcp>=1.8.1",
"pydantic>=2.0.0",
"pydantic-settings>=2.5.2",
"uvicorn>=0.20.0",
Expand Down
16 changes: 11 additions & 5 deletions tests/test_sse_mock_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from uuid import UUID
from unittest.mock import AsyncMock, MagicMock, patch
from fastapi import HTTPException, Request
from mcp.shared.message import SessionMessage
from pydantic import ValidationError
from anyio.streams.memory import MemoryObjectSendStream

Expand Down Expand Up @@ -145,9 +146,10 @@ async def test_send_message_safely_with_validation_error(
# Verify that the writer.send was called with a JSONRPCError
assert mock_writer.send.called
sent_message = mock_writer.send.call_args[0][0]
assert isinstance(sent_message, JSONRPCMessage)
assert isinstance(sent_message.root, JSONRPCError)
assert sent_message.root.error.code == -32700 # Parse error code
assert isinstance(sent_message, SessionMessage)
assert isinstance(sent_message.message, JSONRPCMessage)
assert isinstance(sent_message.message.root, JSONRPCError)
assert sent_message.message.root.error.code == -32700 # Parse error code


@pytest.mark.anyio
Expand All @@ -156,7 +158,9 @@ async def test_send_message_safely_with_jsonrpc_message(
) -> None:
"""Test sending a JSONRPCMessage safely."""
# Create a JSONRPCMessage
message = JSONRPCMessage.model_validate({"jsonrpc": "2.0", "id": "123", "method": "test_method", "params": {}})
message = SessionMessage(
JSONRPCMessage.model_validate({"jsonrpc": "2.0", "id": "123", "method": "test_method", "params": {}})
)

# Call the function
await mock_transport._send_message_safely(mock_writer, message)
Expand All @@ -176,7 +180,9 @@ async def test_send_message_safely_exception_handling(
mock_writer.send.side_effect = Exception("Test exception")

# Create a message
message = JSONRPCMessage.model_validate({"jsonrpc": "2.0", "id": "123", "method": "test_method", "params": {}})
message = SessionMessage(
JSONRPCMessage.model_validate({"jsonrpc": "2.0", "id": "123", "method": "test_method", "params": {}})
)

# Call the function - it should not raise an exception
await mock_transport._send_message_safely(mock_writer, message)
Expand Down
23 changes: 17 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.