Skip to main content

fastmcp.utilities.ui

Shared UI utilities for FastMCP HTML pages. This module provides reusable HTML/CSS components for OAuth callbacks, consent pages, and other user-facing interfaces.

Functions

create_page

Create a complete HTML page with FastMCP styling. Args:
  • content: HTML content to place inside the page
  • title: Page title
  • additional_styles: Extra CSS to include
  • csp_policy: Content Security Policy header value. If empty string "", the CSP meta tag is omitted entirely.
Returns:
  • Complete HTML page as string
Create logo HTML. Args:
  • icon_url: Optional custom icon URL. If not provided, uses the FastMCP logo.
  • alt_text: Alt text for the logo image.
Returns:
  • HTML for logo image tag.

create_status_message

Create a status message with icon. Args:
  • message: Status message text
  • is_success: True for success (✓), False for error (✕)
Returns:
  • HTML for status message

create_info_box

Create an info box. Args:
  • content: HTML content for the info box
  • is_error: True for error styling, False for normal
  • centered: True to center the text, False for left-aligned
  • monospace: True to use gray monospace font styling instead of blue
Returns:
  • HTML for info box

create_detail_box

Create a detail box with key-value pairs. Args:
  • rows: List of (label, value) tuples
Returns:
  • HTML for detail box

create_button_group

Create a group of buttons. Args:
  • buttons: List of (text, value, css_class) tuples
Returns:
  • HTML for button group

create_secure_html_response

Create an HTMLResponse with security headers. Adds X-Frame-Options: DENY to prevent clickjacking attacks per MCP security best practices. Args:
  • html: HTML content to return
  • status_code: HTTP status code
Returns:
  • HTMLResponse with security headers