Skip to content

Commit 3fa7bc7

Browse files
Kludexihrpr
andauthored
tests: add lowest dependency tests (#1067)
Co-authored-by: ihrpr <[email protected]>
1 parent adf3271 commit 3fa7bc7

File tree

5 files changed

+473
-499
lines changed

5 files changed

+473
-499
lines changed

.github/workflows/shared.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
test:
3030
runs-on: ${{ matrix.os }}
3131
timeout-minutes: 10
32+
continue-on-error: true
3233
strategy:
3334
matrix:
3435
python-version: ["3.10", "3.11", "3.12", "3.13"]
@@ -48,8 +49,14 @@ jobs:
4849

4950
- name: Run pytest
5051
run: uv run --frozen --no-sync pytest
51-
continue-on-error: true
5252

53+
# This must run last as it modifies the environment!
54+
- name: Run pytest with lowest versions
55+
run: |
56+
uv sync --all-extras --upgrade
57+
uv run --no-sync pytest
58+
env:
59+
UV_RESOLUTION: lowest-direct
5360
readme-snippets:
5461
runs-on: ubuntu-latest
5562
steps:

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies = [
2525
"anyio>=4.5",
2626
"httpx>=0.27",
2727
"httpx-sse>=0.4",
28-
"pydantic>=2.7.2,<3.0.0",
28+
"pydantic>=2.8.0,<3.0.0",
2929
"starlette>=0.27",
3030
"python-multipart>=0.0.9",
3131
"sse-starlette>=1.6.1",
@@ -36,14 +36,13 @@ dependencies = [
3636

3737
[project.optional-dependencies]
3838
rich = ["rich>=13.9.4"]
39-
cli = ["typer>=0.12.4", "python-dotenv>=1.0.0"]
39+
cli = ["typer>=0.16.0", "python-dotenv>=1.0.0"]
4040
ws = ["websockets>=15.0.1"]
4141

4242
[project.scripts]
4343
mcp = "mcp.cli:app [cli]"
4444

4545
[tool.uv]
46-
resolution = "lowest-direct"
4746
default-groups = ["dev", "docs"]
4847
required-version = ">=0.7.2"
4948

@@ -58,6 +57,7 @@ dev = [
5857
"pytest-examples>=0.0.14",
5958
"pytest-pretty>=1.2.0",
6059
"inline-snapshot>=0.23.0",
60+
"dirty-equals>=0.9.0",
6161
]
6262
docs = [
6363
"mkdocs>=1.6.1",
@@ -124,5 +124,5 @@ filterwarnings = [
124124
# This should be fixed on Uvicorn's side.
125125
"ignore::DeprecationWarning:websockets",
126126
"ignore:websockets.server.WebSocketServerProtocol is deprecated:DeprecationWarning",
127-
"ignore:Returning str or bytes.*:DeprecationWarning:mcp.server.lowlevel"
127+
"ignore:Returning str or bytes.*:DeprecationWarning:mcp.server.lowlevel",
128128
]

tests/issues/test_188_concurrency.py

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,46 @@
11
import anyio
22
import pytest
3-
from pydantic import AnyUrl
43

54
from mcp.server.fastmcp import FastMCP
6-
from mcp.shared.memory import (
7-
create_connected_server_and_client_session as create_session,
8-
)
9-
10-
_sleep_time_seconds = 0.01
11-
_resource_name = "slow://slow_resource"
5+
from mcp.shared.memory import create_connected_server_and_client_session as create_session
126

137

148
@pytest.mark.anyio
159
async def test_messages_are_executed_concurrently():
1610
server = FastMCP("test")
17-
call_timestamps = []
11+
event = anyio.Event()
12+
tool_started = anyio.Event()
13+
call_order = []
1814

1915
@server.tool("sleep")
2016
async def sleep_tool():
21-
call_timestamps.append(("tool_start_time", anyio.current_time()))
22-
await anyio.sleep(_sleep_time_seconds)
23-
call_timestamps.append(("tool_end_time", anyio.current_time()))
17+
call_order.append("waiting_for_event")
18+
tool_started.set()
19+
await event.wait()
20+
call_order.append("tool_end")
2421
return "done"
2522

26-
@server.resource(_resource_name)
27-
async def slow_resource():
28-
call_timestamps.append(("resource_start_time", anyio.current_time()))
29-
await anyio.sleep(_sleep_time_seconds)
30-
call_timestamps.append(("resource_end_time", anyio.current_time()))
23+
@server.tool("trigger")
24+
async def trigger():
25+
# Wait for tool to start before setting the event
26+
await tool_started.wait()
27+
call_order.append("trigger_started")
28+
event.set()
29+
call_order.append("trigger_end")
3130
return "slow"
3231

3332
async with create_session(server._mcp_server) as client_session:
33+
# First tool will wait on event, second will set it
3434
async with anyio.create_task_group() as tg:
35-
for _ in range(10):
36-
tg.start_soon(client_session.call_tool, "sleep")
37-
tg.start_soon(client_session.read_resource, AnyUrl(_resource_name))
38-
39-
active_calls = 0
40-
max_concurrent_calls = 0
41-
for call_type, _ in sorted(call_timestamps, key=lambda x: x[1]):
42-
if "start" in call_type:
43-
active_calls += 1
44-
max_concurrent_calls = max(max_concurrent_calls, active_calls)
45-
else:
46-
active_calls -= 1
47-
print(f"Max concurrent calls: {max_concurrent_calls}")
48-
assert max_concurrent_calls > 1, "No concurrent calls were executed"
49-
50-
51-
def main():
52-
anyio.run(test_messages_are_executed_concurrently)
53-
54-
55-
if __name__ == "__main__":
56-
import logging
57-
58-
logging.basicConfig(level=logging.DEBUG)
59-
60-
main()
35+
# Start the tool first (it will wait on event)
36+
tg.start_soon(client_session.call_tool, "sleep")
37+
# Then the trigger tool will set the event to allow the first tool to continue
38+
await client_session.call_tool("trigger")
39+
40+
# Verify that both ran concurrently
41+
assert call_order == [
42+
"waiting_for_event",
43+
"trigger_started",
44+
"trigger_end",
45+
"tool_end",
46+
], f"Expected concurrent execution, but got: {call_order}"

tests/server/fastmcp/test_func_metadata.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import annotated_types
55
import pytest
6+
from dirty_equals import IsPartialDict
67
from pydantic import BaseModel, Field
78

89
from mcp.server.fastmcp.utilities.func_metadata import func_metadata
@@ -202,11 +203,8 @@ def func_dict_any() -> dict[str, Any]:
202203
return {"a": 1, "b": "hello", "c": [1, 2, 3]}
203204

204205
meta = func_metadata(func_dict_any)
205-
assert meta.output_schema == {
206-
"additionalProperties": True,
207-
"type": "object",
208-
"title": "func_dict_anyDictOutput",
209-
}
206+
207+
assert meta.output_schema == IsPartialDict(type="object", title="func_dict_anyDictOutput")
210208

211209
# Test dict[str, str]
212210
def func_dict_str() -> dict[str, str]:

0 commit comments

Comments
 (0)