Skip to content

MCP Server Part 2: Represent callback-related data with a CallbackAdapter#3711

Open
KoolADE85 wants to merge 2 commits intofeature/mcp-framework-foundationsfrom
feature/mcp-callback-adapters
Open

MCP Server Part 2: Represent callback-related data with a CallbackAdapter#3711
KoolADE85 wants to merge 2 commits intofeature/mcp-framework-foundationsfrom
feature/mcp-callback-adapters

Conversation

@KoolADE85
Copy link
Copy Markdown
Contributor

Summary

  • Add CallbackAdapter: wraps a Dash callback and exposes MCP-related metadata (computed lazily)
  • Add CallbackAdapterCollection for working with collections of adapters
  • Add mcp_enabled parameter to @app.callback() for opting callbacks out of MCP
  • Add mcp>=1.0.0 to dependencies

Manual testing

  • You can inspect what kind of data the CallbackAdapter exposes
  • you can run callbacks directly with run_callback (which is what MCP will do)
from dash import Dash, html, dcc, Input, Output
from dash._get_app import app_context

app = Dash(__name__)
app.layout = html.Div([
    dcc.Input(id="name", value="World"),
    html.Div(id="greeting"),
])
@app.callback(Output("greeting", "children"), Input("name", "value"))
def greet(name):
    """Greet the user by name."""
    return f"Hello, {name}!"

with app.server.app_context():
    app_context.set(app)
    from dash.mcp.primitives.tools.callback_adapter_collection import CallbackAdapterCollection
    from dash.mcp.primitives.tools.callback_utils import run_callback
    collection = CallbackAdapterCollection(app)
    for adapter in collection:
        print(f"Tool: {adapter.tool_name}")
        print(f"  Docstring: {adapter._docstring}")
        print(f"  Outputs: {[o['id_and_prop'] for o in adapter.outputs]}")
        print(f"  Inputs:  {[i['name'] for i in adapter.inputs]}")

    # Execute the callback through the adapter
    adapter = collection[0]
    result = run_callback(adapter, {"name": "Alice"})
    print(f"Callback result: {result}")

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

Thank you for your contribution to Dash! 🎉

This PR is exempt from requiring a linked issue due to its labels.

@KoolADE85 KoolADE85 force-pushed the feature/mcp-callback-adapters branch 2 times, most recently from 42aa12d to 0334a96 Compare April 1, 2026 22:45
@KoolADE85 KoolADE85 force-pushed the feature/mcp-callback-adapters branch from 0334a96 to c6cbe97 Compare April 1, 2026 23:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant