dispatcher_update
Modify an existing dispatcher destination by its ID. Update attributes such as destination, set ID, flags, priority, weight, socket, state, and more. Optionally reload the dispatcher module to apply changes.
Instructions
Update a dispatcher destination by ID. Optionally triggers MI ds_reload.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ||
| destination | No | ||
| setid | No | ||
| flags | No | ||
| priority | No | ||
| attrs | No | ||
| description | No | ||
| weight | No | ||
| socket | No | ||
| state | No | ||
| reload | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The 'dispatcher_update' MCP tool handler function. Decorated with @mcp.tool(), @audited('dispatcher_update'), and @require_permission('db.write'). Accepts an ID and optional fields to update, then calls crud.update_dispatcher() and optionally triggers MI ds_reload.
@mcp.tool() @audited("dispatcher_update") @require_permission("db.write") async def dispatcher_update( ctx: Context, id: int, destination: str | None = None, setid: int | None = None, flags: int | None = None, priority: int | None = None, attrs: str | None = None, description: str | None = None, weight: int | None = None, socket: str | None = None, state: int | None = None, reload: bool = True, ) -> dict[str, Any]: """Update a dispatcher destination by ID. Optionally triggers MI ds_reload.""" from opensips_mcp.db.crud import dispatcher as crud app = ctx.request_context.lifespan_context kwargs: dict[str, Any] = {} for field in ( "destination", "setid", "flags", "priority", "attrs", "description", "weight", "socket", "state", ): val = locals()[field] if val is not None: kwargs[field] = val async with app.db_session_factory() as session: ds = await crud.update_dispatcher(session, id, **kwargs) if not ds: return {"error": "Dispatcher not found"} result: dict[str, Any] = { "id": ds.id, "destination": ds.destination, "setid": ds.setid, "updated": True, } if reload: try: await app.mi_client.execute("ds_reload") result["reloaded"] = True except Exception as exc: logger.warning("ds_reload failed: %s", exc) result["reloaded"] = False result["reload_error"] = str(exc) return result - The update_dispatcher CRUD helper that performs the actual database update. Selects by ID, sets any provided non-id attributes on the Dispatcher ORM model, commits, and returns the updated object.
async def update_dispatcher( session: AsyncSession, id: int, **kwargs ) -> Dispatcher | None: stmt = select(Dispatcher).where(Dispatcher.id == id) result = await session.execute(stmt) ds = result.scalar_one_or_none() if not ds: return None for k, v in kwargs.items(): if hasattr(ds, k) and k != "id": setattr(ds, k, v) await session.commit() await session.refresh(ds) return ds - The Dispatcher SQLAlchemy model (schema) defining the 'dispatcher' table columns: id, setid, destination, flags, priority, attrs, description, weight, socket, state.
class Dispatcher(Base): __tablename__ = "dispatcher" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) setid: Mapped[int] = mapped_column(Integer, default=0) destination: Mapped[str] = mapped_column(String(256), nullable=False) flags: Mapped[int] = mapped_column(Integer, default=0) priority: Mapped[int] = mapped_column(Integer, default=0) attrs: Mapped[str] = mapped_column(String(128), default="") description: Mapped[str] = mapped_column(String(64), default="") weight: Mapped[int] = mapped_column(Integer, default=1) socket: Mapped[str] = mapped_column(String(128), default="") state: Mapped[int] = mapped_column(Integer, default=0) - src/opensips_mcp/server.py:174-174 (registration)Registration of the dispatcher_tools module in the main server file, which causes the @mcp.tool() decorator on dispatcher_update to register it.
from opensips_mcp.tools import dispatcher_tools as _dispatcher_tools # noqa: E402, F401