MCP Server Part 2: Represent callback-related data with a CallbackAdapter#3711
MCP Server Part 2: Represent callback-related data with a CallbackAdapter#3711
CallbackAdapter#3711Conversation
|
Thank you for your contribution to Dash! 🎉 This PR is exempt from requiring a linked issue due to its labels. |
42aa12d to
0334a96
Compare
c6cbe97 to
cd073cf
Compare
cd073cf to
74cd477
Compare
| from dash.mcp.types import is_nullable | ||
| from dash._grouping import flatten_grouping | ||
| from dash._utils import clean_property_name, split_callback_id | ||
| from dash.mcp.types import MCPInput, MCPOutput | ||
| from .callback_utils import run_callback | ||
| from .descriptions import build_tool_description | ||
| from .input_schemas import get_input_schema | ||
| from .output_schemas import get_output_schema |
There was a problem hiding this comment.
dash.mcp.types appears two times and there is a mix of absolute vs relative imports.
| return [hints.get(func_name) for func_name, _ in self._dep_param_map] | ||
|
|
||
|
|
||
| def _expand_dep(dep: dict, value: Any) -> Any: |
There was a problem hiding this comment.
Add a type to this return value.
| return {**dep, "value": value} | ||
|
|
||
|
|
||
| def _expand_output_spec(output_id: str, cb_info: dict, resolved_inputs: list) -> Any: |
There was a problem hiding this comment.
Add a type to this return value.
| if len(results) == 1: | ||
| return results[0] | ||
| return results |
There was a problem hiding this comment.
I think returning the array and handling the results length at call site would be better since this makes the return value an union.
|
|
||
| def _derive_output_ids( | ||
| output_pattern: dict, resolved_inputs: list | ||
| ) -> list[dict] | None: |
There was a problem hiding this comment.
Add type definition to the dict if possible.
| return None | ||
|
|
||
|
|
||
| def _coerce_value(value: Any) -> Any: |
There was a problem hiding this comment.
Could add a generic here [TInput, TOutput]
| class CallbackExecutionError(MCPError): | ||
| """Callback raised an exception during execution.""" | ||
|
|
||
| code = -32603 |
There was a problem hiding this comment.
What are these code? This one has the same code as the base MCPError
Summary
CallbackAdapter: wraps a Dash callback and exposes MCP-related metadata (computed lazily)CallbackAdapterCollectionfor working with collections of adaptersmcp_enabledparameter to@app.callback()for opting callbacks out of MCPmcp>=1.0.0to dependenciesManual testing
CallbackAdapterexposesrun_callback(which is what MCP will do)