fastmcp/examples/apps/qr_server
Jeremiah Lowin 7d76c9d055
Add examples/ to the ty static-analysis gate (#4466)
* Add examples/ to ty static-analysis gate

* Fix example type errors and stale SDK idioms for ty

* Use typing_extensions.TypedDict for the quiz tool-param type

Question is a take_quiz parameter, so FastMCP builds a Pydantic schema
for it; typing.TypedDict raises PydanticUserError on Python 3.10/3.11
(only 3.12+ accepts it). ty and 3.12 runs miss this, so it slipped in.

* Guard get_access_token() None case in huggingface_oauth example

Caught by the ty gate this PR adds: the example, merged separately,
had never been type-checked against examples/. Matches the existing
aws_oauth/keycloak_oauth pattern.

* Print actual YAML text in custom serializer example
2026-07-18 19:44:13 -04:00
..
fastmcp.json MCP Apps: structured CSP/permissions types, resource meta propagation fix, QR example (#3031) 2026-01-30 14:05:25 -05:00
pyproject.toml MCP Apps: structured CSP/permissions types, resource meta propagation fix, QR example (#3031) 2026-01-30 14:05:25 -05:00
qr_server.py Add examples/ to the ty static-analysis gate (#4466) 2026-07-18 19:44:13 -04:00
README.md Rename ui= to app= and consolidate ToolUI/ResourceUI into AppConfig (#3117) 2026-02-08 20:26:47 -05:00

QR Code MCP App

An MCP App server that generates QR codes with an interactive viewer UI. Ported from the ext-apps QR server example to demonstrate FastMCP's MCP Apps support.

What it demonstrates

  • Linking a tool to a ui:// resource via AppConfig
  • Serving embedded HTML with the @modelcontextprotocol/ext-apps JS SDK from CDN
  • Declaring CSP resource domains via ResourceCSP
  • Returning ImageContent (base64 PNG) from a tool

Setup

cd examples/apps/qr_server
uv sync

Usage

uv run python qr_server.py

Or install it into an MCP client:

fastmcp install stdio fastmcp.json

How it works

The server registers one tool (generate_qr) and one resource (ui://qr-server/view.html). The tool generates a QR code as a base64 PNG image. The resource serves an HTML page that uses the MCP Apps JS SDK to receive the tool result and display the image in a sandboxed iframe.

The HTML loads the ext-apps SDK from unpkg, so the resource declares csp=ResourceCSP(resource_domains=["https://unpkg.com"]) to allow the host to set the appropriate Content-Security-Policy.