Skip to main content
Glama

add_routing_rule

Add a new routing rule to a strategy by specifying keywords, agent name, and priority to manage communication between ACP agents and MCP clients effectively.

Instructions

Add a new routing rule to a strategy

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_nameYes
descriptionNo
keywordsYes
priorityNo
strategy_nameYes

Implementation Reference

  • The FastMCP tool handler for 'add_routing_rule'. Parses comma-separated keywords, creates a RoutingRule instance, and appends it to an existing strategy or creates a new RouterStrategy.
    @mcp.tool()
    async def add_routing_rule(
        strategy_name: str,
        keywords: str,  # Comma-separated
        agent_name: str,
        priority: int = 5,
        description: str = ""
    ) -> str:
        """Add a new routing rule to a strategy"""
        
        try:
            keyword_list = [k.strip() for k in keywords.split(",")]
            
            new_rule = RoutingRule(
                keywords=keyword_list,
                agent_name=agent_name,
                priority=priority,
                description=description or f"Route to {agent_name}"
            )
            
            # Get or create strategy
            if strategy_name in router.strategies:
                strategy = router.strategies[strategy_name]
                strategy.rules.append(new_rule)
            else:
                strategy = RouterStrategy(
                    name=strategy_name,
                    description=f"Custom strategy: {strategy_name}",
                    rules=[new_rule]
                )
                router.strategies[strategy_name] = strategy
            
            return f"Successfully added rule: {keyword_list} -> {agent_name}"
            
        except Exception as e:
            return f"Error: {e}"
  • Pydantic model defining the structure of routing rules, directly used in the add_routing_rule handler to instantiate new rules.
    class RoutingRule(BaseModel):
        keywords: List[str]
        agent_name: str
        priority: int = 1
        description: str = ""
  • Registers all router tools, including 'add_routing_rule', by calling register_router_tools during ACPMCPServer initialization in _register_all_tools method.
    register_router_tools(self.mcp, self.router)
  • The registration function that defines and registers the add_routing_rule tool (and others) with the FastMCP instance using @mcp.tool() decorators.
    def register_router_tools(mcp: FastMCP, router: AgentRouter):

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GongRzhe/ACP-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server