Skip to content

Commit ed35912

Browse files
committed
Fix tests for Pydantic 2.11
1 parent 58b989c commit ed35912

File tree

9 files changed

+49
-52
lines changed

9 files changed

+49
-52
lines changed

examples/clients/simple-chatbot/mcp_simple_chatbot/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ async def process_llm_response(self, llm_response: str) -> str:
322322
total = result["total"]
323323
percentage = (progress / total) * 100
324324
logging.info(
325-
f"Progress: {progress}/{total} "
326-
f"({percentage:.1f}%)"
325+
f"Progress: {progress}/{total} ({percentage:.1f}%)"
327326
)
328327

329328
return f"Tool execution result: {result}"

src/mcp/server/fastmcp/server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,9 @@ async def read_resource(self, uri: str | AnyUrl) -> Iterable[ReadResourceContent
652652
Returns:
653653
The resource content as either text or bytes
654654
"""
655-
assert (
656-
self._fastmcp is not None
657-
), "Context is not available outside of a request"
655+
assert self._fastmcp is not None, (
656+
"Context is not available outside of a request"
657+
)
658658
return await self._fastmcp.read_resource(uri)
659659

660660
async def log(

src/mcp/server/fastmcp/utilities/func_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def model_dump_one_level(self) -> dict[str, Any]:
2727
That is, sub-models etc are not dumped - they are kept as pydantic models.
2828
"""
2929
kwargs: dict[str, Any] = {}
30-
for field_name in self.model_fields.keys():
30+
for field_name in self.__class__.model_fields.keys():
3131
kwargs[field_name] = getattr(self, field_name)
3232
return kwargs
3333

src/mcp/server/lowlevel/server.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,12 @@ async def _handle_notification(self, notify: Any):
576576
assert type(notify) in self.notification_handlers
577577

578578
handler = self.notification_handlers[type(notify)]
579-
logger.debug(
580-
f"Dispatching notification of type " f"{type(notify).__name__}"
581-
)
579+
logger.debug(f"Dispatching notification of type {type(notify).__name__}")
582580

583581
try:
584582
await handler(notify)
585583
except Exception as err:
586-
logger.error(f"Uncaught exception in notification handler: " f"{err}")
584+
logger.error(f"Uncaught exception in notification handler: {err}")
587585

588586

589587
async def _ping_handler(request: types.PingRequest) -> types.ServerResult:

src/mcp/shared/memory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828

2929
@asynccontextmanager
30-
async def create_client_server_memory_streams() -> (
31-
AsyncGenerator[tuple[MessageStream, MessageStream], None]
32-
):
30+
async def create_client_server_memory_streams() -> AsyncGenerator[
31+
tuple[MessageStream, MessageStream], None
32+
]:
3333
"""
3434
Creates a pair of bidirectional memory streams for client-server communication.
3535

tests/issues/test_100_tool_listing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ def dummy_tool_func():
3030
# Verify each tool is unique and has the correct name
3131
tool_names = [tool.name for tool in tools]
3232
expected_names = [f"tool_{i}" for i in range(num_tools)]
33-
assert sorted(tool_names) == sorted(
34-
expected_names
35-
), "Tool names don't match expected names"
33+
assert sorted(tool_names) == sorted(expected_names), (
34+
"Tool names don't match expected names"
35+
)

tests/issues/test_152_resource_mime_type.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,31 +45,31 @@ def get_image_as_bytes() -> bytes:
4545
bytes_resource = mapping["test://image_bytes"]
4646

4747
# Verify mime types
48-
assert (
49-
string_resource.mimeType == "image/png"
50-
), "String resource mime type not respected"
51-
assert (
52-
bytes_resource.mimeType == "image/png"
53-
), "Bytes resource mime type not respected"
48+
assert string_resource.mimeType == "image/png", (
49+
"String resource mime type not respected"
50+
)
51+
assert bytes_resource.mimeType == "image/png", (
52+
"Bytes resource mime type not respected"
53+
)
5454

5555
# Also verify the content can be read correctly
5656
string_result = await client.read_resource(AnyUrl("test://image"))
5757
assert len(string_result.contents) == 1
58-
assert (
59-
getattr(string_result.contents[0], "text") == base64_string
60-
), "Base64 string mismatch"
61-
assert (
62-
string_result.contents[0].mimeType == "image/png"
63-
), "String content mime type not preserved"
58+
assert getattr(string_result.contents[0], "text") == base64_string, (
59+
"Base64 string mismatch"
60+
)
61+
assert string_result.contents[0].mimeType == "image/png", (
62+
"String content mime type not preserved"
63+
)
6464

6565
bytes_result = await client.read_resource(AnyUrl("test://image_bytes"))
6666
assert len(bytes_result.contents) == 1
6767
assert (
6868
base64.b64decode(getattr(bytes_result.contents[0], "blob")) == image_bytes
6969
), "Bytes mismatch"
70-
assert (
71-
bytes_result.contents[0].mimeType == "image/png"
72-
), "Bytes content mime type not preserved"
70+
assert bytes_result.contents[0].mimeType == "image/png", (
71+
"Bytes content mime type not preserved"
72+
)
7373

7474

7575
async def test_lowlevel_resource_mime_type():
@@ -119,28 +119,28 @@ async def handle_read_resource(uri: AnyUrl):
119119
bytes_resource = mapping["test://image_bytes"]
120120

121121
# Verify mime types
122-
assert (
123-
string_resource.mimeType == "image/png"
124-
), "String resource mime type not respected"
125-
assert (
126-
bytes_resource.mimeType == "image/png"
127-
), "Bytes resource mime type not respected"
122+
assert string_resource.mimeType == "image/png", (
123+
"String resource mime type not respected"
124+
)
125+
assert bytes_resource.mimeType == "image/png", (
126+
"Bytes resource mime type not respected"
127+
)
128128

129129
# Also verify the content can be read correctly
130130
string_result = await client.read_resource(AnyUrl("test://image"))
131131
assert len(string_result.contents) == 1
132-
assert (
133-
getattr(string_result.contents[0], "text") == base64_string
134-
), "Base64 string mismatch"
135-
assert (
136-
string_result.contents[0].mimeType == "image/png"
137-
), "String content mime type not preserved"
132+
assert getattr(string_result.contents[0], "text") == base64_string, (
133+
"Base64 string mismatch"
134+
)
135+
assert string_result.contents[0].mimeType == "image/png", (
136+
"String content mime type not preserved"
137+
)
138138

139139
bytes_result = await client.read_resource(AnyUrl("test://image_bytes"))
140140
assert len(bytes_result.contents) == 1
141141
assert (
142142
base64.b64decode(getattr(bytes_result.contents[0], "blob")) == image_bytes
143143
), "Bytes mismatch"
144-
assert (
145-
bytes_result.contents[0].mimeType == "image/png"
146-
), "Bytes content mime type not preserved"
144+
assert bytes_result.contents[0].mimeType == "image/png", (
145+
"Bytes content mime type not preserved"
146+
)

tests/issues/test_176_progress_token.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ async def test_progress_token_zero_first_call():
3535
await ctx.report_progress(10, 10) # Complete
3636

3737
# Verify progress notifications
38-
assert (
39-
mock_session.send_progress_notification.call_count == 3
40-
), "All progress notifications should be sent"
38+
assert mock_session.send_progress_notification.call_count == 3, (
39+
"All progress notifications should be sent"
40+
)
4141
mock_session.send_progress_notification.assert_any_call(
4242
progress_token=0, progress=0.0, total=10.0
4343
)

tests/issues/test_192_request_id.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ async def run_server():
8686
response = await server_reader.receive()
8787

8888
# Verify response ID matches request ID
89-
assert (
90-
response.root.id == custom_request_id
91-
), "Response ID should match request ID"
89+
assert response.root.id == custom_request_id, (
90+
"Response ID should match request ID"
91+
)
9292

9393
# Cancel server task
9494
tg.cancel_scope.cancel()

0 commit comments

Comments
 (0)