# libtmux_mcp.server.mcp

- **Module:** libtmux_mcp.server
- **Package:** libtmux-mcp
- **Language:** Python
- **Kind:** constant
- **Source:** https://github.com/tmux-python/libtmux-mcp/blob/4daddc0dfca96c43bf521d818bf91564e1434760/src/libtmux_mcp/server.py#L383
- **Page:** https://libtmux.org/en/py/stable/mcp/reference/libtmux_mcp-server-mcp/

```py
libtmux_mcp.server.mcp = FastMCP(
    name="tmux",
    version=__version__,
    instructions=_build_instructions(
        toolsets=_toolsets,
        suppress_history=_suppress_history,
    ),
    website_url="https://libtmux-mcp.git-pull.com/",
    lifespan=_lifespan,
    # Middleware runs outermost-first. Order rationale:
    #   1. TimingMiddleware — neutral observer; start clock as early
    #      as possible so timing captures middleware cost too.
    #   2. TailPreservingResponseLimitingMiddleware — bounds the final
    #      tool result on the way back out. Tool errors may already be
    #      ToolResult(is_error=True) here, so truncation preserves that
    #      flag instead of turning expected failures into schema errors.
    #   3. ToolErrorResultMiddleware — converts tool-call failures to
    #      rich ToolResult(is_error=True) results and transforms
    #      resource errors to MCP code -32002. Must stay OUTSIDE the
    #      audit + toolset pair: both depend on exception semantics
    #      (audit catches to record outcome=error, and toolset denials
    #      must propagate as exceptions for audit to record them), so
    #      converting the exception to a result any deeper would
    #      silently break both.
    #   4. AuditMiddleware — outside ToolsetMiddleware so refusal
    #      events (which raise ExpectedToolError before call_next inside
    #      Toolset) are still logged with outcome=error. Without this
    #      ordering, denied access attempts would silently bypass the
    #      audit log — a security-observability gap.
    #   5. ToolsetMiddleware — innermost gate (fail-closed). Refusals
    #      never reach the tool, but the audit record above captures
    #      them for forensic review.
    middleware=[
        TimingMiddleware(),
        TailPreservingResponseLimitingMiddleware(
            max_size=DEFAULT_RESPONSE_LIMIT_BYTES,
            tools=_RESPONSE_LIMITED_TOOLS,
        ),
        ToolErrorResultMiddleware(transform_errors=True),
        AuditMiddleware(),
        ToolsetMiddleware(_toolsets, _extra_tools, _excluded_tools),
    ],
    on_duplicate="error",
)
```
