# mcp_tool_middleware

> **Function** in `deepagents_code`

📖 [View in docs](https://reference.langchain.com/python/deepagents-code/mcp_middleware/mcp_tool_middleware)

Build the middleware wrapping every MCP tool call.

## Signature

```python
mcp_tool_middleware(
    timeout_seconds: float = MCP_TOOL_TIMEOUT_SECONDS_DEFAULT,
) -> AgentMiddleware
```

## Returns

`AgentMiddleware`

Middleware that normalizes arguments and reports a stale-token failure
as a tool message naming the login command.

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/4bfa52000ef65ac623d8ada0cb67f67cbdd663ea/libs/code/deepagents_code/mcp_middleware.py#L95)