Skip to content

MCP Server Part 3: Dash App Resources - #3712

Merged
KoolADE85 merged 4 commits into
mcpfrom
feature/mcp-resources
Apr 16, 2026
Merged

MCP Server Part 3: Dash App Resources#3712
KoolADE85 merged 4 commits into
mcpfrom
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

fromdashimportDash, html, dcc, Input, Outputfromdash._get_appimportapp_contextimportjsonapp=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"))defupdate_chart(city):
return {"data": [{"x": [1, 2], "y": [3, 4]}], "layout": {"title": city}}
withapp.server.app_context():
app_context.set(app)
fromdash.mcp.primitives.resourcesimportlist_resources, read_resourceresult=list_resources()
forrinresult.resources:
print(f"Resource: {r.uri}{r.name}")
result=read_resource("dash://components")
print(json.loads(result.contents[0].text))

@github-actions

github-actionsBot commented Apr 1, 2026

Copy link
Copy Markdown

Thank you for your contribution to Dash! 🎉

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

@KoolADE85
KoolADE85force-pushed the feature/mcp-callback-adapters branch from c6cbe97 to cd073cfCompareApril 6, 2026 18:11
@KoolADE85
KoolADE85force-pushed the feature/mcp-resources branch from 93ea7ec to 0eecb3eCompareApril 6, 2026 18:13
@KoolADE85
KoolADE85force-pushed the feature/mcp-callback-adapters branch from cd073cf to 74cd477CompareApril 8, 2026 15:59
@KoolADE85
KoolADE85force-pushed the feature/mcp-resources branch from 0eecb3e to c397a38CompareApril 8, 2026 16:39

@T4rk1nT4rk1n left a comment

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.

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
ContributorAuthor

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
ContributorAuthor

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
KoolADE85force-pushed the feature/mcp-resources branch from c397a38 to 4532955CompareApril 13, 2026 22:28

@T4rk1nT4rk1n left a comment

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.

Looks good 💃

@KoolADE85
KoolADE85force-pushed the feature/mcp-resources branch from e68a524 to d9975e4CompareApril 16, 2026 17:29
@KoolADE85
KoolADE85 changed the base branch from feature/mcp-callback-adapters to mcpApril 16, 2026 17:30
@KoolADE85
KoolADE85 merged commit 5674a8d into mcpApr 16, 2026
7 of 9 checks passed
Sign up for freeto 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

@KoolADE85@T4rk1n@camdecoster