Skip to main content

fastmcp.utilities.openapi.formatters

Parameter formatting functions for OpenAPI operations.

Functions

format_array_parameter

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 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 a simple example value from a JSON schema dictionary. Very basic implementation focusing on types.

format_json_for_description

Formats Python data as a JSON string block for Markdown.

format_simple_description

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

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.