# middleware

URL: /milo-cli/api/milo/middleware/
Section: milo
Description: Middleware stack for MCP and CLI call interception.

---

> For a complete page index, fetch /milo-cli/llms.txt.

Open LLM text
(/milo-cli/api/milo/middleware/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fmiddleware%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fmiddleware%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fmiddleware%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fmiddleware%2Findex.txt)

Module

#
`middleware`

Middleware stack for MCP and CLI call interception.

2Classes

## Classes

`MCPCall`

4

▼

Represents an interceptable MCP or CLI call.

Represents an interceptable MCP or CLI call.

#### Attributes

Name
Type
Description

`method`

`str`

—

`name`

`str`

—

`arguments`

`dict[str, Any]`

—

`metadata`

`dict[str, Any]`

—

`MiddlewareStack`

3

▼

Ordered middleware pipeline for intercepting calls.

Middleware signature: ``def mw(ctx, call: MCPC…

Ordered middleware pipeline for intercepting calls.

Middleware signature:`def mw(ctx, call: MCPCall, next_fn: NextFn) -> Any`

Usage::

```
stack = MiddlewareStack()

@stack.use
def log_calls(ctx, call, next_fn):
    print(f"Calling {call.name}")
    result = next_fn(call)
    print(f"Done {call.name}")
    return result

result = stack.execute(ctx, call, handler)
```

#### Methods

`use`

1

`MiddlewareFn`

▼

Register a middleware function. Can be used as a decorator.

`def use(self, fn: MiddlewareFn) -> MiddlewareFn`

##### Parameters

Name
Type
Description

`fn`
`—`

##### Returns

`MiddlewareFn`

`execute`

3

`Any`

▼

Execute the middleware chain, ending with the handler.

`def execute(self, ctx: Any, call: MCPCall, handler: Callable[..., Any]) -> Any`

##### Parameters

Name
Type
Description

`ctx`
`—`

`call`
`—`

`handler`
`—`

##### Returns

`Any`

Internal Methods
1

▼

`__init__`

0

▼

`def __init__(self) -> None`
