Skip to main content
Glama
OpenSIPS

OpenSIPS MCP Server

Official
by OpenSIPS

cfg_generate_iterative

Generate OpenSIPS configurations from scenario templates and validate iteratively with opensips -C -f. Reports validation results and includes raw output if validation fails.

Instructions

Generate an OpenSIPS config and iteratively validate it.

Generates a configuration from the given scenario, validates it using opensips -C -f, and reports the results. If validation fails, the raw output is included for diagnosis.

Parameters

scenario: The scenario template name. params: Template parameters. max_attempts: Maximum validation attempts (reserved for future auto-fix logic).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
scenarioYes
paramsNo
max_attemptsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The cfg_generate_iterative tool handler: generates an OpenSIPS config from a scenario template, then iteratively validates it with opensips -C -f up to max_attempts times. Returns config text, validation attempts, and a success/failure verdict.
    @mcp.tool()
    @audited("cfg_generate_iterative")
    @require_permission("config.write")
    async def cfg_generate_iterative(
        ctx: Context,
        scenario: str,
        params: dict[str, Any] | None = None,
        max_attempts: int = 3,
    ) -> dict[str, Any]:
        """Generate an OpenSIPS config and iteratively validate it.
    
        Generates a configuration from the given scenario, validates it using
        ``opensips -C -f``, and reports the results. If validation fails,
        the raw output is included for diagnosis.
    
        Parameters
        ----------
        scenario:
            The scenario template name.
        params:
            Template parameters.
        max_attempts:
            Maximum validation attempts (reserved for future auto-fix logic).
        """
        try:
            config = _builder.render(scenario, params)
        except Exception as exc:
            return {"error": f"Generation failed: {exc}", "attempt": 0}
    
        attempts = []
        current_config = config
    
        for attempt in range(1, max_attempts + 1):
            try:
                result = await _validator.validate(current_config)
                attempts.append({
                    "attempt": attempt,
                    "valid": result.valid,
                    "errors": result.errors,
                    "warnings": result.warnings,
                })
    
                if result.valid:
                    return {
                        "config": current_config,
                        "valid": True,
                        "attempts": attempts,
                        "total_attempts": attempt,
                        "scenario": scenario,
                    }
    
                # If not valid and not last attempt, log for future auto-fix
                logger.warning(
                    "Validation attempt %d/%d failed: %s",
                    attempt,
                    max_attempts,
                    result.errors,
                )
    
            except FileNotFoundError:
                return {
                    "config": current_config,
                    "valid": None,
                    "note": "opensips binary not found - could not validate. "
                    "Configuration was generated but not verified.",
                    "attempts": [],
                    "total_attempts": 0,
                    "scenario": scenario,
                }
            except Exception as exc:
                attempts.append({
                    "attempt": attempt,
                    "valid": False,
                    "errors": [str(exc)],
                    "warnings": [],
                })
    
        return {
            "config": current_config,
            "valid": False,
            "attempts": attempts,
            "total_attempts": max_attempts,
            "scenario": scenario,
            "message": f"Configuration did not pass validation after {max_attempts} attempts. "
            "Review the errors and adjust parameters.",
        }
  • Registration: decorated with @mcp.tool(), @audited('cfg_generate_iterative'), and @require_permission('config.write') on line 597-599. The @mcp.tool() decorator registers it with the MCP server.
    @mcp.tool()
    @audited("cfg_generate_iterative")
    @require_permission("config.write")
  • Schema/parameters: accepts scenario (str), params (optional dict), and max_attempts (int, default 3) — the input schema is defined via type annotations in the function signature.
    async def cfg_generate_iterative(
        ctx: Context,
        scenario: str,
        params: dict[str, Any] | None = None,
        max_attempts: int = 3,
    ) -> dict[str, Any]:
Behavior2/5

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

No annotations provided, so description must fully disclose behavior. It mentions generation and validation steps but does not clarify if the config is saved to disk or just returned, nor does it state side effects (e.g., file creation, modification). Missing details on error handling beyond including raw output.

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

Conciseness4/5

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

The description is structured with a concise summary followed by parameter details. It is front-loaded and to the point, though the parameter descriptions could be more succinct. No wasted sentences.

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

Completeness3/5

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

Given no annotations, the description covers purpose and basic mechanics. However, it lacks clarity on return format (though output schema exists), side effects, and error behavior beyond raw output. Adequate but incomplete for a moderate-complexity tool.

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

Parameters4/5

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

Schema coverage is 0%, so description carries the burden. The parameter descriptions add value: scenario as template name, params as template parameters, max_attempts as reserved for auto-fix. These meanings are not inferable from schema alone.

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?

The description clearly states the tool generates an OpenSIPS config and iteratively validates it using opensips -C -f. It specifies the result includes validation results and raw output on failure. This distinguishes it from siblings like cfg_generate (which likely generates without validation) and cfg_validate (which only validates).

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?

The description mentions iterative validation and includes raw output on failure, but does not explicitly guide when to choose this tool over others like cfg_generate, cfg_validate, or cfg_lint. Given many sibling tools, explicit usage context is lacking.

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