In MCP, a tool is a named function that an AI agent can discover and call. By default, Dash exposes your callbacks as tools. The @mcp_enabled decorator lets you add any plain Python function as an additional tool. This is useful if you want AI agents to access your app’s data or functionality in a more directly applicable way than what your callbacks provide.
Import mcp_enabled from dash.mcp and decorate any function to expose it as an MCP tool.
from dash.mcp import mcp_enabled
Applied without arguments, @mcp_enabled exposes the function using its Python name and no docstring.
from dash.mcp import mcp_enabled
@mcp_enabled
def get_sales(region: str) -> dict:
data = {"north": 120, "south": 95, "east": 140, "west": 110}
return {"region": region, "sales": data.get(region.lower(), 0)}
name and expose_docstringfrom dash.mcp import mcp_enabled
@mcp_enabled(name="get_sales", expose_docstring=True)
def get_sales_by_region(region: str) -> dict:
"""Return the sales total for a given region (north, south, east, west)."""
data = {"north": 120, "south": 95, "east": 140, "west": 110}
return {"region": region, "sales": data.get(region.lower(), 0)}
nameThe name argument sets the identifier the MCP client uses to request the tool and display it to the user. It defaults to the Python function name. Use it when you want a more descriptive or human-readable label, or to avoid exposing internal naming conventions.
expose_docstringWhen True, the function’s docstring is included in the tool description sent to the MCP client. Agents use this text to understand what the tool does, when to call it, and what arguments to pass. You may want to suppress it (False) if the docstring contains implementation details not intended for agents.
When left unset, expose_docstring inherits the app-wide expose_callback_docstrings value passed to configure_mcp_server (which itself defaults to False). Set it explicitly on the decorator to override that default for an individual tool.