Skip to content

Commit c966951

Browse files
committed
refactor: clean up code formatting and remove unused imports across server and test modules
1 parent b25098d commit c966951

4 files changed

Lines changed: 7 additions & 24 deletions

File tree

src/apcore_mcp/server/router.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,7 @@ async def _handle_stream(
450450

451451
async for chunk in stream_iter:
452452
if not isinstance(chunk, dict):
453-
raise TypeError(
454-
f"stream chunk must be dict, got {type(chunk).__name__}: {chunk!r}"
455-
)
453+
raise TypeError(f"stream chunk must be dict, got {type(chunk).__name__}: {chunk!r}")
456454
# Redact each chunk before sending so sensitive fields never reach
457455
# the client via progress notifications, even before final accumulation.
458456
safe_chunk = self._maybe_redact(tool_name, chunk)
@@ -481,8 +479,6 @@ async def _handle_stream(
481479
except Exception as error:
482480
logger.error("handle_call stream error for %s: %s", tool_name, error)
483481
error_info = self._error_mapper.to_mcp_error(error)
484-
stream_error_content: list[dict[str, Any]] = [
485-
{"type": "text", "text": self._build_error_text(error_info)}
486-
]
482+
stream_error_content: list[dict[str, Any]] = [{"type": "text", "text": self._build_error_text(error_info)}]
487483
self._attach_traceparent(stream_error_content, context)
488484
return (stream_error_content, True, context.trace_id if context is not None else None)

src/apcore_mcp/server/server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def __init__(
4949
) -> None:
5050
transport_lower = transport.lower()
5151
if transport_lower not in _VALID_TRANSPORTS:
52-
raise ValueError(
53-
f"Unknown transport: {transport!r}. Expected one of {sorted(_VALID_TRANSPORTS)}"
54-
)
52+
raise ValueError(f"Unknown transport: {transport!r}. Expected one of {sorted(_VALID_TRANSPORTS)}")
5553
self._registry_or_executor = registry_or_executor
5654
self._transport = transport_lower
5755
self._host = host

tests/server/test_async_task_bridge.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@
1313
from typing import Any
1414

1515
import pytest
16-
1716
from apcore.async_task import AsyncTaskManager, TaskStatus
1817
from apcore.errors import TaskLimitExceededError
1918

2019
from apcore_mcp.server.async_task_bridge import META_TOOL_NAMES, AsyncTaskBridge
2120
from apcore_mcp.server.factory import MCPServerFactory
2221

23-
2422
# ---------------------------------------------------------------------------
2523
# Stubs
2624
# ---------------------------------------------------------------------------
@@ -119,9 +117,7 @@ async def test_status_tool_returns_result_when_completed() -> None:
119117
break
120118
await asyncio.sleep(0.005)
121119

122-
content, is_error, _ = await bridge.handle_meta_tool(
123-
"__apcore_task_status", {"task_id": task_id}
124-
)
120+
content, is_error, _ = await bridge.handle_meta_tool("__apcore_task_status", {"task_id": task_id})
125121
assert is_error is False
126122
body = json.loads(content[0]["text"])
127123
assert body["status"] == "completed"
@@ -132,9 +128,7 @@ async def test_status_tool_returns_result_when_completed() -> None:
132128
async def test_status_tool_unknown_task_id() -> None:
133129
mgr = AsyncTaskManager(_SlowExecutor())
134130
bridge = AsyncTaskBridge(mgr)
135-
content, is_error, _ = await bridge.handle_meta_tool(
136-
"__apcore_task_status", {"task_id": "missing"}
137-
)
131+
content, is_error, _ = await bridge.handle_meta_tool("__apcore_task_status", {"task_id": "missing"})
138132
assert is_error is True
139133
body = json.loads(content[0]["text"])
140134
assert body["error"] == "ASYNC_TASK_NOT_FOUND"
@@ -154,9 +148,7 @@ async def test_cancel_tool_cancels_running_task() -> None:
154148
envelope = await bridge.submit("m", {}, None)
155149
task_id = envelope["task_id"]
156150

157-
content, is_error, _ = await bridge.handle_meta_tool(
158-
"__apcore_task_cancel", {"task_id": task_id}
159-
)
151+
content, is_error, _ = await bridge.handle_meta_tool("__apcore_task_cancel", {"task_id": task_id})
160152
assert is_error is False
161153
body = json.loads(content[0]["text"])
162154
assert body["task_id"] == task_id
@@ -246,9 +238,7 @@ async def send(notification: dict[str, Any]) -> None:
246238
from apcore import Context
247239

248240
ctx = Context.create()
249-
await bridge._submit_with_progress(
250-
"m", {}, ctx, progress_token="tok-1", send_notification=send
251-
)
241+
await bridge._submit_with_progress("m", {}, ctx, progress_token="tok-1", send_notification=send)
252242
# Simulate the module invoking the installed progress callback.
253243
cb = ctx.data["_mcp_progress"]
254244
await cb(0.5, 1.0, "halfway")

tests/test_observability.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import annotations
99

1010
from typing import Any
11-
from unittest.mock import patch
1211

1312
import pytest
1413

0 commit comments

Comments
 (0)