Skip to content

Commit 4f47dc2

Browse files
committed
fix: resolve pyright type checking errors
- Add type ignore comments for ExceptionGroup compatibility issues - Add proper type annotations for find_mcp_error function - All pre-commit checks now pass including pyright type checking
1 parent 227a8f8 commit 4f47dc2

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

tests/shared/test_streamable_http.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
try:
1515
from builtins import ExceptionGroup
1616
except ImportError:
17-
from exceptiongroup import ExceptionGroup
17+
from exceptiongroup import ExceptionGroup # type: ignore
1818

1919
import anyio
2020
import httpx
@@ -1615,62 +1615,64 @@ async def test_client_unexpected_content_type_raises_mcp_error():
16151615
async def html_endpoint(request: Request):
16161616
return HTMLResponse("<html><body>Not an MCP server</body></html>")
16171617

1618-
app = Starlette(routes=[
1619-
Route("/mcp", html_endpoint, methods=["GET", "POST"]),
1620-
])
1621-
1618+
app = Starlette(
1619+
routes=[
1620+
Route("/mcp", html_endpoint, methods=["GET", "POST"]),
1621+
]
1622+
)
1623+
16221624
# Start server on a random port using a simpler approach
16231625
with socket.socket() as s:
16241626
s.bind(("127.0.0.1", 0))
16251627
port = s.getsockname()[1]
1626-
1628+
16271629
# Use a thread instead of multiprocessing to avoid pickle issues
16281630
import asyncio
16291631
import threading
1630-
1632+
16311633
def run_server():
16321634
loop = asyncio.new_event_loop()
16331635
asyncio.set_event_loop(loop)
16341636
uvicorn.run(app, host="127.0.0.1", port=port, log_level="error")
1635-
1637+
16361638
server_thread = threading.Thread(target=run_server, daemon=True)
16371639
server_thread.start()
1638-
1640+
16391641
try:
16401642
# Give server time to start
16411643
await asyncio.sleep(0.5)
1642-
1644+
16431645
server_url = f"http://127.0.0.1:{port}"
1644-
1646+
16451647
# Test that the client raises McpError when server returns HTML
1646-
with pytest.raises(ExceptionGroup) as exc_info:
1648+
with pytest.raises(ExceptionGroup) as exc_info: # type: ignore
16471649
async with streamablehttp_client(f"{server_url}/mcp") as (
16481650
read_stream,
16491651
write_stream,
16501652
_,
16511653
):
16521654
async with ClientSession(read_stream, write_stream) as session:
16531655
await session.initialize()
1654-
1656+
16551657
# Extract the McpError from the ExceptionGroup (handle nested groups)
16561658
mcp_error = None
1657-
1658-
def find_mcp_error(exc_group):
1659-
for exc in exc_group.exceptions:
1659+
1660+
def find_mcp_error(exc_group: ExceptionGroup) -> McpError | None: # type: ignore
1661+
for exc in exc_group.exceptions: # type: ignore
16601662
if isinstance(exc, McpError):
16611663
return exc
1662-
elif isinstance(exc, ExceptionGroup):
1664+
elif isinstance(exc, ExceptionGroup): # type: ignore
16631665
result = find_mcp_error(exc)
16641666
if result:
16651667
return result
16661668
return None
1667-
1669+
16681670
mcp_error = find_mcp_error(exc_info.value)
1669-
1671+
16701672
assert mcp_error is not None, "Expected McpError in ExceptionGroup hierarchy"
16711673
assert "Unexpected content type" in str(mcp_error)
16721674
assert "text/html" in str(mcp_error)
1673-
1675+
16741676
finally:
16751677
# Server thread will be cleaned up automatically as daemon
16761678
pass

0 commit comments

Comments
 (0)