Skip to main content
Use Mastra’s native MCPClient to discover Magic Hour tools, verify API access, and retrieve a completed image project by its saved ID. This walkthrough needs no model or provider API key and submits no new generation.

Install and configure

Requires Node.js 22.13+. These dependency versions were validated together on Node.js 24.21:
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 keys, account details, and signed download URLs private.

Verify access and recover a saved project

Save this as mastra.mjs and run node mastra.mjs. Telemetry is disabled before importing Mastra. The legacy protocol setting selects MCP’s initialization handshake.
Discovery is public, so it does not establish authorization. The account check verifies API access without printing private fields. Mastra namespaces tools as serverName_toolName: the magic_hour server key produces magic_hour_account_retrieve. Check required tools as well as discovery errors, since individual tools can be absent. The project read reuses the accepted ID without another creation or generation charge. If a job is still queued or rendering, keep the same ID and retrieve it again later. Completed project metadata contains temporary download URLs; preserve them exactly, including query parameters.

Use tools in your agent

Mastra accepts the discovered tool map as an agent’s tools option. Keep the MCP client open while your agent uses those tools, then disconnect it during application shutdown. See Mastra’s MCPClient reference for agent wiring. This walkthrough validates direct tool execution; it does not run a model or test agent-driven tool selection. Generation sends authorized prompts and media to Magic Hour and spends credits. Save every accepted project ID before waiting, then resume that job instead of repeating creation. See Magic Hour MCP for uploads, generation, and exact download handling, and our privacy policy. Native validation discovered 48 tools with no discovery errors, verified the account payload, and retrieved the existing completed image project with its exact saved ID. The client disconnected afterward. No new generation, model call, or media download was performed. Inline rendering and binary downloads are not demonstrated here.