in process fixes
This commit is contained in:
+11
-17
@@ -1,6 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
@@ -27,27 +26,22 @@ async def client() -> AsyncIterator[AsyncClient]:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mcp_endpoint_url() -> str:
|
||||
"""Provides the MCP endpoint URL for SDK-based client sessions."""
|
||||
return os.getenv("PERSONAL_MCP_TEST_HTTP_URL", "")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mcp_session_factory(mcp_endpoint_url: str):
|
||||
"""Provides a context manager factory for MCP SDK sessions.
|
||||
|
||||
Keeping stream/client/session enter and exit in the test task avoids
|
||||
cross-task cancel scope teardown errors from async generator fixtures.
|
||||
"""
|
||||
if not mcp_endpoint_url:
|
||||
pytest.skip("Set PERSONAL_MCP_TEST_HTTP_URL to run SDK-backed MCP endpoint tests.")
|
||||
def mcp_session_factory():
|
||||
"""Provides an in-process context manager factory for MCP SDK sessions."""
|
||||
|
||||
@asynccontextmanager
|
||||
async def create_session(*, initialize: bool = True) -> AsyncIterator[ClientSession]:
|
||||
app = create_app()
|
||||
mcp_url = f"http://testserver{app.state.settings.mcp_route}"
|
||||
async with (
|
||||
AsyncClient(timeout=10.0) as http_client,
|
||||
app.router.lifespan_context(app),
|
||||
AsyncClient(
|
||||
transport=ASGITransport(app=app),
|
||||
base_url="http://testserver",
|
||||
timeout=10.0,
|
||||
) as http_client,
|
||||
streamable_http_client(
|
||||
mcp_endpoint_url,
|
||||
mcp_url,
|
||||
http_client=http_client,
|
||||
) as (read_stream, write_stream, _),
|
||||
ClientSession(read_stream, write_stream) as session,
|
||||
|
||||
Reference in New Issue
Block a user