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
| Name | Required | Description | Default |
|---|---|---|---|
| scenario | Yes | ||
| params | No | ||
| max_attempts | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
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.", } - src/opensips_mcp/tools/cfg_tools.py:597-599 (registration)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]: