> ## Documentation Index
> Fetch the complete documentation index at: https://gofastmcp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# state

# `fastmcp.cli.deploy.state`

Versioned JSON state helpers for the FastMCP CLI.

## Functions

### `state_lock` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/deploy/state.py#L96" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
state_lock(directory: Path) -> Iterator[None]
```

Lock related CLI state changes across processes.

### `read_state` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/deploy/state.py#L145" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
read_state(path: Path, model: type[ModelT]) -> ModelT | None
```

Read and validate a versioned JSON state file.

### `write_state` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/deploy/state.py#L169" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
write_state(path: Path, data: dict[str, Any]) -> None
```

Write JSON through a restricted temporary file and atomic replacement.

### `remove_state` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/deploy/state.py#L221" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python theme={"theme":{"light":"snazzy-light","dark":"dark-plus"}}
remove_state(path: Path) -> None
```

Remove a state file when it exists.

## Classes

### `StateFileError` <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/fastmcp_slim/fastmcp/cli/deploy/state.py#L20" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

A CLI state file could not be read or written safely.
