Fix fastmcp stateless_http deprecation warning (#12108)

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Rohit Malhotra <rohitvinodmalhotra@gmail.com>
This commit is contained in:
Graham Neubig 2025-12-20 09:45:52 -05:00 committed by GitHub
parent 0677cebb25
commit 6605070d05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 4 deletions

View File

@ -36,7 +36,7 @@ from openhands.server.shared import conversation_manager, server_config
from openhands.server.types import AppMode
from openhands.version import get_version
mcp_app = mcp_server.http_app(path='/mcp')
mcp_app = mcp_server.http_app(path='/mcp', stateless_http=True)
def combine_lifespans(*lifespans):

View File

@ -25,9 +25,7 @@ from openhands.server.user_auth import (
)
from openhands.storage.data_models.conversation_metadata import ConversationMetadata
mcp_server = FastMCP(
'mcp', stateless_http=True, mask_error_details=True, dependencies=None
)
mcp_server = FastMCP('mcp', mask_error_details=True)
HOST = f'https://{os.getenv("WEB_HOST", "app.all-hands.dev").strip()}'
CONVERSATION_URL = HOST + '/conversations/{}'

View File

@ -1,3 +1,4 @@
import warnings
from unittest.mock import AsyncMock, patch
import pytest
@ -7,6 +8,38 @@ from openhands.server.routes.mcp import get_conversation_link
from openhands.server.types import AppMode
def test_mcp_server_no_stateless_http_deprecation_warning():
"""Test that mcp_server is created without stateless_http deprecation warning.
This test verifies the fix for the fastmcp deprecation warning:
'Providing `stateless_http` when creating a server is deprecated.
Provide it when calling `run` or as a global setting instead.'
The fix moves the stateless_http parameter from FastMCP() constructor
to the http_app() method call.
"""
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
# Import the mcp_server which triggers FastMCP creation
from openhands.server.routes.mcp import mcp_server
# Check that no deprecation warning about stateless_http was raised
stateless_http_warnings = [
warning
for warning in w
if issubclass(warning.category, DeprecationWarning)
and 'stateless_http' in str(warning.message)
]
assert len(stateless_http_warnings) == 0, (
f'Unexpected stateless_http deprecation warning: {stateless_http_warnings}'
)
# Verify mcp_server was created successfully
assert mcp_server is not None
@pytest.mark.asyncio
async def test_get_conversation_link_non_saas_mode():
"""Test get_conversation_link in non-SAAS mode."""