Merge branch 'develop' into v5

This commit is contained in:
Danglewood
2026-07-20 15:59:31 -07:00
committed by GitHub
2 changed files with 20 additions and 1 deletions

View File

@@ -942,7 +942,12 @@ async def stdio_main(mcp_server):
os._exit(0) # pylint: disable=protected-access
for sig in (signal.SIGINT, signal.SIGTERM):
loop.add_signal_handler(sig, signal_handler)
try:
loop.add_signal_handler(sig, signal_handler)
except NotImplementedError:
# Windows event loops do not support signal handlers. The MCP client
# owns the stdio child process and closes it directly.
break
logger.info("Starting OpenBB MCP Server in STDIO mode. Press Ctrl+C to stop.")

View File

@@ -1,5 +1,6 @@
"""Unit tests for app module."""
import asyncio
from unittest.mock import MagicMock, patch
import pytest
@@ -13,6 +14,7 @@ from openbb_mcp_server.app.app import (
_read_system_prompt_file,
_strip_api_prefix,
create_mcp_server,
stdio_main,
)
from openbb_mcp_server.models.settings import MCPSettings
@@ -56,6 +58,18 @@ def test_read_system_prompt_file(tmp_path):
assert _read_system_prompt_file("nonexistent.txt") is None
@pytest.mark.asyncio
async def test_stdio_main_runs_when_signal_handlers_are_unsupported():
"""Windows event loops can serve stdio without registering signal handlers."""
loop = asyncio.get_running_loop()
mcp_server = MagicMock()
with patch.object(loop, "add_signal_handler", side_effect=NotImplementedError):
await stdio_main(mcp_server)
mcp_server.run.assert_called_once_with("stdio")
@patch("openbb_mcp_server.app.app.process_fastapi_routes_for_mcp")
@patch("openbb_mcp_server.app.app.CategoryIndex")
@patch("openbb_mcp_server.app.app.FastMCP.from_fastapi")