# LocalContextMiddleware

> **Class** in `deepagents_cli`

📖 [View in docs](https://reference.langchain.com/python/deepagents-cli/local_context/LocalContextMiddleware)

Inject local context (git state, project structure, etc.) into the system prompt.

Runs a bash detection script via `backend.execute()` on first interaction
and again after each summarization event, stores the result in state, and
appends it to the system prompt on every model call.

Because the script runs inside the backend, it works for both local shells
and remote sandboxes.

## Signature

```python
LocalContextMiddleware(
    self,
    backend: _ExecutableBackend | _AsyncExecutableBackend,
    *,
    mcp_server_info: list[MCPServerInfo] | None = None,
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `backend` | `_ExecutableBackend \| _AsyncExecutableBackend` | Yes | Backend instance that provides shell command execution. |
| `mcp_server_info` | `list[MCPServerInfo] \| None` | No | MCP server metadata to include in the system prompt. (default: `None`) |

## Extends

- `AgentMiddleware`

## Constructors

```python
__init__(
    self,
    backend: _ExecutableBackend | _AsyncExecutableBackend,
    *,
    mcp_server_info: list[MCPServerInfo] | None = None,
) -> None
```

| Name | Type |
|------|------|
| `backend` | `_ExecutableBackend \| _AsyncExecutableBackend` |
| `mcp_server_info` | `list[MCPServerInfo] \| None` |


## Properties

- `state_schema`
- `backend`

## Methods

- [`before_agent()`](https://reference.langchain.com/python/deepagents-cli/local_context/LocalContextMiddleware/before_agent)
- [`abefore_agent()`](https://reference.langchain.com/python/deepagents-cli/local_context/LocalContextMiddleware/abefore_agent)
- [`wrap_model_call()`](https://reference.langchain.com/python/deepagents-cli/local_context/LocalContextMiddleware/wrap_model_call)
- [`awrap_model_call()`](https://reference.langchain.com/python/deepagents-cli/local_context/LocalContextMiddleware/awrap_model_call)

---

[View source on GitHub](https://github.com/langchain-ai/deepagents/blob/a827cddf72d72e4b17921b8eb445a3bfb0511cb4/libs/cli/deepagents_cli/local_context.py#L431)