Skip to main content
Glama
OpenSIPS

OpenSIPS MCP Server

Official
by OpenSIPS

docker_restart

Restart a Docker Compose service in your OpenSIPS environment. Specify the service name to quickly restart it, defaulting to opensips.

Instructions

Restart a Docker Compose service.

Parameters

service: The service name to restart (default: opensips).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serviceNoopensips

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The docker_restart tool function: decorated with @mcp.tool(), @audited('docker_restart'), @require_permission('process.manage'). Executes 'docker compose restart <service>' as a subprocess with a 60-second timeout. Accepts a 'service' parameter (default 'opensips') and returns the exit code, stdout, stderr, and success flag.
    @mcp.tool()
    @audited("docker_restart")
    @require_permission("process.manage")
    async def docker_restart(
        ctx: Context,
        service: str = "opensips",
    ) -> dict[str, Any]:
        """Restart a Docker Compose service.
    
        Parameters
        ----------
        service:
            The service name to restart (default: ``opensips``).
        """
        try:
            proc = await asyncio.create_subprocess_exec(
                "docker", "compose", "restart", service,
                stdout=asyncio.subprocess.PIPE,
                stderr=asyncio.subprocess.PIPE,
            )
            stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=60)
            return {
                "service": service,
                "returncode": proc.returncode,
                "output": stdout.decode().strip(),
                "errors": stderr.decode().strip() if proc.returncode != 0 else "",
                "success": proc.returncode == 0,
            }
        except FileNotFoundError:
            return {"error": "docker command not found -- is Docker installed?"}
        except asyncio.TimeoutError:
            return {"error": "docker compose restart timed out after 60 seconds"}
        except Exception as exc:
            return {"error": f"Failed to restart service: {exc}"}
  • Registration of the docker_tools module on the MCP server. The import at line 175 in server.py triggers all @mcp.tool() decorators in docker_tools.py, including the docker_restart tool.
    from opensips_mcp.tools import docker_tools as _docker_tools  # noqa: E402, F401
  • The @audited() decorator used on docker_restart. It logs audit entries (success/error) for every call to the tool, recording the operation name ('docker_restart'), parameters, and the caller's role.
    def audited(operation: str):
        """Decorator that logs audit entries for tool calls."""
    
        def decorator(func):
            @wraps(func)
            async def wrapper(ctx: Context, *args, **kwargs):
                app = ctx.request_context.lifespan_context
                role = getattr(app.settings, "role", "unknown")
                try:
                    result = await func(ctx, *args, **kwargs)
                    audit_log(operation, kwargs, "success", role)
                    return result
                except Exception as e:
                    audit_log(operation, kwargs, f"error: {e}", role)
                    raise
    
            return wrapper
    
        return decorator
  • The @require_permission() decorator used on docker_restart. It enforces RBAC by checking the caller's role has the 'process.manage' permission before allowing the tool to execute.
    def require_permission(permission: str) -> Callable[..., Any]:
        """Decorator that enforces RBAC on an MCP tool function.
    
        The decorated function **must** accept ``ctx: Context`` as its first
        positional argument.  The current role is read from
        ``ctx.request_context.lifespan_context.settings.role``.
    
        Raises ``McpError`` when the active role lacks the requested permission.
        """
    
        def decorator(func: Callable[..., Any]) -> Callable[..., Any]:
            @functools.wraps(func)
            async def wrapper(ctx: Context, *args: Any, **kwargs: Any) -> Any:
                app_context = ctx.request_context.lifespan_context
                role_value: str = app_context.settings.role.lower()
    
                try:
                    role = Role(role_value)
                except ValueError:
                    raise McpError(
                        ErrorData(
                            code=-1,
                            message=f"Unknown role '{role_value}'. Valid roles: {[r.value for r in Role]}",
                        )
                    ) from None
    
                allowed = PERMISSIONS.get(role, set())
                if permission not in allowed:
                    raise McpError(
                        ErrorData(
                            code=-1,
                            message=f"Permission denied: role '{role.value}' lacks '{permission}' permission",
                        )
                    )
    
                return await func(ctx, *args, **kwargs)
    
            return wrapper
Behavior2/5

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

With no annotations, the description carries full burden for behavioral disclosure. It only states that the tool restarts a service, but does not explain whether the restart is graceful, what happens to existing connections, or any other behavioral traits. This is insufficient.

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 very concise, using a single sentence and a clear parameter listing. No unnecessary words, but the docstring-like formatting could be more natural for an agent.

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 the simplicity of the tool (one parameter with default, output schema exists), the description is minimally adequate. However, it lacks details like potential errors, return value description, or behavior when the service does not exist, which affects completeness.

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

Parameters3/5

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

The schema has 0% description coverage, so the description must compensate. It does provide a brief explanation of the 'service' parameter and its default, but it lacks details like valid values or whether the service name is a Docker Compose service name. It adds some value but not enough for a high score.

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

Purpose4/5

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

The description clearly states the verb 'Restart' and the resource 'Docker Compose service', which aligns with the tool name. However, it does not differentiate from sibling tools like docker_deploy_scenario or docker_status, which have similar scope.

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 usage guidance is provided. There is no mention of when to use this tool over alternatives, prerequisites (e.g., service must be running), or potential side effects. The description simply repeats the action without context.

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