Create powerful AI workflows by connecting multiple MCP servers including Outlook, Gmail, Google Docs for enhanced automation capabilities in Klavis AI.
Outlook Mail is a web-based suite of webmail, contacts, tasks, and calendaring services from Microsoft
Gmail is a free email service provided by Google
Google Docs is a word processor included as part of the free, web-based Google Docs Editors suite
Follow these steps to connect your AI agents to these MCP servers
Sign up for KlavisAI to access our MCP server management platform.
Add your desired MCP servers to your AI client and configure authentication settings.
Verify your connections work correctly and start using your enhanced AI capabilities.
import os
import json
from fireworks.client import Fireworks
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType, ToolFormat
# Initialize clients
fireworks_client = Fireworks(api_key=os.getenv("FIREWORKS_API_KEY"))
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
platform_name="Klavis",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
platform_name="Klavis",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
platform_name="Klavis",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
# Get all MCP tools
outlook_tools = klavis_client.mcp_server.list_tools(
server_url=outlook_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
gmail_tools = klavis_client.mcp_server.list_tools(
server_url=gmail_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
google_docs_tools = klavis_client.mcp_server.list_tools(
server_url=google_docs_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
# Combine all tools
all_tools = []
all_tools.extend(outlook_tools.tools)
all_tools.extend(gmail_tools.tools)
all_tools.extend(google_docs_tools.tools)
messages = [
{"role": "system", "content": "You are a helpful assistant with access to multiple data sources."},
{"role": "user", "content": user_message}
]
response = fireworks_client.chat.completions.create(
model="accounts/fireworks/models/llama-v3p1-70b-instruct",
messages=messages,
tools=all_tools
)import os
import json
from anthropic import Anthropic
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType, ToolFormat
# Initialize clients
anthropic_client = Anthropic(api_key=os.getenv("ANTHROPIC_API_KEY"))
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
# Constants
CLAUDE_MODEL = "claude-3-5-sonnet-20241022"
user_message = "Your message here"
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
# Get tools from all MCP servers
outlook_tools = klavis_client.mcp_server.list_tools(
server_url=outlook_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.ANTHROPIC,
)
gmail_tools = klavis_client.mcp_server.list_tools(
server_url=gmail_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.ANTHROPIC,
)
google_docs_tools = klavis_client.mcp_server.list_tools(
server_url=google_docs_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.ANTHROPIC,
)
# Combine all tools
all_tools = []
all_tools.extend(outlook_tools.tools)
all_tools.extend(gmail_tools.tools)
all_tools.extend(google_docs_tools.tools)
messages = [
{"role": "user", "content": user_message}
]
response = anthropic_client.messages.create(
model=CLAUDE_MODEL,
max_tokens=4000,
messages=messages,
tools=all_tools
)import Anthropic from '@anthropic-ai/sdk';
import { KlavisClient, Klavis } from 'klavis';
// Initialize clients
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });
const CLAUDE_MODEL = "claude-3-5-sonnet-20241022";
const userMessage = "Your message here";
const outlookMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Outlook,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const gmailMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Gmail,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const google_docsMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.GoogleDocs,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
// Get tools from all MCP servers
const outlookTools = await klavisClient.mcpServer.listTools({
serverUrl: outlookMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Anthropic,
});
const gmailTools = await klavisClient.mcpServer.listTools({
serverUrl: gmailMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Anthropic,
});
const google_docsTools = await klavisClient.mcpServer.listTools({
serverUrl: google_docsMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Anthropic,
});
// Combine all tools
const allTools = [
...outlookTools.tools,
...gmailTools.tools,
...google_docsTools.tools
];
const response = await anthropic.messages.create({
model: CLAUDE_MODEL,
max_tokens: 4000,
messages: [{ role: 'user', content: userMessage }],
tools: allTools,
});import json
import os
from openai import OpenAI
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType, ToolFormat
# Initialize clients
openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
# Constants
OPENAI_MODEL = "gpt-4o-mini"
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
# Get tools from all MCP servers
outlook_tools = klavis_client.mcp_server.list_tools(
server_url=outlook_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
gmail_tools = klavis_client.mcp_server.list_tools(
server_url=gmail_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
google_docs_tools = klavis_client.mcp_server.list_tools(
server_url=google_docs_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
# Combine all tools
all_tools = []
all_tools.extend(outlook_tools)
all_tools.extend(gmail_tools)
all_tools.extend(google_docs_tools)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": user_message}
]
response = openai_client.chat.completions.create(
model=OPENAI_MODEL,
messages=messages,
tools=all_tools if all_tools else None
)import OpenAI from 'openai';
import { KlavisClient, Klavis } from 'klavis';
// Initialize clients
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });
const OPENAI_MODEL = "gpt-4o-mini";
const userMessage = "Your query here";
const outlookMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Outlook,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const gmailMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Gmail,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const google_docsMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.GoogleDocs,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
// Get tools from all MCP servers
const outlookTools = await klavisClient.mcpServer.listTools({
serverUrl: outlookMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Openai,
});
const gmailTools = await klavisClient.mcpServer.listTools({
serverUrl: gmailMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Openai,
});
const google_docsTools = await klavisClient.mcpServer.listTools({
serverUrl: google_docsMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Openai,
});
// Combine all tools
const allTools = [
...outlookTools,
...gmailTools,
...google_docsTools
];
const response = await openai.chat.completions.create({
model: OPENAI_MODEL,
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: userMessage }
],
tools: allTools,
});import os
from google import genai
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType, ToolFormat
# Initialize clients
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
client = genai.Client(api_key=os.getenv("GOOGLE_API_KEY"))
user_message = "Your query here"
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
# Get tools from all MCP servers
outlook_tools = klavis_client.mcp_server.list_tools(
server_url=outlook_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.GEMINI,
)
gmail_tools = klavis_client.mcp_server.list_tools(
server_url=gmail_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.GEMINI,
)
google_docs_tools = klavis_client.mcp_server.list_tools(
server_url=google_docs_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.GEMINI,
)
# Combine all tools
all_tools = []
all_tools.extend(outlook_tools.tools)
all_tools.extend(gmail_tools.tools)
all_tools.extend(google_docs_tools.tools)
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=user_message,
config=genai.types.GenerateContentConfig(
tools=all_tools,
),
)import { GoogleGenAI } from '@google/genai';
import { KlavisClient, Klavis } from 'klavis';
// Initialize clients
const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY });
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });
const userMessage = "Your query here";
const outlookMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Outlook,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const gmailMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Gmail,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const google_docsMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.GoogleDocs,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
// Get tools from all MCP servers
const outlookTools = await klavisClient.mcpServer.listTools({
serverUrl: outlookMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Gemini,
});
const gmailTools = await klavisClient.mcpServer.listTools({
serverUrl: gmailMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Gemini,
});
const google_docsTools = await klavisClient.mcpServer.listTools({
serverUrl: google_docsMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Gemini,
});
// Combine all tools
const allTools = [
...outlookTools.tools,
...gmailTools.tools,
...google_docsTools.tools
];
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: userMessage,
tools: allTools,
});import os
import asyncio
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
# Initialize clients
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
llm = ChatOpenAI(model="gpt-4o-mini", api_key=os.getenv("OPENAI_API_KEY"))
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
mcp_client = MultiServerMCPClient({
"outlook": {
"transport": "streamable_http",
"url": outlook_mcp_instance.server_url
},
"gmail": {
"transport": "streamable_http",
"url": gmail_mcp_instance.server_url
},
"google docs": {
"transport": "streamable_http",
"url": google_docs_mcp_instance.server_url
}
})
tools = asyncio.run(mcp_client.get_tools())
agent = create_react_agent(
model=llm,
tools=tools,
)
response = asyncio.run(agent.ainvoke({
"messages": [{"role": "user", "content": "Your query here"}]
}))import { KlavisClient, Klavis } from 'klavis';
import { MultiServerMCPClient } from "@langchain/mcp-adapters";
import { ChatOpenAI } from "@langchain/openai";
import { createReactAgent } from "@langchain/langgraph/prebuilt";
// Initialize clients
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });
const llm = new ChatOpenAI({ model: "gpt-4o-mini", apiKey: process.env.OPENAI_API_KEY });
const outlookMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Outlook,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const gmailMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Gmail,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const google_docsMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.GoogleDocs,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const mcpClient = new MultiServerMCPClient({
"outlook": {
transport: "streamable_http",
url: outlookMcpInstance.serverUrl
},
"gmail": {
transport: "streamable_http",
url: gmailMcpInstance.serverUrl
},
"google docs": {
transport: "streamable_http",
url: google_docsMcpInstance.serverUrl
}
});
const tools = await mcpClient.getTools();
const agent = createReactAgent({
llm: llm,
tools: tools,
});
const response = await agent.invoke({
messages: [{ role: "user", content: "Your query here" }]
});import os
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType
from llama_index.tools.mcp import (
BasicMCPClient,
get_tools_from_mcp_url,
aget_tools_from_mcp_url,
)
from llama_index.core.agent.workflow import FunctionAgent, AgentWorkflow
# Initialize clients
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
outlook_tools = await aget_tools_from_mcp_url(
outlook_mcp_instance.server_url,
client=BasicMCPClient(outlook_mcp_instance.server_url)
)
gmail_tools = await aget_tools_from_mcp_url(
gmail_mcp_instance.server_url,
client=BasicMCPClient(gmail_mcp_instance.server_url)
)
google_docs_tools = await aget_tools_from_mcp_url(
google_docs_mcp_instance.server_url,
client=BasicMCPClient(google_docs_mcp_instance.server_url)
)
outlook_agent = FunctionAgent(
name="outlook_agent",
tools=outlook_tools,
llm=llm,
)
gmail_agent = FunctionAgent(
name="gmail_agent",
tools=gmail_tools,
llm=llm,
)
google_docs_agent = FunctionAgent(
name="google_docs_agent",
tools=google_docs_tools,
llm=llm,
)
workflow = AgentWorkflow(
agents=[outlook_agent, gmail_agent, google_docs_agent],
root_agent="outlook_agent",
)import { KlavisClient, Klavis } from 'klavis';
import { mcp } from "@llamaindex/tools";
import { agent, multiAgent } from "@llamaindex/workflow";
import { openai } from "@llamaindex/llm";
// Initialize clients
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });
const outlookMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Outlook,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const gmailMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Gmail,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const google_docsMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.GoogleDocs,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
// Create MCP server connections
const outlookServer = mcp({
url: outlookMcpInstance.serverUrl,
verbose: true,
});
const gmailServer = mcp({
url: gmailMcpInstance.serverUrl,
verbose: true,
});
const google_docsServer = mcp({
url: google_docsMcpInstance.serverUrl,
verbose: true,
});
// Get tools from MCP servers
const outlookTools = await outlookServer.tools();
const gmailTools = await gmailServer.tools();
const google_docsTools = await google_docsServer.tools();
// Create specialized agents
const outlookAgent = agent({
name: "outlook_agent",
llm: openai({ model: "gpt-4o" }),
tools: outlookTools,
});
const gmailAgent = agent({
name: "gmail_agent",
llm: openai({ model: "gpt-4o" }),
tools: gmailTools,
});
const google_docsAgent = agent({
name: "google_docs_agent",
llm: openai({ model: "gpt-4o" }),
tools: google_docsTools,
});
// Create multi-agent workflow
const agents = multiAgent({
agents: [outlookAgent, gmailAgent, google_docsAgent],
rootAgent: outlookAgent,
});import os
from crewai import Agent, Task, Crew, Process
from crewai_tools import MCPServerAdapter
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType
# Initialize clients
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
# Initialize MCP tools for each server
outlook_tools = MCPServerAdapter(outlook_mcp_instance.server_params)
gmail_tools = MCPServerAdapter(gmail_mcp_instance.server_params)
google_docs_tools = MCPServerAdapter(google_docs_mcp_instance.server_params)
# Create specialized agents for each service
outlook_agent = Agent(
role="Outlook Specialist",
goal="Handle all Outlook related tasks and data processing",
backstory="You are an expert in Outlook operations and data analysis",
tools=outlook_tools,
reasoning=True,
verbose=False
)
gmail_agent = Agent(
role="Gmail Specialist",
goal="Handle all Gmail related tasks and data processing",
backstory="You are an expert in Gmail operations and data analysis",
tools=gmail_tools,
reasoning=True,
verbose=False
)
google_docs_agent = Agent(
role="Google Docs Specialist",
goal="Handle all Google Docs related tasks and data processing",
backstory="You are an expert in Google Docs operations and data analysis",
tools=google_docs_tools,
reasoning=True,
verbose=False
)
# Define collaborative tasks
research_task = Task(
description="Gather comprehensive data from all available sources",
expected_output="Raw data and initial findings from all services",
agent=outlook_agent,
markdown=True
)
# Create multi-agent crew
crew = Crew(
agents=[outlook_agent, gmail_agent, google_docs_agent],
tasks=[research_task],
verbose=False,
process=Process.sequential
)
result = crew.kickoff()// CrewAI currently only supports Python. Please use the Python example.import os
import json
from together import Together
from klavis import Klavis
from klavis.types import McpServerName, ConnectionType, ToolFormat
# Initialize clients
together_client = Together(api_key=os.getenv("TOGETHER_API_KEY"))
klavis_client = Klavis(api_key=os.getenv("KLAVIS_API_KEY"))
outlook_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.OUTLOOK,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
gmail_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GMAIL,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
google_docs_mcp_instance = klavis_client.mcp_server.create_server_instance(
server_name=McpServerName.GOOGLE_DOCS,
user_id="1234",
connection_type=ConnectionType.STREAMABLE_HTTP,
)
# Get all MCP tools
outlook_tools = klavis_client.mcp_server.list_tools(
server_url=outlook_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
gmail_tools = klavis_client.mcp_server.list_tools(
server_url=gmail_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
google_docs_tools = klavis_client.mcp_server.list_tools(
server_url=google_docs_mcp_instance.server_url,
connection_type=ConnectionType.STREAMABLE_HTTP,
format=ToolFormat.OPENAI,
)
# Combine all tools
all_tools = []
all_tools.extend(outlook_tools.tools)
all_tools.extend(gmail_tools.tools)
all_tools.extend(google_docs_tools.tools)
messages = [
{"role": "system", "content": "You are a helpful AI assistant with access to multiple data sources."},
{"role": "user", "content": user_message}
]
response = together_client.chat.completions.create(
model="meta-llama/Llama-2-70b-chat-hf",
messages=messages,
tools=all_tools
)import Together from 'together-ai';
import { KlavisClient, Klavis } from 'klavis';
// Initialize clients
const togetherClient = new Together({ apiKey: process.env.TOGETHER_API_KEY });
const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });
const outlookMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Outlook,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const gmailMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.Gmail,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
const google_docsMcpInstance = await klavisClient.mcpServer.createServerInstance({
serverName: Klavis.McpServerName.GoogleDocs,
userId: "1234",
connectionType: Klavis.ConnectionType.StreamableHttp,
});
// Get all MCP tools
const outlookTools = await klavisClient.mcpServer.listTools({
serverUrl: outlookMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Openai,
});
const gmailTools = await klavisClient.mcpServer.listTools({
serverUrl: gmailMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Openai,
});
const google_docsTools = await klavisClient.mcpServer.listTools({
serverUrl: google_docsMcpInstance.serverUrl,
connectionType: Klavis.ConnectionType.StreamableHttp,
format: Klavis.ToolFormat.Openai,
});
// Combine all tools
const allTools = [
...outlookTools.tools,
...gmailTools.tools,
...google_docsTools.tools
];
const response = await togetherClient.chat.completions.create({
model: "meta-llama/Llama-2-70b-chat-hf",
messages: [
{ role: "system", content: "You are a helpful AI assistant with access to multiple data sources." },
{ role: "user", content: userMessage }
],
tools: allTools,
});Everything you need to know about connecting to these MCP servers
Join developers who are already using KlavisAI to power their AI agents and AI applications with these MCP servers.
Start For Free