import webbrowser
# Create YouTube and Gmail MCP servers
youtube_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.YOUTUBE,
user_id="1234",
platform_name="Klavis",
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
platform_name="Klavis",
)
# Handle OAuth for Gmail
webbrowser.open(gmail_mcp_instance.oauth_url)
print(f"🔐 Opening OAuth authorization for Gmail...")
print(f"📱 If not redirected automatically, open: {gmail_mcp_instance.oauth_url}")
VIDEO_URL = "https://www.youtube.com/watch?v=LCEmiRjPEtQ"
RECIPIENT_EMAIL = "your-email@example.com"
# Configure multiple MCP servers
multiple_server_params = [
{
"url": youtube_mcp_instance.server_url,
"transport": "streamable-http"
},
{
"url": gmail_mcp_instance.server_url,
"transport": "streamable-http"
}
]
try:
with MCPServerAdapter(multiple_server_params) as all_mcp_tools:
print(f"✅ Available tools from all MCP servers: {[tool.name for tool in all_mcp_tools]}")
# Create YouTube Research Agent
youtube_research_agent = Agent(
role="YouTube Content Analyst",
goal="Research and analyze YouTube videos to extract comprehensive insights",
backstory="You are an expert at analyzing video content and extracting key insights.",
tools=all_mcp_tools,
reasoning=False,
verbose=False,
)
# Create Email Communication Agent
email_agent = Agent(
role="Email Communications Specialist",
goal="Draft and send professional email communications based on research findings",
backstory="You are skilled at crafting professional emails with clear, impactful messaging.",
tools=all_mcp_tools,
reasoning=True,
verbose=False,
)
# Define workflow tasks
youtube_research_task = Task(
description=f"Research the YouTube video at {VIDEO_URL}. Extract transcript, analyze the content for key insights about AI and software development, and create a comprehensive analysis report with key takeaways and recommendations.",
expected_output="Complete video analysis report with transcript, key insights, recommendations, and strategic takeaways",
agent=youtube_research_agent
)
send_email_task = Task(
description=f"Based on the youtube analysis, draft and send a professional email to {RECIPIENT_EMAIL} with the subject 'YouTube Video AI Analysis'. Include content of the youtube video in the email.",
expected_output="Confirmation that a professional email has been sent with the research insights",
agent=email_agent,
context=[youtube_research_task]
)
# Create and execute the crew
multi_service_crew = Crew(
agents=[youtube_research_agent, email_agent],
tasks=[youtube_research_task, send_email_task],
verbose=False,
process=Process.sequential
)
result = multi_service_crew.kickoff()
print(result)
except Exception as e:
print(f"❌ Error with multi-service MCP integration: {e}")