Skip to content

MCP Server Part 7: get_dash_component tool and callback tool execution#3749

Open
KoolADE85 wants to merge 3 commits intofeature/mcp-formatted-tool-resultsfrom
feature/mcp-get-dash-component-tool
Open

MCP Server Part 7: get_dash_component tool and callback tool execution#3749
KoolADE85 wants to merge 3 commits intofeature/mcp-formatted-tool-resultsfrom
feature/mcp-get-dash-component-tool

Conversation

@KoolADE85
Copy link
Copy Markdown
Contributor

Summary

  • Wires up the full tool pipeline following the same pattern as resources:

    • list_tools() builds the tool list from all registered tool providers
    • call_tool(name, args) routes LLM calls to the appropriate callback function
  • Adds a static tool get_dash_component which allows LLMs to query a specific prop for a given ID.

Manual verification:

from dash import Dash, html, dcc, Input, Output
import json

app = Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(id="city", options=["NYC", "LA"], value="NYC"),
    dcc.Graph(id="chart"),
    html.Div(id="summary"),
])

@app.callback(Output("chart", "figure"), Input("city", "value"))
def update_chart(city):
    return {"data": [], "layout": {"title": city}}

@app.callback(Output("summary", "children"), Input("city", "value"))
def update_summary(city):
    return f"Showing data for {city}"

with app.server.app_context():
    from dash.mcp.primitives.tools import list_tools, call_tool

    # List all tools — should include update_chart, update_summary, get_dash_component
    tools = list_tools()
    for tool in tools.tools:
        print(f"- {tool.name}")

    # Inspect a component — shows it's input to both callbacks
    result = call_tool("get_dash_component", {"component_id": "city"})
    print(json.dumps(json.loads(result.content[0].text), indent=2))
    # "value" property should list both `update_chart` and `update_summary` in input_to_tool

    # Execute a callback via its tool
    result = call_tool("update_summary", {"city": "LA"})
    print(result.content[0].text)  # Shows "Showing data for LA"

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 16, 2026

Thank you for your contribution to Dash! 🎉

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

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