Skip to main content
Use LlamaIndex’s native MCP adapter with Magic Hour’s hosted MCP. This walkthrough checks API authorization and retrieves an existing image without an LLM, model-provider key, or new generation.

Install and configure

Requires Python 3.10+; native validation used Python 3.12. Install the versions verified together:
Provide a Magic Hour API key through your secret manager as MAGIC_HOUR_API_KEY. Set MAGIC_HOUR_IMAGE_PROJECT_ID to an image project ID already saved from an accepted generation. Keep credentials, account details, and temporary download URLs private.

Verify access and recover an image

Save this as your application entry point and run it with Python. McpToolSpec converts MCP schemas into LlamaIndex FunctionTool objects. Calling acall invokes a tool directly, without running an agent or model. Each call closes its MCP session; the outer context closes the HTTP client after all calls finish.
Tool discovery is public; the account read checks actual Magic Hour authorization without printing private account fields. The example only invokes account access and image recovery. Recovery reuses the saved project ID without another creation or generation charge. A timeout does not cancel the accepted job: keep its ID and retry recovery. Inline media is limited to 8 MiB here; use the exact returned signed download URL, preserving its query parameters, for larger outputs.

Use with an agent

Pass the returned tools to a LlamaIndex agent while the HTTP client context remains open. Add only the tools your application needs through allowed_tools. Model-backed runs need their own provider configuration and may spend provider tokens and Magic Hour credits when generation tools are used. The independently maintained Magic Hour ToolSpec also provides image generation, text-to-video and image-to-video through the Python SDK. This guide uses LlamaIndex’s existing MCP adapter to access the hosted MCP’s account and recovery tools. Generation sends authorized prompts and media to Magic Hour. Persist each accepted project ID before waiting and recover it instead of repeating a paid creation. See Magic Hour MCP for uploads, generation and download rules, our privacy policy, and the official LlamaIndex MCP guide. Native validation converted 48 live tool schemas, invoked account access through FunctionTool.acall, and recovered a completed project as a typed inline 640×640 PNG. Its bytes matched the accepted job’s output, full image decode passed, and the HTTP/MCP sessions closed. No model, new generation or additional credits were used. This proof covers the MCP adapter; the separate community ToolSpec and model-driven agent execution were not part of this validation.