Skip to main content

fastmcp.utilities.openapi.formatters

Parameter formatting functions for OpenAPI operations.

Functions

format_array_parameter

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

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

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

format_json_for_description(data: Any, indent: int = 2) -> str
Formats Python data as a JSON string block for Markdown.

format_simple_description

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

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.