Skip to main content
Glama
OpenSIPS

OpenSIPS MCP Server

Official
by OpenSIPS

cfg_explain_route

Analyze any OpenSIPS route block to identify its components: SIP methods handled, module functions called, conditions, and overall flow. Understand routing logic with clear breakdown.

Instructions

Explain an OpenSIPS route block by identifying its components.

Analyzes the route code and identifies SIP methods handled, module functions called, conditions, and overall flow.

Parameters

route_code: The route block code to explain (e.g. the body of a route{...}).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
route_codeYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The `cfg_explain_route` tool handler function. It analyzes an OpenSIPS route block by detecting SIP methods via is_method(), module function calls, flags, AVPs, sub-route calls, and conditions. Returns a dict with methods_handled, module_functions, conditions, flags_used, avps_used, sub_routes_called, and a summary.
    @mcp.tool()
    @require_permission("config.read")
    async def cfg_explain_route(
        ctx: Context,
        route_code: str,
    ) -> dict[str, Any]:
        """Explain an OpenSIPS route block by identifying its components.
    
        Analyzes the route code and identifies SIP methods handled, module
        functions called, conditions, and overall flow.
    
        Parameters
        ----------
        route_code:
            The route block code to explain (e.g. the body of a ``route{...}``).
        """
        explanation: dict[str, Any] = {
            "methods_handled": [],
            "module_functions": [],
            "conditions": [],
            "flags_used": [],
            "avps_used": [],
            "sub_routes_called": [],
            "summary": "",
        }
    
        # Detect SIP methods
        method_re = re.compile(r'is_method\s*\(\s*"([^"]+)"\s*\)')
        for m in method_re.finditer(route_code):
            for method in m.group(1).split("|"):
                if method not in explanation["methods_handled"]:
                    explanation["methods_handled"].append(method)
    
        # Detect module function calls
        func_re = re.compile(r"\b([a-z_]+)\s*\(")
        known_opensips_funcs = {
            "t_relay", "t_check_trans", "t_on_failure", "t_on_reply", "t_on_branch",
            "sl_send_reply", "record_route", "loose_route", "has_totag",
            "mf_process_maxfwd_header", "fix_nated_contact", "fix_nated_register",
            "nat_uac_test", "force_rport", "save", "lookup", "create_dialog",
            "www_authorize", "www_challenge", "proxy_authorize", "proxy_challenge",
            "consume_credentials", "check_from", "ds_select_dst", "ds_next_dst",
            "do_routing", "use_next_gw", "lb_start", "lb_next", "lb_disable_dst",
            "do_accounting", "setflag", "setbflag", "isbflagset", "isflagset",
            "rtpengine_offer", "rtpengine_answer", "rtpengine_delete",
            "rtpengine_use_set", "pike_check_req", "handle_subscribe",
            "handle_publish", "cc_handle_call", "b2b_init_request",
            "is_from_local", "is_uri_host_local", "xlog",
        }
        for m in func_re.finditer(route_code):
            fname = m.group(1)
            if fname in known_opensips_funcs and fname not in explanation["module_functions"]:
                explanation["module_functions"].append(fname)
    
        # Detect flags
        flag_re = re.compile(r'(?:setflag|setbflag|isbflagset|isflagset)\s*\(\s*"?([^")\s]+)"?\s*\)')
        for m in flag_re.finditer(route_code):
            if m.group(1) not in explanation["flags_used"]:
                explanation["flags_used"].append(m.group(1))
    
        # Detect AVPs
        avp_re = re.compile(r"\$avp\(([^)]+)\)")
        for m in avp_re.finditer(route_code):
            if m.group(1) not in explanation["avps_used"]:
                explanation["avps_used"].append(m.group(1))
    
        # Detect sub-route calls
        route_call_re = re.compile(r"route\s*\(\s*(\w+)\s*\)")
        for m in route_call_re.finditer(route_code):
            if m.group(1) not in explanation["sub_routes_called"]:
                explanation["sub_routes_called"].append(m.group(1))
    
        # Detect conditions
        cond_re = re.compile(r"if\s*\((.+?)\)\s*\{")
        for m in cond_re.finditer(route_code):
            cond = m.group(1).strip()
            if len(cond) < 120:
                explanation["conditions"].append(cond)
    
        # Build summary
        parts = []
        if explanation["methods_handled"]:
            parts.append(f"Handles SIP methods: {', '.join(explanation['methods_handled'])}")
        if explanation["module_functions"]:
            parts.append(f"Calls {len(explanation['module_functions'])} OpenSIPS functions")
        if explanation["sub_routes_called"]:
            parts.append(f"Delegates to sub-routes: {', '.join(explanation['sub_routes_called'])}")
        if explanation["flags_used"]:
            parts.append(f"Uses flags: {', '.join(explanation['flags_used'])}")
        explanation["summary"] = ". ".join(parts) + "." if parts else "Empty or unrecognized route."
    
        return explanation
  • The output schema/dict structure that cfg_explain_route returns, including keys: methods_handled, module_functions, conditions, flags_used, avps_used, sub_routes_called, summary.
    explanation: dict[str, Any] = {
        "methods_handled": [],
        "module_functions": [],
        "conditions": [],
        "flags_used": [],
        "avps_used": [],
        "sub_routes_called": [],
        "summary": "",
    }
  • Registration of cfg_explain_route as an MCP tool via the @mcp.tool() decorator, with @require_permission('config.read') for RBAC.
    @mcp.tool()
    @require_permission("config.read")
  • The Explainer instance (_explainer) is initialized here but is used by cfg_explain (the "kubectl explain" tool), not by cfg_explain_route. cfg_explain_route uses inline logic and a hardcoded set of known_opensips_funcs.
    _explainer = Explainer()
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Describes analysis behavior (identifies components, methods, functions, conditions, flow) beyond schema. No annotations, but description suffices for a read-only analysis tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Some redundancy between the first line and the subsequent paragraph, but front-loaded with purpose. A bit verbose for a single-parameter tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers input and behavior well, and output schema exists (though not shown). For a single-param tool, it is sufficiently complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema coverage, description fully explains route_code as the route block body and gives an example, adding significant value over the schema's minimal 'Route Code' label.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states it explains an OpenSIPS route block by identifying components like SIP methods, module functions, conditions, and flow, distinguishing it from sibling tools like cfg_explain or cfg_lint.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage for analyzing route blocks but does not explicitly mention when to use vs alternatives like cfg_explain for full config or cfg_lint for validation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/OpenSIPS/opensips-mcp-server'

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