Skip to main content
Use Spring AI’s native MCP adapter from a Java backend to discover Magic Hour tools, verify API access, and retrieve an existing image project. This walkthrough calls no model and needs no model-provider API key.

Install and configure

Requires JDK 17+ and Maven. Create pom.xml in your application directory:
Provide MAGIC_HOUR_API_KEY through your server’s secret manager. Set MAGIC_HOUR_IMAGE_PROJECT_ID to an image project ID saved from an accepted generation. Keep the key, account details, and temporary download URLs private.

Discover tools and recover saved project status

Save this as MagicHourSpring.java beside pom.xml. It uses the hosted Streamable HTTP transport with bearer authorization, adapts the tools into Spring AI ToolCallbacks, and closes the MCP client in finally.
From a POSIX shell in that directory, resolve the runtime dependencies and run the application with Java’s single-file source launcher:
Spring AI’s callback returns a JSON array of content blocks. The example reads the text block’s JSON object and prints authorization success and project status without printing private account values or download URLs. A tool error propagates as an exception. If a request fails, keep the accepted project ID and check it again. A failed status read does not establish that generation failed. Do not automatically submit another paid job.

Verified scope

Validated together: Spring AI 2.0.2, MCP Java SDK 2.1.0, and JDK 17.0.21. The native adapter discovered 48 tools, authenticated an account read, and returned complete for a previously accepted image project. Graceful client cleanup succeeded. This validates native tool discovery and authenticated metadata retrieval. It does not run a model-driven Spring AI agent, create a new image, download media, or verify an upstream directory listing. A model-driven application requires its own model setup. See MCP setup for the full server capabilities and recovering an existing result for durable job recovery.