Skip to content

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

Open
KoolADE85 wants to merge 4 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 4 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.

@KoolADE85 KoolADE85 force-pushed the feature/mcp-formatted-tool-results branch from 0e54d74 to 8a41b76 Compare April 21, 2026 17:28
@KoolADE85 KoolADE85 force-pushed the feature/mcp-get-dash-component-tool branch from 8c1f392 to f9b05da Compare April 21, 2026 17:28
@KoolADE85 KoolADE85 force-pushed the feature/mcp-formatted-tool-results branch from 8a41b76 to 4fb9d4a Compare April 22, 2026 21:31
@KoolADE85 KoolADE85 force-pushed the feature/mcp-get-dash-component-tool branch from f9b05da to bc340e6 Compare April 22, 2026 21:37
@KoolADE85 KoolADE85 force-pushed the feature/mcp-formatted-tool-results branch from 4fb9d4a to 10a544b Compare April 23, 2026 20:15
@KoolADE85 KoolADE85 force-pushed the feature/mcp-get-dash-component-tool branch from bc340e6 to b3d4015 Compare April 23, 2026 20:24
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.

2 participants