Skip to content

MCP Server Part 3: Dash App Resources#3712

Open
KoolADE85 wants to merge 3 commits intofeature/mcp-callback-adaptersfrom
feature/mcp-resources
Open

MCP Server Part 3: Dash App Resources#3712
KoolADE85 wants to merge 3 commits intofeature/mcp-callback-adaptersfrom
feature/mcp-resources

Conversation

@KoolADE85
Copy link
Copy Markdown
Contributor

Summary

  • Add read-only MCP resources:

    • dash://layout: retrieves the layout in the same json format as the _dash-layout endpoint
    • dash://components: retrieves a flat list of components which have IDs, along with their types
    • dash://pages: retrieves all pages from the page registry
    • dash://page-layout/{path}: a template for retrieving the layout of a specific page
    • dash://clientside-callbacks: describes all clientside callbacks for LLM discovery
  • Resources may be conditionally listed (e.g. dash://pages only appears for multi-page apps)

Manual testing

from dash import Dash, html, dcc, Input, Output
from dash._get_app import app_context
import json

app = Dash(__name__)
app.layout = html.Div([
    dcc.Dropdown(id="city", options=["NYC", "LA", "Chicago"], value="NYC"),
    dcc.Graph(id="chart"),
])
@app.callback(Output("chart", "figure"), Input("city", "value"))
def update_chart(city):
    return {"data": [{"x": [1, 2], "y": [3, 4]}], "layout": {"title": city}}

with app.server.app_context():
    app_context.set(app)
    from dash.mcp.primitives.resources import list_resources, read_resource
    result = list_resources()
    for r in result.resources:
        print(f"Resource: {r.uri}{r.name}")
    result = read_resource("dash://components")
    print(json.loads(result.contents[0].text))

@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 from c6cbe97 to cd073cf Compare April 6, 2026 18:11
@KoolADE85 KoolADE85 force-pushed the feature/mcp-resources branch from 93ea7ec to 0eecb3e Compare April 6, 2026 18:13
@KoolADE85 KoolADE85 force-pushed the feature/mcp-callback-adapters branch from cd073cf to 74cd477 Compare April 8, 2026 15:59
@KoolADE85 KoolADE85 force-pushed the feature/mcp-resources branch from 0eecb3e to c397a38 Compare April 8, 2026 16:39
Copy link
Copy Markdown
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, just wondering why the pages import wouldn't work since that is a pretty standard module.

Comment on lines +38 to +39
def get_template() -> ResourceTemplate | None:
return None
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary if it only returns None? Seems like the modules are being used as a class, maybe refactor to a base class instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a great idea! I added a base class and removed the no-op methods from each type of resource.

Comment on lines +38 to +41
try:
from dash._pages import PAGE_REGISTRY
except ImportError:
raise ValueError("Dash Pages is not available.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this import be not available?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - I guess it would always be there. I removed the defensive import and put it at the top.

@KoolADE85 KoolADE85 force-pushed the feature/mcp-resources branch from c397a38 to 4532955 Compare April 13, 2026 22:28
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.

3 participants