Skip to main content
Connect Microsoft Agent Framework to Magic Hour’s hosted MCP server using its native Python client. This walkthrough discovers tools, verifies API authorization, and reads an existing image project without submitting another generation. It calls no model and needs no Azure or OpenAI key.

Install and configure

Requires Python 3.10+. Install the core package and compatible MCP SDK:
The core package supports this workflow without installing every model-provider integration. Tenacity is required by the native MCP connection’s capability-list subscription. Provide your Magic Hour API key through your server-side secret manager as MAGIC_HOUR_API_KEY. Set MAGIC_HOUR_IMAGE_PROJECT_ID to a saved image project ID. Keep keys, private account responses, and temporary download URLs private.

Verify access and read a saved job

Save this as your Python entry point. The async context closes the owned MCP connection when it exits. OpenTelemetry is disabled before importing the SDK.
Discovery is public; the account call separately verifies the API key. Native MCP errors raise an exception. The SDK converts structured results into text content; the example parses that metadata without printing the private account response or signed download URLs. Reusing an accepted project ID reads its status without charging for another creation. A timeout does not cancel a generation: keep its ID and recover it instead of repeating a paid request. The SDK may reconnect and retry a tool call after a lost connection, so this example uses only read operations. Review retry behavior before adding paid generation tools.

Add model-driven behavior separately

Model-driven agents require their own provider configuration and can spend model tokens and Magic Hour credits. This recipe covers native MCP tool discovery and direct function calls; Agent execution, model selection, new generation, and media downloads are separate workflows. See Magic Hour MCP for generation, upload and download rules, our privacy policy, and the official MCP client source.