Skip to content

Commit 3e146f8

Browse files
committed
lint
1 parent b48a13f commit 3e146f8

5 files changed

Lines changed: 34 additions & 25 deletions

File tree

dash/mcp/primitives/tools/descriptions/description_background_callbacks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from typing import TYPE_CHECKING
1010

11+
from ..tool_background_tasks import GET_RESULT_TOOL_NAME
1112
from .base import ToolDescriptionSource
1213

1314
if TYPE_CHECKING:
@@ -19,9 +20,9 @@ class BackgroundCallbackDescription(ToolDescriptionSource):
1920

2021
@classmethod
2122
def describe(cls, callback: CallbackAdapter) -> list[str]:
23+
# pylint: disable-next=protected-access
2224
if not callback._cb_info.get("background"):
2325
return []
24-
from ..tool_background_tasks import GET_RESULT_TOOL_NAME
2526

2627
return [
2728
"",

dash/mcp/primitives/tools/results/__init__.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
from __future__ import annotations
88

99
import json
10-
from typing import Any
10+
from typing import TYPE_CHECKING, Any
1111

1212
from mcp.types import CallToolResult, CreateTaskResult, TextContent
1313

1414
from dash.types import CallbackExecutionResponse
15-
from dash.mcp.primitives.tools.callback_adapter import CallbackAdapter
1615

1716
from .base import ResultFormatter
1817
from .result_dataframe import DataFrameResult
1918
from .result_plotly_figure import PlotlyFigureResult
2019

20+
if TYPE_CHECKING:
21+
from dash.mcp.primitives.tools.callback_adapter import CallbackAdapter
22+
2123
_RESULT_FORMATTERS: list[type[ResultFormatter]] = [
2224
PlotlyFigureResult,
2325
DataFrameResult,
@@ -61,17 +63,21 @@ def task_result_to_tool_result(create_task_result: CreateTaskResult) -> CallTool
6163
"""
6264
task = create_task_result.task
6365
return CallToolResult(
64-
content=[TextContent(
65-
type="text",
66-
text=json.dumps({
67-
"taskId": task.taskId,
68-
"status": task.status,
69-
"pollInterval": task.pollInterval,
70-
"message": (
71-
"This is a long-running background callback. "
72-
"Call the get_background_task_result tool with this taskId "
73-
"to poll for the result."
66+
content=[
67+
TextContent(
68+
type="text",
69+
text=json.dumps(
70+
{
71+
"taskId": task.taskId,
72+
"status": task.status,
73+
"pollInterval": task.pollInterval,
74+
"message": (
75+
"This is a long-running background callback. "
76+
"Call the get_background_task_result tool with this taskId "
77+
"to poll for the result."
78+
),
79+
}
7480
),
75-
}),
76-
)],
81+
)
82+
],
7783
)

dash/mcp/primitives/tools/tool_background_tasks.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121

2222

2323
def _has_background_callbacks() -> bool:
24-
return any(
25-
cb_info.get("background")
26-
for cb_info in get_app().callback_map.values()
27-
)
24+
return any(cb_info.get("background") for cb_info in get_app().callback_map.values())
2825

2926

3027
class BackgroundTaskTools(MCPToolProvider):

dash/mcp/primitives/tools/tools_callbacks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def call_tool(
4747
" Please call tools/list to refresh your tool list."
4848
)
4949

50+
# pylint: disable-next=protected-access
5051
is_background = bool(cb._cb_info.get("background"))
5152

5253
try:

dash/mcp/tasks/tasks.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from datetime import datetime, timezone
77
from typing import Any
88

9-
from mcp.types import CreateTaskResult, GetTaskResult, Task
9+
from mcp.types import CancelTaskResult, CreateTaskResult, GetTaskResult, Task
1010

1111
from dash import get_app
1212
from dash.mcp.primitives.tools.results import format_callback_response
@@ -33,6 +33,7 @@ def create_task(dispatch_response: dict[str, Any], callback) -> CreateTaskResult
3333
cache_key = dispatch_response["cacheKey"]
3434
job_id = str(dispatch_response["job"])
3535
task_id = f"{callback.tool_name}:{job_id}:{cache_key}"
36+
# pylint: disable-next=protected-access
3637
interval = callback._cb_info.get("background", {}).get("interval", 1000)
3738
now = datetime.now(timezone.utc)
3839
return CreateTaskResult(
@@ -75,14 +76,17 @@ def get_task(task_id: str) -> GetTaskResult:
7576
adapter = get_app().mcp_callback_map.find_by_tool_name(tool_name)
7677
interval = None
7778
if adapter is not None:
79+
# pylint: disable-next=protected-access
7880
interval = adapter._cb_info.get("background", {}).get("interval", 1000)
7981

8082
now = datetime.now(timezone.utc)
8183
return GetTaskResult(
8284
taskId=task_id,
8385
status=status,
8486
statusMessage=str(progress) if progress else None,
85-
createdAt=datetime.fromisoformat(manager.handle.get(f"{cache_key}-created_at") or now.isoformat()),
87+
createdAt=datetime.fromisoformat(
88+
manager.handle.get(f"{cache_key}-created_at") or now.isoformat()
89+
),
8690
lastUpdatedAt=now,
8791
ttl=manager.expire * 1000 if manager.expire else None,
8892
pollInterval=interval,
@@ -117,7 +121,9 @@ def get_task_result(task_id: str) -> Any:
117121
response_data = json.loads(response.get_data(as_text=True))
118122

119123
if "response" not in response_data:
120-
raise MCPError("Task result not ready. Poll tasks/get until status is 'completed'.")
124+
raise MCPError(
125+
"Task result not ready. Poll tasks/get until status is 'completed'."
126+
)
121127

122128
return format_callback_response(response_data, adapter)
123129

@@ -127,9 +133,7 @@ def cancel_task(task_id: str) -> Any:
127133
128134
Same underlying mechanism as the renderer's cancelJob query param.
129135
"""
130-
from mcp.types import CancelTaskResult
131-
132-
tool_name, job_id, cache_key = parse_task_id(task_id)
136+
_tool_name, job_id, cache_key = parse_task_id(task_id)
133137

134138
manager = _get_callback_manager()
135139
if manager is None:

0 commit comments

Comments
 (0)