Skip to main content

Partnership

CrewAI has officially showcased their integration with Klavis AI in this LinkedIn post, demonstrating how to build powerful AI agent crews that can automate complex workflows across multiple platforms.
CrewAI and Klavis Integration - Automate your next sales follow-up

Prerequisites

Before we begin, you’ll need:

Installation

First, install the required packages:
pip install crewai 'crewai-tools[mcp]' klavis openai

Setup Environment Variables

import os

# Set environment variables
os.environ["OPENAI_API_KEY"] = "your-openai-api-key-here"  # Replace with your actual OpenAI API key
os.environ["KLAVIS_API_KEY"] = "your-klavis-api-key-here"   # Replace with your actual Klavis API key

CrewAI with MCP Integration

CrewAI allows you to create specialized AI agent crews where each agent can have access to different MCP tools. This enables sophisticated multi-agent workflows that can:
  1. Create MCP Instances: Set up connections to external services
  2. Specialized Agents: Each agent focuses on specific tasks with relevant tools
  3. Collaborative Workflows: Agents work together in sequential or parallel processes
  4. Tool Discovery: Automatically discover available tools from MCP servers
  5. Smart Coordination: CrewAI manages task dependencies and agent collaboration

Crew AI + Klavis Strata

Create a crew agent that helps in assisting user queries using Strata Server

Step 1 - Create Strata MCP Server with Gmail and Slack

from klavis import Klavis
from klavis.types import McpServerName, ToolFormat
import webbrowser

klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))

response = klavis_client.mcp_server.create_strata_server(
    servers=[McpServerName.GMAIL, McpServerName.SLACK], 
    user_id="1234"
)

# Handle OAuth authorization for each services
if response.oauth_urls:
    for server_name, oauth_url in response.oauth_urls.items():
        webbrowser.open(oauth_url)
        print(f"Or please open this URL to complete {server_name} OAuth authorization: {oauth_url}")
OAuth Authorization Required: The code above will open browser windows for each service. Click through the OAuth flow to authorize access to your accounts.

Step 2 - Create method to use MCP Server with Crew AI

This method handles multiple rounds of tool calls until a final response is ready, allowing the AI to chain tool executions for complex tasks.
import json
from crewai import Agent, Task, Crew, Process
from crewai_tools import MCPServerAdapter

def crew_with_mcp_server(mcp_server_url: str, user_query: str):
    klavis_server_params = [
            {
                "url": mcp_server_url,
                "transport": "streamable-http"
            }
        ]

    with MCPServerAdapter(klavis_server_params) as all_mcp_tools:
        print(f"Available tools: {[tool.name for tool in all_mcp_tools]}")

        klavis_agent = Agent(
            role="Klavis Query Assistant",
            goal="Assist the user with their query using available tools",
            backstory="Expert at assisting users with their queries using available tools",
            tools=all_mcp_tools,
            verbose=False,
            llm="gpt-4o"
        )

        klavis_task = Task(
            description=f"Answer the user's query: {user_query}",
            expected_output="Provide a detailed response to the user's query",
            agent=klavis_agent
        )

        crew = Crew(
            agents = [klavis_agent],
            tasks = [klavis_task],
            process=Process.sequential,
            verbose=True
        )

        result = crew.kickoff()
        return result

Step 3 - Run!

result = crew_with_mcp_server(
    mcp_server_url=response.strata_server_url, 
    user_query="Check my latest 5 emails and summarize them in a Slack message to #general"
)

print(f"\nFinal Response: {result}")
Perfect! You’ve integrated Crew with Strata MCP servers.

Security Best Practices

When using CrewAI with Klavis MCP servers, follow these security guidelines:
def create_secure_crew():
    """Demonstrates secure MCP server integration with CrewAI"""
    
    # 1. Use environment variables for sensitive data
    api_key = os.getenv("KLAVIS_API_KEY")
    if not api_key:
        raise ValueError("KLAVIS_API_KEY environment variable is required")
    
    # 2. Validate server URLs (use HTTPS in production)
    server_params = [{
        "url": server_instance.server_url,
        "transport": "streamable-http"
    }]
    
    # 3. Always use context managers for proper resource cleanup
    try:
        with MCPServerAdapter(server_params) as mcp_tools:
            # 4. Validate available tools before use
            if not mcp_tools:
                raise ValueError("No tools available from MCP server")
            
            print(f"✅ Securely connected with {len(mcp_tools)} tools")
            
            # 5. Create agents with limited scope
            agent = Agent(
                role="Data Analyst",
                goal="Analyze data within defined parameters",
                backstory="You operate within strict security guidelines.",
                tools=mcp_tools,
                reasoning=False,  # Disable for production
                verbose=False     # Disable verbose logging in production
            )
            
            return agent
            
    except Exception as e:
        print(f"🔒 Security check failed: {e}")
        return None

# Example usage
secure_agent = create_secure_crew()
if secure_agent:
    print("✅ Secure crew created successfully")

Available MCP Servers

CrewAI works with all Klavis MCP servers. Here are some popular options:

Communication

Gmail, Slack, Discord, Outlook

Content & Media

YouTube, Notion, Google Docs, WordPress

Development

GitHub, Jira, Linear, Confluence

Data & Analytics

Google Sheets, Supabase, PostgreSQL

Business Tools

Salesforce, HubSpot, Asana, ClickUp

Cloud Storage

Google Drive, Dropbox, OneDrive

Summary

CrewAI + Klavis integration enables you to build sophisticated multi-agent AI systems with real-world capabilities. Key benefits include:

🚀 CrewAI + Klavis Benefits:

  • Seamless Integration: MCPServerAdapter makes MCP connection effortless
  • Agent Specialization: Each agent can focus on specific domains
  • Scalable Architecture: Easy to add more agents and MCP servers
  • Professional AI Teams: Create sophisticated multi-agent systems
  • Real-World Impact: Connect AI to actual business tools and services
Ready to build your first AI crew? Start with a simple agent and expand from there! 🚀👥