Middleware

Safety middleware for libtmux MCP server.

Gates tools by safety tier based on the LIBTMUX_SAFETY environment variable. Tools tagged above the configured tier are hidden from listing and blocked from execution.

class libtmux_mcp.middleware.SafetyMiddleware[source]

Bases: Middleware

Gate tools by safety tier.

Parameters:

max_tier (str) – Maximum allowed tier. One of TAG_READONLY, TAG_MUTATING, or TAG_DESTRUCTIVE.

__init__(max_tier='mutating')[source]
Parameters:

max_tier (str)

Return type:

None

async on_list_tools(context, call_next)[source]

Filter tools above the safety tier from the listing.

Return type:

Any

Parameters:
  • context (MiddlewareContext)

  • call_next (Any)

async on_call_tool(context, call_next)[source]

Block execution of tools above the safety tier.

Return type:

Any

Parameters:
  • context (MiddlewareContext)

  • call_next (Any)