Skip to content

Commit 56cccb2

Browse files
committed
style: Apply ruff formatting fixes
Auto-formatted by pre-commit ruff-format hook: - 5 files reformatted - 221 files left unchanged This resolves the pre-commit formatting check.
1 parent ac8e973 commit 56cccb2

File tree

5 files changed

+94
-300
lines changed

5 files changed

+94
-300
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ async def stdio_client(server: StdioServerParameters, errlog: TextIO = sys.stder
124124
process = await _create_platform_compatible_process(
125125
command=command,
126126
args=server.args,
127-
env=(
128-
{**get_default_environment(), **server.env}
129-
if server.env is not None
130-
else get_default_environment()
131-
),
127+
env=({**get_default_environment(), **server.env} if server.env is not None else get_default_environment()),
132128
errlog=errlog,
133129
cwd=server.cwd,
134130
)
@@ -172,9 +168,7 @@ async def stdin_writer():
172168
try:
173169
async with write_stream_reader:
174170
async for session_message in write_stream_reader:
175-
json = session_message.message.model_dump_json(
176-
by_alias=True, exclude_none=True
177-
)
171+
json = session_message.message.model_dump_json(by_alias=True, exclude_none=True)
178172
await process.stdin.send(
179173
(json + "\n").encode(
180174
encoding=server.encoding,
@@ -260,9 +254,7 @@ async def _create_platform_compatible_process(
260254
return process
261255

262256

263-
async def _terminate_process_tree(
264-
process: Process | FallbackProcess, timeout_seconds: float | None = None
265-
) -> None:
257+
async def _terminate_process_tree(process: Process | FallbackProcess, timeout_seconds: float | None = None) -> None:
266258
"""
267259
Terminate a process and all its children using platform-specific methods.
268260

tests/client/test_stdio.py

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232

3333

3434
@pytest.mark.anyio
35-
@pytest.mark.skip(
36-
"Skip context manager timing test - process termination varies by platform"
37-
)
35+
@pytest.mark.skip("Skip context manager timing test - process termination varies by platform")
3836
async def test_stdio_context_manager_exiting():
3937
async with stdio_client(StdioServerParameters(command=tee)) as (_, _):
4038
pass
@@ -68,20 +66,14 @@ async def test_stdio_client():
6866
break
6967

7068
assert len(read_messages) == 2
71-
assert read_messages[0] == JSONRPCMessage(
72-
root=JSONRPCRequest(jsonrpc="2.0", id=1, method="ping")
73-
)
74-
assert read_messages[1] == JSONRPCMessage(
75-
root=JSONRPCResponse(jsonrpc="2.0", id=2, result={})
76-
)
69+
assert read_messages[0] == JSONRPCMessage(root=JSONRPCRequest(jsonrpc="2.0", id=1, method="ping"))
70+
assert read_messages[1] == JSONRPCMessage(root=JSONRPCResponse(jsonrpc="2.0", id=2, result={}))
7771

7872

7973
@pytest.mark.anyio
8074
async def test_stdio_client_bad_path():
8175
"""Check that the connection doesn't hang if process errors."""
82-
server_params = StdioServerParameters(
83-
command="python", args=["-c", "non-existent-file.py"]
84-
)
76+
server_params = StdioServerParameters(command="python", args=["-c", "non-existent-file.py"])
8577
async with stdio_client(server_params) as (read_stream, write_stream):
8678
async with ClientSession(read_stream, write_stream) as session:
8779
# The session should raise an error when the connection closes
@@ -267,9 +259,7 @@ class TestChildProcessCleanup:
267259
"""
268260

269261
@pytest.mark.anyio
270-
@pytest.mark.filterwarnings(
271-
"ignore::ResourceWarning" if sys.platform == "win32" else "default"
272-
)
262+
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
273263
async def test_basic_child_process_cleanup(self):
274264
"""
275265
Test basic parent-child process cleanup.
@@ -318,9 +308,7 @@ async def test_basic_child_process_cleanup(self):
318308
print("\nStarting child process termination test...")
319309

320310
# Start the parent process
321-
proc = await _create_platform_compatible_process(
322-
sys.executable, ["-c", parent_script]
323-
)
311+
proc = await _create_platform_compatible_process(sys.executable, ["-c", parent_script])
324312

325313
# Wait for processes to start
326314
await anyio.sleep(0.5)
@@ -334,9 +322,7 @@ async def test_basic_child_process_cleanup(self):
334322
await anyio.sleep(0.3)
335323
size_after_wait = os.path.getsize(marker_file)
336324
assert size_after_wait > initial_size, "Child process should be writing"
337-
print(
338-
f"Child is writing (file grew from {initial_size} to {size_after_wait} bytes)"
339-
)
325+
print(f"Child is writing (file grew from {initial_size} to {size_after_wait} bytes)")
340326

341327
# Terminate using our function
342328
print("Terminating process and children...")
@@ -352,9 +338,9 @@ async def test_basic_child_process_cleanup(self):
352338
final_size = os.path.getsize(marker_file)
353339

354340
print(f"After cleanup: file size {size_after_cleanup} -> {final_size}")
355-
assert (
356-
final_size == size_after_cleanup
357-
), f"Child process still running! File grew by {final_size - size_after_cleanup} bytes"
341+
assert final_size == size_after_cleanup, (
342+
f"Child process still running! File grew by {final_size - size_after_cleanup} bytes"
343+
)
358344

359345
print("SUCCESS: Child process was properly terminated")
360346

@@ -367,9 +353,7 @@ async def test_basic_child_process_cleanup(self):
367353
pass
368354

369355
@pytest.mark.anyio
370-
@pytest.mark.filterwarnings(
371-
"ignore::ResourceWarning" if sys.platform == "win32" else "default"
372-
)
356+
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
373357
async def test_nested_process_tree(self):
374358
"""
375359
Test nested process tree cleanup (parent → child → grandchild).
@@ -429,9 +413,7 @@ async def test_nested_process_tree(self):
429413
)
430414

431415
# Start the parent process
432-
proc = await _create_platform_compatible_process(
433-
sys.executable, ["-c", parent_script]
434-
)
416+
proc = await _create_platform_compatible_process(sys.executable, ["-c", parent_script])
435417

436418
# Let all processes start
437419
await anyio.sleep(1.0)
@@ -477,9 +459,7 @@ async def test_nested_process_tree(self):
477459
pass
478460

479461
@pytest.mark.anyio
480-
@pytest.mark.filterwarnings(
481-
"ignore::ResourceWarning" if sys.platform == "win32" else "default"
482-
)
462+
@pytest.mark.filterwarnings("ignore::ResourceWarning" if sys.platform == "win32" else "default")
483463
async def test_early_parent_exit(self):
484464
"""
485465
Test cleanup when parent exits during termination sequence.
@@ -523,9 +503,7 @@ def handle_term(sig, frame):
523503
)
524504

525505
# Start the parent process
526-
proc = await _create_platform_compatible_process(
527-
sys.executable, ["-c", parent_script]
528-
)
506+
proc = await _create_platform_compatible_process(sys.executable, ["-c", parent_script])
529507

530508
# Let child start writing
531509
await anyio.sleep(0.5)
@@ -561,9 +539,7 @@ def handle_term(sig, frame):
561539

562540

563541
@pytest.mark.anyio
564-
@pytest.mark.skip(
565-
"Skip graceful exit timing test - process termination varies by platform"
566-
)
542+
@pytest.mark.skip("Skip graceful exit timing test - process termination varies by platform")
567543
async def test_stdio_client_graceful_stdin_exit():
568544
"""
569545
Test that a process exits gracefully when stdin is closed,
@@ -620,9 +596,7 @@ async def test_stdio_client_graceful_stdin_exit():
620596

621597

622598
@pytest.mark.anyio
623-
@pytest.mark.skip(
624-
"Skip stdin close timing test - process termination varies by platform"
625-
)
599+
@pytest.mark.skip("Skip stdin close timing test - process termination varies by platform")
626600
async def test_stdio_client_stdin_close_ignored():
627601
"""
628602
Test that when a process ignores stdin closure, the shutdown sequence

tests/server/fastmcp/test_integration.py

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ def run_server_with_transport(module_name: str, port: int, transport: str) -> No
8080
import sys
8181

8282
# Add examples/snippets to Python path for multiprocessing context
83-
snippets_path = os.path.join(
84-
os.path.dirname(__file__), "..", "..", "..", "examples", "snippets"
85-
)
83+
snippets_path = os.path.join(os.path.dirname(__file__), "..", "..", "..", "examples", "snippets")
8684
sys.path.insert(0, os.path.abspath(snippets_path))
8785

8886
# Import the servers module in the multiprocessing context
@@ -131,9 +129,7 @@ def run_server_with_transport(module_name: str, port: int, transport: str) -> No
131129
else:
132130
raise ValueError(f"Invalid transport for test server: {transport}")
133131

134-
server = uvicorn.Server(
135-
config=uvicorn.Config(app=app, host="127.0.0.1", port=port, log_level="error")
136-
)
132+
server = uvicorn.Server(config=uvicorn.Config(app=app, host="127.0.0.1", port=port, log_level="error"))
137133
print(f"Starting {transport} server on port {port}")
138134
server.run()
139135

@@ -173,9 +169,7 @@ def server_transport(request, server_port: int) -> Generator[str, None, None]:
173169
time.sleep(delay)
174170
attempt += 1
175171
else:
176-
raise RuntimeError(
177-
f"Server failed to start after {max_attempts} attempts (port {server_port})"
178-
)
172+
raise RuntimeError(f"Server failed to start after {max_attempts} attempts (port {server_port})")
179173

180174
yield transport
181175

@@ -352,14 +346,10 @@ async def test_basic_prompts(server_transport: str, server_url: str) -> None:
352346

353347
# Test review_code prompt
354348
prompts = await session.list_prompts()
355-
review_prompt = next(
356-
(p for p in prompts.prompts if p.name == "review_code"), None
357-
)
349+
review_prompt = next((p for p in prompts.prompts if p.name == "review_code"), None)
358350
assert review_prompt is not None
359351

360-
prompt_result = await session.get_prompt(
361-
"review_code", {"code": "def hello():\n print('Hello')"}
362-
)
352+
prompt_result = await session.get_prompt("review_code", {"code": "def hello():\n print('Hello')"})
363353
assert isinstance(prompt_result, GetPromptResult)
364354
assert len(prompt_result.messages) == 1
365355
assert isinstance(prompt_result.messages[0].content, TextContent)
@@ -415,18 +405,16 @@ async def test_tool_progress(server_transport: str, server_url: str) -> None:
415405
assert result.capabilities.tools is not None
416406

417407
# Test long_running_task tool that reports progress
418-
tool_result = await session.call_tool(
419-
"long_running_task", {"task_name": "test", "steps": 3}
420-
)
408+
tool_result = await session.call_tool("long_running_task", {"task_name": "test", "steps": 3})
421409
assert len(tool_result.content) == 1
422410
assert isinstance(tool_result.content[0], TextContent)
423411
assert "Task 'test' completed" in tool_result.content[0].text
424412

425413
# Verify that progress notifications or log messages were sent
426414
# Progress can come through either progress notifications or log messages
427-
total_notifications = len(
428-
notification_collector.progress_notifications
429-
) + len(notification_collector.log_messages)
415+
total_notifications = len(notification_collector.progress_notifications) + len(
416+
notification_collector.log_messages
417+
)
430418
assert total_notifications > 0
431419

432420

@@ -447,9 +435,7 @@ async def test_sampling(server_transport: str, server_url: str) -> None:
447435

448436
async with client_cm as client_streams:
449437
read_stream, write_stream = unpack_streams(client_streams)
450-
async with ClientSession(
451-
read_stream, write_stream, sampling_callback=sampling_callback
452-
) as session:
438+
async with ClientSession(read_stream, write_stream, sampling_callback=sampling_callback) as session:
453439
# Test initialization
454440
result = await session.initialize()
455441
assert isinstance(result, InitializeResult)
@@ -480,9 +466,7 @@ async def test_elicitation(server_transport: str, server_url: str) -> None:
480466

481467
async with client_cm as client_streams:
482468
read_stream, write_stream = unpack_streams(client_streams)
483-
async with ClientSession(
484-
read_stream, write_stream, elicitation_callback=elicitation_callback
485-
) as session:
469+
async with ClientSession(read_stream, write_stream, elicitation_callback=elicitation_callback) as session:
486470
# Test initialization
487471
result = await session.initialize()
488472
assert isinstance(result, InitializeResult)
@@ -528,9 +512,7 @@ async def test_completion(server_transport: str, server_url: str) -> None:
528512
assert len(prompts.prompts) > 0
529513

530514
# Test getting a prompt
531-
prompt_result = await session.get_prompt(
532-
"review_code", {"language": "python", "code": "def test(): pass"}
533-
)
515+
prompt_result = await session.get_prompt("review_code", {"language": "python", "code": "def test(): pass"})
534516
assert len(prompt_result.messages) > 0
535517

536518

@@ -642,9 +624,7 @@ async def test_structured_output(server_transport: str, server_url: str) -> None
642624
assert result.serverInfo.name == "Structured Output Example"
643625

644626
# Test get_weather tool
645-
weather_result = await session.call_tool(
646-
"get_weather", {"city": "New York"}
647-
)
627+
weather_result = await session.call_tool("get_weather", {"city": "New York"})
648628
assert len(weather_result.content) == 1
649629
assert isinstance(weather_result.content[0], TextContent)
650630

0 commit comments

Comments
 (0)