Overview
Rasa integrates with Model Context Protocol (MCP) servers to connect your agent to external APIs, databases, and other services. MCP servers expose tools that your agent can use directly in flows or provide to ReAct style sub agents for dynamic decision-making.Defining an MCP Server
Define your MCP servers in theendpoints.yml file:
endpoints.yml
meta_map on the MCP server in endpoints.yml.
Using an MCP tool in a flow
Use MCP tools directly in flows with thecall step, specifying input/output mappings:
flows.yml
Tool Results and Output Handling
MCP tools return results in two possible formats:Structured Content
When tools provide an output schema (see for example), you get structured data as output:Unstructured Content
When the invoked tool has no output schema is defined, the entire output is captured as a serialized string:Dynamic selection of tools in an autonomous step
Flows can also contain autonomous steps, where the business logic is dynamically figured out at runtime, based on the available context and tools from the MCP server. In order to do so, Rasa requires creation of ReAct sub agents.Sub agent Configuration
Each sub agent which has access to MCP tools operates in a ReAct loop, determining which tools to call based on the conversation context. To create a sub agent, add a folder specific to that agent in thesub_agents/ directory of your rasa agent:
sub_agents/stock_explorer/config.yml:
sub_agents/stock_explorer/config.yml
configuration block when you need LLM settings, intermediate messages (enabled by default for ReAct; implemented as tool acknowledgements), or other options.
More details on available configuration parameters can be found in the reference section.
Invoking a sub agent
A sub agent can be invoked from a flow using thecall step:
flows.yml
flows.yml
stock_explorer agent will keep running until the user_satisfied slot is not set to True.
To read more details about the runtime execution of a ReAct style sub agent inside Rasa, head over to the reference documentation.
Selective Tool Access
You can have fine-grained control over the specific MCP tools a sub agent can access by using theinclude_tools and exclude_tools properties in the agent configuration:
sub_agents/restricted_agent/config.yml
Customization
A React style sub agentβs behaviour can be customized by one of the three modes:- Custom prompt templates - Include specific instructions and slot context
- Python customization modules - Override agent behavior with custom python classes
- Additional tools - Add Python-based tools alongside existing tools from MCP servers
Error handling
When an MCP tool call or sub agent call fails at runtime, Rasa cancels the active flow and triggerspattern_internal_error. The pattern frame exposes structured context in context.info so you can customize the user-facing responseβfor example by tool name, agent name, or failure type. See the context.info field reference for available keys.
Override pattern_internal_error in your flows.yml and branch on context.info.error_source, or on a specific context.info.tool_name or context.info.agent_name. See Handling agent and MCP tool failures for a complete example.
Best Practices
MCP Server Setup
- Define servers in
endpoints.ymlfor consistency with other Rasa endpoints. - Use descriptive server names that indicate their purpose.
- Ensure MCP servers are accessible from your Rasa environment.
Tool Usage in Flows
- Always account for both structured and unstructured response content from tools.
- Use clear parameter and slot names for maintainability.
Security Considerations
- Use
include_toolsto provide only necessary tools for security. - Use
exclude_toolsto block sensitive or dangerous operations. - Set clear exit conditions to prevent infinite loops.
- Limit context sharing to necessary slots only.
- Prefer
pre_call_hookon MCP servers (andbuild_custom_tool_call_metadatafor ReAct custom tools) for per-conversation secrets: credentials are resolved only at outbound call time and are not stored in slots or the tracker. - Use
meta_mapfor static, non-secret server context (API version labels, non-sensitive identifiers from slots). Those values are not part of tool schemas shown to the LLM, and Rasa avoids logging or telemetry leakage of metadata values (key names only where needed). - Regularly audit agent permissions and access to tools.