import asyncio import json import os import sys import uuid from typing import List, Optional from textwrap import dedent from agno.agent import Agent from agno.models.openai import OpenAIChat from agno.tools.mcp import MultiMCPTools from agno.memory.v2 import Memory from mcp import StdioServerParameters from agno.utils.pprint import apprint_run_response from dotenv import load_dotenv # Load environment variables load_dotenv() GITHUB_TOKEN = os.getenv("GITHUB_PERSONAL_ACCESS_TOKEN") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") PERPLEXITY_API_KEY = os.getenv("PERPLEXITY_API_KEY") async def main(): print("\n" + "="*60) print(" šŸš€ Multi-MCP Intelligent Assistant šŸš€") print("="*60) print("šŸ”— Connected Services: GitHub • Perplexity • Calendar") print("šŸ’” Powered by OpenAI GPT-4o with Advanced Tool Integration") print("="*60 + "\n") # Validate required environment variables required_vars = { "GITHUB_PERSONAL_ACCESS_TOKEN": GITHUB_TOKEN, "OPENAI_API_KEY": OPENAI_API_KEY, "PERPLEXITY_API_KEY": PERPLEXITY_API_KEY, } missing_vars = [name for name, value in required_vars.items() if not value] if missing_vars: print("āŒ ERROR: Missing required environment variables:") for var in missing_vars: print(f" • {var}") print("\nPlease check your .env file and ensure all required variables are set.") return # Generate unique user and session IDs for this terminal session user_id = f"user_{uuid.uuid4().hex[:8]}" session_id = f"session_{uuid.uuid4().hex[:8]}" print(f"šŸ‘¤ User ID: {user_id}") print(f"šŸ”‘ Session ID: {session_id}") print("\nšŸ”Œ Initializing MCP server connections...\n") # Set up environment variables for MCP servers env = { **os.environ, "GITHUB_PERSONAL_ACCESS_TOKEN": GITHUB_TOKEN, "PERPLEXITY_API_KEY": PERPLEXITY_API_KEY } mcp_servers = [ "npx -y @modelcontextprotocol/server-github", "npx -y @chatmcp/server-perplexity-ask", "npx @gongrzhe/server-calendar-autoauth-mcp", "npx @gongrzhe/server-gmail-autoauth-mcp" ] # Start the MCP Tools session async with MultiMCPTools(mcp_servers, env=env) as mcp_tools: print("āœ… Successfully connected to all MCP servers!") # Create the agent with comprehensive instructions agent = Agent( name="MultiMCPAgent", model=OpenAIChat(id="gpt-4o", api_key=OPENAI_API_KEY), tools=[mcp_tools], description="Advanced AI assistant with GitHub, Perplexity, and Calendar integration", instructions=dedent(f""" You are an elite AI assistant with powerful integrations across multiple platforms. Your mission is to help users be incredibly productive across their digital workspace. šŸŽÆ CORE CAPABILITIES & INSTRUCTIONS: 1. šŸ”§ TOOL MASTERY • You have DIRECT access to GitHub, Notion, Perplexity, and Calendar through MCP tools • ALWAYS use the appropriate MCP tool calls for any requests related to these platforms • Be proactive in suggesting powerful workflows and automations • Chain multiple tool calls together for complex tasks 2. šŸ“‹ GITHUB EXCELLENCE • Repository management: create, clone, fork, search repositories • Issue & PR workflow: create, update, review, merge, comment • Code analysis: search code, review diffs, suggest improvements • Branch management: create, switch, merge branches • Collaboration: manage teams, reviews, and project workflows 4. šŸ” PERPLEXITY RESEARCH • Real-time web search and research • Current events and trending information • Technical documentation and learning resources • Fact-checking and verification 5. šŸ“… CALENDAR INTEGRATION • Event scheduling and management • Meeting coordination and availability • Deadline tracking and reminders 6. šŸŽØ INTERACTION PRINCIPLES • Be conversational, helpful, and proactive • Explain what you're doing and why • Suggest follow-up actions and optimizations • Handle errors gracefully with alternative solutions • Ask clarifying questions when needed • Provide rich, formatted responses using markdown 7. šŸš€ ADVANCED WORKFLOWS • Cross-platform automation (e.g., GitHub issues → Notion tasks) • Research-driven development (Perplexity → GitHub) • Project management integration • Documentation and knowledge sharing SESSION INFO: • User ID: {user_id} • Session ID: {session_id} • Active Services: GitHub, Notion, Perplexity, Calendar REMEMBER: You're not just answering questions - you're a productivity multiplier. Think big, suggest workflows, and help users achieve more than they imagined possible! """), markdown=True, show_tool_calls=True, retries=3, memory=Memory(), add_history_to_messages=True, num_history_runs=10, # Increased for better context retention ) print("\n" + "šŸŽ‰ " + "="*54 + " šŸŽ‰") print(" Multi-MCP Assistant is READY! Let's get productive!") print("šŸŽ‰ " + "="*54 + " šŸŽ‰\n") print("šŸ’” Try these example commands:") print(" • 'Show my recent GitHub repositories'") print(" • 'Search for the latest AI developments'") print(" • 'Schedule a meeting for next week'") print("⚔ Type 'exit', 'quit', or 'bye' to end the session\n") # Start interactive CLI session await agent.acli_app( user_id=user_id, session_id=session_id, user="You", emoji="šŸ¤–", stream=True, markdown=True, exit_on=["exit", "quit", "bye", "goodbye"] ) if __name__ == "__main__": asyncio.run(main())