This tutorial demonstrates how to integrate LangChain’s agent framework with Strata MCP servers to build AI agents that can interact with Gmail and Slack.
import { config } from 'dotenv';// Load environment variables from .env fileconfig();// Make sure you have a .env file with:// OPENAI_API_KEY=your_openai_api_key// KLAVIS_API_KEY=your_klavis_api_key
Step 1 - Create Strata MCP Server with Gmail and Slack
from klavis import Klavisfrom klavis.types import McpServerName, ToolFormatimport webbrowserklavis_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 servicesif 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}")
import { KlavisClient, Klavis } from 'klavis';import open from 'open';import { createInterface } from 'readline/promises';const klavisClient = new KlavisClient({ apiKey: process.env.KLAVIS_API_KEY });const response = await klavisClient.mcpServer.createStrataServer({ servers: [Klavis.McpServerName.Gmail, Klavis.McpServerName.Slack], userId: "1234"});// Handle OAuth authorization for each serviceif (response.oauthUrls) { const rl = createInterface({ input: process.stdin, output: process.stdout, }); for (const [serverName, oauthUrl] of Object.entries(response.oauthUrls)) { await open(oauthUrl); await rl.question(`Press Enter after completing ${serverName} OAuth authorization...`); } rl.close();}
OAuth Authorization Required: The code above will open browser windows for each service. Click through the OAuth flow to authorize access to your accounts.
response_message = asyncio.run(agent.ainvoke({ "messages": [{"role": "user", "content": "Check my latest 5 emails and summarize them in a Slack message to #general"}]}))print(f"\n🤖 Final Response: {response_message['messages'][-1].content}")
const result = await agent.invoke({ messages: [{ role: 'user' as const, content: 'Check my latest 5 emails and summarize them in a Slack message to #general' }]});// Print only the final AI response contentconst lastMessage = result.messages[result.messages.length - 1];console.log('\n🤖 Final Response:', lastMessage.content);