Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions MCP Integration/magic_hour_mcp.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Create AI video with Magic Hour MCP\n",
"\n",
"Connect CrewAI 1.15.22 to Magic Hour's hosted MCP server. Magic Hour exposes image, video, and audio generation tools. This quickstart discovers tools without spending credits, then optionally runs one text-to-video task.\n",
"\n",
"Prerequisites:\n",
"- Python 3.10\u20133.13\n",
"- [Magic Hour API key](https://magichour.ai/developer)\n",
"- `OPENAI_API_KEY` for the optional crew run\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%pip install -q \"crewai==1.15.22\" \"crewai-tools[mcp]==1.15.22\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"\n",
"from crewai import Agent, Crew, Process, Task\n",
"from crewai_tools import MCPServerAdapter\n",
"\n",
"assert os.environ.get(\"MAGIC_HOUR_API_KEY\"), \"Set MAGIC_HOUR_API_KEY before continuing.\"\n",
"\n",
"server_params = {\n",
" \"url\": \"https://mcp.magichour.ai/\",\n",
" \"headers\": {\"Authorization\": f\"Bearer {os.environ['MAGIC_HOUR_API_KEY']}\"},\n",
" \"transport\": \"streamable-http\",\n",
"}\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Discover tools\n",
"\n",
"This connects and lists tools only. It does not start a generation job or spend Magic Hour credits.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with MCPServerAdapter(server_params, connect_timeout=60) as tools:\n",
" print(f\"Discovered {len(tools)} Magic Hour tools\")\n",
" print(\"\\n\".join(tool.name for tool in tools))\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create one video\n",
"\n",
"The next cell starts a credit-consuming render. It creates one project, waits on that same project ID, and asks the agent to return the exact signed download URL without trimming query parameters.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assert os.environ.get(\"OPENAI_API_KEY\"), \"Set OPENAI_API_KEY before running the crew.\"\n",
"\n",
"with MCPServerAdapter(server_params, connect_timeout=60) as tools:\n",
" producer = Agent(\n",
" role=\"AI video producer\",\n",
" goal=\"Create one polished video and return its exact download URL\",\n",
" backstory=(\n",
" \"You produce short videos with Magic Hour. Create each project once, wait for the \"\n",
" \"same project ID to finish, and preserve signed download URLs exactly as returned.\"\n",
" ),\n",
" tools=tools,\n",
" verbose=True,\n",
" )\n",
" task = Task(\n",
" description=(\n",
" \"Create a five-second cinematic video of bioluminescent jellyfish drifting through \"\n",
" \"deep ocean water. Wait for completion and return the exact download URL.\"\n",
" ),\n",
" expected_output=\"The completed project ID and exact signed video download URL.\",\n",
" agent=producer,\n",
" )\n",
" result = Crew(agents=[producer], tasks=[task], process=Process.sequential).kickoff()\n",
" print(result)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python",
"version": "3.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}