---
title: formatters
sidebarTitle: formatters
---

# `fastmcp.utilities.openapi.formatters`


Parameter formatting functions for OpenAPI operations.

## Functions

### `format_array_parameter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/formatters.py#L12" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
format_array_parameter(values: list, parameter_name: str, is_query_parameter: bool = False) -> str | list
```


Format an array parameter according to OpenAPI specifications.

**Args:**
- `values`: List of values to format
- `parameter_name`: Name of the parameter (for error messages)
- `is_query_parameter`: If True, can return list for explode=True behavior

**Returns:**
- String (comma-separated) or list (for query params with explode=True)


### `format_deep_object_parameter` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/formatters.py#L66" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
format_deep_object_parameter(param_value: dict, parameter_name: str) -> dict[str, str]
```


Format a dictionary parameter for deep-object style serialization.

According to OpenAPI 3.0 spec, deepObject style with explode=true serializes
object properties as separate query parameters with bracket notation.

For example, `{"id": "123", "type": "user"}` becomes
`param[id]=123&param[type]=user`.

**Args:**
- `param_value`: Dictionary value to format
- `parameter_name`: Name of the parameter

**Returns:**
- Dictionary with bracketed parameter names as keys


### `generate_example_from_schema` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/formatters.py#L100" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
generate_example_from_schema(schema: JsonSchema | None) -> Any
```


Generate a simple example value from a JSON schema dictionary.
Very basic implementation focusing on types.


### `format_json_for_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/formatters.py#L183" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
format_json_for_description(data: Any, indent: int = 2) -> str
```


Formats Python data as a JSON string block for Markdown.


### `format_simple_description` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/formatters.py#L192" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
format_simple_description(base_description: str, parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
```


Formats a simple description for MCP objects (tools, resources, prompts).
Excludes response details, examples, and verbose status codes.

**Args:**
- `base_description`: The initial description to be formatted.
- `parameters`: A list of parameter information.
- `request_body`: Information about the request body.

**Returns:**
- The formatted description string with minimal details.


### `format_description_with_responses` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/openapi/formatters.py#L225" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

```python
format_description_with_responses(base_description: str, responses: dict[str, Any], parameters: list[ParameterInfo] | None = None, request_body: RequestBodyInfo | None = None) -> str
```


Formats the base description string with response, parameter, and request body information.

**Args:**
- `base_description`: The initial description to be formatted.
- `responses`: A dictionary of response information, keyed by status code.
- `parameters`: A list of parameter information,
including path and query parameters. Each parameter includes details such as name,
location, whether it is required, and a description.
- `request_body`: Information about the request body,
including its description, whether it is required, and its content schema.

**Returns:**
- The formatted description string with additional details about responses, parameters,
- and the request body.

