Skip to main content
Glama
OpenSIPS

OpenSIPS MCP Server

Official
by OpenSIPS

cfg_preprocess

Preprocess OpenSIPS configuration files by running m4 on opensips.cfg.m4 and local.cfg.m4, then optionally validate the output with opensips -C -f.

Instructions

Run m4 local.cfg.m4 opensips.cfg.m4 and optionally validate the output.

Parameters

main_m4: Contents of opensips.cfg.m4. local_m4: Contents of local.cfg.m4 (site-specific define(...) lines). validate: If True and the opensips binary is present, run opensips -C -f on the preprocessed output.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
main_m4Yes
local_m4Yes
validateNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The cfg_preprocess tool handler - runs m4 preprocessing on m4 config files and optionally validates the output with opensips -C -f.
    async def cfg_preprocess(
        ctx: Context,
        main_m4: str,
        local_m4: str,
        validate: bool = True,
    ) -> dict[str, Any]:
        """Run ``m4 local.cfg.m4 opensips.cfg.m4`` and optionally validate the output.
    
        Parameters
        ----------
        main_m4:
            Contents of ``opensips.cfg.m4``.
        local_m4:
            Contents of ``local.cfg.m4`` (site-specific ``define(...)`` lines).
        validate:
            If True and the ``opensips`` binary is present, run ``opensips -C -f``
            on the preprocessed output.
        """
        pre = await run_m4(main_m4, local_m4)
        payload: dict[str, Any] = {
            "output_cfg": pre.output_cfg,
            "m4_stderr": pre.m4_stderr,
            "m4_returncode": pre.m4_returncode,
            "m4_success": pre.success,
        }
        if validate and pre.success:
            payload["validation"] = await _validate_if_available(pre.output_cfg)
        elif validate:
            payload["validation"] = {
                "valid": False,
                "errors": ["m4 preprocessing failed; skipping opensips validation."],
                "warnings": [],
                "raw_output": "",
            }
        return payload
  • The tool is registered via the @mcp.tool() decorator at line 804, making it available as an MCP tool named 'cfg_preprocess'.
    async def cfg_preprocess(
        ctx: Context,
        main_m4: str,
        local_m4: str,
        validate: bool = True,
    ) -> dict[str, Any]:
  • The _validate_if_available helper used by cfg_preprocess to optionally validate the preprocessed output via opensips -C -f.
    async def _validate_if_available(cfg_text: str) -> dict[str, Any]:
        """Run ``opensips -C -f`` when the binary exists; return a dict payload."""
        try:
            result = await _validator.validate(cfg_text)
            return result.model_dump()
        except FileNotFoundError:
            return {
                "valid": None,
                "errors": [],
                "warnings": [],
                "raw_output": "",
                "note": "opensips binary not found — validation skipped.",
            }
        except Exception as exc:
            return {
                "valid": False,
                "errors": [str(exc)],
                "warnings": [],
                "raw_output": "",
            }
  • The run_m4 helper import from cfg.m4_builder, which is the core preprocessing function called by cfg_preprocess.
        M4ConfigBuilder,
        check_m4_binary,
        is_safe_out_dir,
        run_m4,
    )
    from opensips_mcp.cfg.migration import ConfigMigrator
Behavior3/5

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

No annotations provided, so description carries full burden. It explains that inputs are file contents (not file paths) and that validation is conditional on opensips binary presence. However, it does not state whether the action is destructive, what the return value is (though output schema exists), or prerequisites like m4 installation.

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

Conciseness5/5

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

The description is concise, with a one-line summary followed by structured parameter definitions. No redundant content; every sentence adds value.

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?

For a simple 3-parameter tool, the description covers the main action, inputs, and optional validation. Output schema exists so return format is documented. Missing minor context like prerequisites (m4 installation) but overall sufficient.

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?

Schema has 0% description coverage, but the description fully explains each parameter: main_m4 is 'Contents of opensips.cfg.m4', local_m4 is 'Contents of local.cfg.m4 (site-specific define(...) lines)', validate has detailed conditional logic. This adds critical meaning beyond the schema titles and types.

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's action: 'Run ``m4 local.cfg.m4 opensips.cfg.m4``' and optionally validate. It specifies verb (run) and resource (m4 preprocessing). Among sibling cfg_* tools, this is distinct as it handles m4 preprocessing, not parsing or validation alone.

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

Usage Guidelines2/5

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

No explicit guidance on when to use this tool versus alternative cfg_* tools like cfg_parse or cfg_validate. The description only defines the tool's behavior but does not provide decision criteria or exclusion scenarios.

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