How to integrate Outlook MCP with LangChain

Trusted by
AWS
Glean
Zoom
Airtable

30 min · no commitment · see it on your stack

Outlook logo
LangChain logo
divider

Introduction

This guide walks you through connecting Outlook to LangChain using the Composio tool router. By the end, you'll have a working Outlook agent that can download latest attachments from your inbox, create new calendar for project deadlines, add rule to move newsletters to folder through natural language commands.

This guide will help you understand how to give your LangChain agent real control over a Outlook account through Composio's Outlook MCP server.

Before we dive in, let's take a quick look at the key ideas and tools involved.

Also integrate Outlook with

TL;DR

Here's what you'll learn:
  • Get and set up your OpenAI and Composio API keys
  • Connect your Outlook project to Composio
  • Create a Tool Router MCP session for Outlook
  • Initialize an MCP client and retrieve Outlook tools
  • Build a LangChain agent that can interact with Outlook
  • Set up an interactive chat interface for testing

What is LangChain?

LangChain is a framework for developing applications powered by language models. It provides tools and abstractions for building agents that can reason, use tools, and maintain conversation context.

Key features include:

  • Agent Framework: Build agents that can use tools and make decisions
  • MCP Integration: Connect to external services through Model Context Protocol adapters
  • Memory Management: Maintain conversation history across interactions
  • Multi-Provider Support: Works with OpenAI, Anthropic, and other LLM providers

What is the Outlook MCP server, and what's possible with it?

The Outlook MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Outlook account. It provides structured and secure access to your email, calendar, and contacts, so your agent can perform actions like sending emails, organizing folders, managing your calendar, and handling attachments on your behalf.

  • Email organization and folder management: Let your agent create, delete, or organize mail folders to keep your inbox tidy and efficient.
  • Calendar and event creation: Easily have your agent set up new calendars, so you can organize meetings and events without lifting a finger.
  • Smart attachments handling: Automatically download files from your emails or add attachments to outgoing messages for seamless file management.
  • Automated rules and filtering: Direct your agent to create email rules that filter, sort, or take action on messages as they arrive.
  • Contact and category organization: Ask your agent to create new contact folders or master categories to streamline how you manage people and projects.

Supported Tools & Triggers

Tools
Triggers
Accept calendar event inviteAccepts or tentatively accepts a calendar meeting invite on behalf of a user.
Add event attachmentAdds an attachment to a specific Outlook calendar event.
Add mail attachmentTool to add an attachment to an email message.
Batch move messagesBatch-move up to 20 Outlook messages to a destination folder in a single Microsoft Graph $batch call.
Batch update messagesBatch-update up to 20 Outlook messages per call using Microsoft Graph JSON batching.
Create Calendar EventCreates a new Outlook calendar event, ensuring `start_datetime` is chronologically before `end_datetime`.
Cancel user's calendar eventTool to cancel an event in a specific calendar for a specified user and send cancellation notifications to all attendees.
Cancel user calendar group eventTool to cancel an event in a user's calendar within a calendar group and send cancellation notifications to all attendees.
Cancel user calendar eventTool to cancel a calendar event for a specified user and send cancellation notifications to all attendees.
Copy user's mail folderTool to copy a user's mail folder and its contents to another folder.
Copy child mail folderTool to copy a child mail folder to a destination folder.
Copy message to folderTool to copy an email message to another folder within the user's mailbox.
Copy message from child folderTool to copy an email message from a child folder (nested folder) to another folder within the user's mailbox.
Copy user message from folderTool to copy a message from a specific user's mail folder to another folder.
Create attachment upload sessionTool to create an upload session for large (>3 MB) message attachments.
Create attachment upload session in child folderTool to create an upload session for large (>3 MB) message attachments in child mail folders.
Create calendarTool to create a new calendar in the signed-in user's mailbox.
Create calendar event attachmentTool to create a new attachment for an event in a specific calendar.
Create calendar event attachment upload sessionTool to create an upload session for large calendar event attachments in a specific calendar.
Create event in specific calendarTool to create a new event in a specific calendar for a user.
Create calendar groupTool to create a new calendar group for a user.
Create user calendar group event attachmentTool to create a new attachment for an event in a calendar within a calendar group for a specific user.
Create event extensionTool to create a new open extension on a calendar event within a specific calendar group and calendar.
Create Calendar PermissionTool to create a calendar permission for a specific calendar in a calendar group.
Create calendar group event attachment upload sessionTool to create an upload session for large calendar group event attachments.
Create contactCreates a new contact in a Microsoft Outlook user's contacts folder.
Create contact folderTool to create a new contact folder in the user's mailbox.
Create user contact folder child folderTool to create a child contact folder within a parent contact folder for a specific user.
Create email draftCreates a new Outlook email draft with subject, body, recipients, and an optional attachment.
Create a draft replyCreates a draft reply in the specified user's Outlook mailbox to an existing message (identified by a valid `message_id`), optionally including a `comment` and CC/BCC recipients.
Create Email RuleCreate email rule filter with conditions and actions
Create user calendar event attachmentTool to create a new attachment for a user's calendar event.
Create event attachment upload sessionTool to create an upload session for large calendar event attachments.
Create user mail folder message forward draftTool to create a forward draft of an Outlook message for a specific user.
Create mail folderTool to create a new mail folder.
Create message in mail folderTool to create a new message in a specific mail folder.
Create mail folder message attachmentTool to add an attachment to a message in a specific mail folder.
Create mail folder message attachment upload sessionTool to create an upload session for large (>3 MB) message attachments in a specific mail folder.
Create User Mail Folder Message RuleTool to create a message rule in a user's mail folder.
Create user calendar event extensionTool to create a new open extension on a calendar event for a specific user.
Create user calendar permissionTool to create a new calendar permission for a specific user's calendar.
Create message in user's child folderTool to create a new draft message in a child folder within a user's mail folder.
Create user contact in folderTool to create a new contact in a specific user's contact folder.
Create user contact extensionTool to create a new open extension on a contact within a user's contact folder.
Create contact extensionTool to create a new open extension on a contact within a child folder.
Create contact in child folderTool to create a new contact in a child folder within a contact folder.
Create calendar event for userTool to create a new calendar event for a specific user.
Create me event attachment upload sessionTool to create an upload session for large event attachments.
Create forward draftTool to create a draft forward of an existing message.
Create user Focused Inbox overrideTool to create a Focused Inbox override for a sender identified by SMTP address for a specific user.
Create reply-all draft for user messageTool to create a draft reply-all to a user's message.
Create reply-all draft for child folder messageTool to create a draft reply-all to a message in a child folder.
Create message attachmentTool to create an attachment for a message.
Create reply-all draft in folderTool to create a reply-all draft for a message in a mail folder.
Create To Do taskTool to create a new task in Microsoft To Do within a specified task list.
Create user calendar event attachmentTool to create a new attachment for an event in a specific user's calendar.
Create calendar in user's calendar groupTool to create a new calendar in a calendar group for a specific user.
Create user calendar group eventTool to create a new calendar event in a specific user's calendar within a calendar group.
Create user contact extensionTool to create a new open extension on a specific user's contact.
Create calendar permission via eventTool to create a calendar permission via an event's calendar.
Create user message extensionTool to create a new open extension on a message in a child mail folder for any user.
Create user mail folder message extensionTool to create a new open extension on a message in a user's mail folder.
Create reply draft for user mail folder messageTool to create a reply draft for a message in a user's mail folder.
Create user mail folders child foldersTool to create a new child folder under a specified mail folder for a user.
Create user master categoryTool to create a new category in a user's master category list.
Create user messageTool to create a new draft message in a user's mailbox.
Create user message attachmentTool to create an attachment on a message in a user's mail folder.
Decline calendar eventTool to decline an invitation to a calendar event.
Delete calendarTool to delete a calendar other than the default calendar from a user's mailbox.
Delete calendar eventTool to delete a calendar event from a user's Outlook calendar.
Delete user calendar event attachmentDelete user calendar event attachment
Delete event from specific calendarTool to delete an event from a specific calendar in Outlook.
Delete user calendar group calendarTool to delete a calendar from a specific user's calendar group in Microsoft Outlook.
Delete calendar groupTool to delete a calendar group other than the default calendar group.
Delete user calendar group calendar eventTool to delete a calendar event from a specific user's calendar within a calendar group.
Delete calendar group event attachmentTool to delete an attachment from an event in a calendar within a calendar group.
Permanently Delete Calendar Group EventTool to permanently delete a calendar event from a calendar within a calendar group.
Permanently Delete CalendarPermanently deletes a calendar from a user's mailbox.
Delete User Calendar Group Calendar PermissionTool to delete a calendar permission from a user's calendar within a calendar group.
Permanently Delete Child Contact FolderPermanently deletes a child contact folder.
Delete Child Folder MessageTool to delete a message from a child mail folder in Outlook.
Delete ContactPermanently deletes an existing contact, using its `contact_id` (obtainable via 'List User Contacts' or 'Get Contact'), from the Outlook contacts of the user specified by `user_id`.
Delete contact folderTool to delete a contact folder from the user's mailbox.
Delete user contact folder child folderTool to delete a child contact folder from a parent contact folder for a specific user.
Delete Contact from FolderTool to permanently delete a contact from a specific contact folder.
Permanently Delete Contact FolderPermanently deletes a contact folder.
Permanently Delete User Contact from Child FolderTool to permanently delete a contact from a child folder for a specific user.
Permanently Delete Contact from FolderPermanently deletes a contact from a specific contact folder.
Permanently Delete ContactPermanently deletes a contact.
Delete contact extensionTool to delete a navigation property extension from a contact within a child folder.
Delete Email RuleDelete an email rule permanently; deletion is irreversible.
Delete event attachmentTool to delete an attachment from an Outlook calendar event.
Delete event extensionTool to delete an open extension from a calendar event in a calendar group.
Permanently Delete EventPermanently deletes a calendar event.
Delete mail folderDelete a mail folder from the user's mailbox.
Delete Mail Folder MessageTool to delete a message from a specific mail folder in Outlook.
Delete master categoryTool to delete a category from the user's master category list.
Delete User Calendars Calendar PermissionTool to delete a calendar permission from a specific user's calendar.
Delete contact extensionTool to delete an open extension from a contact.
Delete user contact folder contact extensionTool to delete an extension from a contact in a user's contact folder.
Delete user event extensionTool to delete an open extension from a user's calendar event.
Delete user event attachmentTool to delete an attachment from a user's Outlook event.
Delete inference classification overrideTool to delete an inference classification override for a specific sender.
Delete mail folder child folderTool to delete a child mail folder from a parent mail folder.
Permanently Delete Child Mail FolderPermanently deletes a child mail folder from a parent mail folder.
Delete mail folder message ruleTool to delete a message rule from a specific mail folder.
Delete user message extensionDelete user message extension
Delete message extensionTool to delete a navigation property extension from a message within a mail folder.
Delete Message AttachmentTool to delete an attachment from a message.
Delete MessageTool to permanently delete an Outlook email message by its message_id.
Delete Message AttachmentTool to delete an attachment from a message in a nested mail folder structure.
Delete message extensionTool to delete an open extension from an Outlook message.
Delete User Calendar PermissionTool to delete a calendar permission from a specific user's calendar.
Permanently Delete User Calendar EventTool to permanently delete a calendar event from a specific user's calendar.
Delete Contact from User's Child FolderTool to delete a contact from a child folder in a user's contact folder.
Delete User Child Folder Message PermanentlyTool to permanently delete a message from a user's child mail folder in Outlook.
Permanently Delete User EventTool to permanently delete a calendar event for a specified user.
Permanently Delete User Mail FolderPermanently deletes a mail folder for a specific user.
Dismiss user calendar event reminderTool to dismiss a reminder for a specific event in a user's calendar.
Dismiss event reminderTool to dismiss a reminder for a specific calendar event.
Dismiss user calendar group event reminderTool to dismiss a reminder for an event in a user's calendar within a calendar group.
Dismiss user event reminderTool to dismiss a reminder for a specific user's calendar event.
Download Outlook attachmentDownloads a specific file attachment from an email message in a Microsoft Outlook mailbox; the attachment must contain 'contentBytes' (binary data) and not be a link or embedded item.
Find Meeting TimesSuggests meeting times based on organizer and attendee availability, time constraints, and duration requirements.
Forward messageTool to forward a message.
Forward user calendar eventTool to forward a calendar event from a specific user's calendar to new recipients.
Get event from calendarTool to retrieve a specific event from a specified calendar.
Get calendar event attachmentTool to retrieve a specific attachment from an event within a calendar.
Get calendar from eventTool to retrieve the parent calendar that contains a specific event.
Get calendar from calendar groupTool to retrieve a specific calendar from a calendar group in Microsoft Outlook.
Get calendar groupTool to retrieve the properties and relationships of a calendar group object.
Get event extensionTool to retrieve an open extension from a calendar event within a specific calendar group and calendar.
Get User Calendar Group ScheduleTool to retrieve free/busy schedule information for a specific user's calendar within a calendar group.
Get user calendar permissionTool to retrieve a specific calendar permission for a user's calendar.
Get user calendar permissionTool to retrieve a specific calendar permission from a user's calendar.
Get Calendar ScheduleTool to get free/busy schedule information for users, distribution lists, or resources.
Get Calendar ViewGet events ACTIVE during a time window (includes multi-day events).
Get child folder messageTool to retrieve a specific email message from a child mail folder.
Get child folder message MIME contentTool to get the MIME content of a message from a child mail folder.
Get child mail folderTool to retrieve a specific child mail folder from a parent mail folder.
Get contact extensionTool to retrieve an open extension from a contact in Microsoft Graph.
Get contact folderTool to retrieve a specific contact folder by ID.
List user contact foldersTool to retrieve contact folders from a specific user's mailbox.
Get contact from folderTool to retrieve a specific contact from a contact folder by its ID.
Get drafts mail folderTool to get the drafts mail folder.
Get calendar eventRetrieves the full details of a specific calendar event by its ID from a user's Outlook calendar, provided the event exists.
Get event attachmentTool to retrieve a specific attachment from an Outlook calendar event by attachment ID.
Get event calendar from calendar groupTool to retrieve the calendar that contains a specific event within a calendar group.
Get inference classificationTool to get inference classification settings for the authenticated user.
Get mailbox settingsTool to retrieve mailbox settings.
Get mail deltaRetrieve incremental changes (delta) of messages in a mailbox.
Get mail folderTool to retrieve a mail folder by ID or well-known name.
Get mail folder messageTool to retrieve a specific message from a mail folder by its ID.
Get user mail folder message ruleTool to retrieve a specific message rule from a user's mail folder.
Get mail tipsTool to retrieve mail tips such as automatic replies and mailbox full status.
Get master categoriesTool to retrieve the user's master category list.
Get master categoryTool to retrieve properties of a specific category from the user's master category list.
Get user's default calendarTool to get the properties and relationships of the signed-in user's default calendar.
Get user child contact folderTool to retrieve a specific child contact folder for a user by ID.
Get contact from child folderTool to retrieve a specific contact from a nested child folder within a contact folder.
Get contact photoTool to get the binary media content of a contact's profile photo.
Get contactRetrieves a specific Outlook contact by its `contact_id` from the contacts of a specified `user_id` (defaults to 'me' for the authenticated user).
Get user contact extensionTool to retrieve a specific open extension from a user's contact.
Get user event attachmentTool to retrieve a specific attachment from a user's calendar event.
Get event calendarTool to retrieve the calendar that contains a specific event.
Get message extensionTool to retrieve a specific extension from a message in a user's mailbox.
Get message MIME contentTool to get the MIME content of a message.
Get user outlookTool to retrieve the outlookUser object for a specified user.
Get email messageRetrieves a specific email message by its ID from the specified user's Outlook mailbox.
Get user message extensionTool to retrieve a specific extension from a user's message.
Get attachment from nested folder messageTool to retrieve a specific attachment from a message located in a nested mail folder structure.
Get Outlook profileRetrieves the Microsoft Outlook profile for a specified user.
Get scheduleRetrieves free/busy schedule information for specified email addresses within a defined time window.
Get supported languagesTool to retrieve supported languages in the user's mailbox.
Get supported time zonesTool to get the list of time zones supported for a user as configured on their mailbox server.
Get user's calendarTool to get the properties and relationships of a specific calendar for a user.
Get allowed calendar sharing roles for user calendarTool to retrieve allowed calendar sharing roles for a specific user on a given calendar.
Get user calendar eventTool to retrieve a specific calendar event from a user's primary calendar.
Get user calendar group calendar permissionTool to retrieve a specific calendar permission for a user's calendar within a calendar group.
Get user calendar group eventTool to retrieve a specific event from a user's calendar within a calendar group.
Get user calendar group event attachmentTool to retrieve a specific attachment from an event within a calendar group for a user.
Get message from child folderTool to retrieve a specific message from a child folder within a user's mail folder hierarchy.
Get event extensionTool to retrieve a specific open type extension from a user's calendar event by its extension ID or name.
Get user message attachmentTool to retrieve a specific attachment from a message in a mail folder hierarchy.
List user calendar event attachmentsTool to list attachments for a calendar event within a specific calendar for a user.
List user calendar group calendar eventsTool to list events from a specific calendar within a calendar group for a user.
List calendars in calendar groupTool to retrieve calendars belonging to a specific calendar group.
List user calendar group event attachmentsTool to list attachments for a calendar event within a specific calendar group for a user.
List Outlook calendar groupsTool to list calendar groups in the signed-in user's mailbox.
List calendar permissionsTool to list calendar permissions for a specific calendar within a calendar group.
List Outlook calendarsTool to list calendars in the signed-in user's mailbox.
List calendar view deltaTool to get calendar events that have been added, deleted, or updated in a calendar view.
List chat messagesTool to list messages in a Teams chat.
List Teams chatsTool to list Teams chats.
List user child folder contactsTool to retrieve contacts from a user's child contact folder.
List child folder messagesTool to list messages from a child folder within a parent mail folder.
List child mail foldersTool to list subfolders (childFolders) under a specified Outlook mail folder.
List contact folder child foldersTool to list child folders under a specified contact folder.
List contact folders deltaTool to get contact folders that have been added, deleted, or updated.
List contacts deltaRetrieve incremental changes (delta) of contacts in a specified folder.
List Email RulesList all email rules from inbox.
List event attachmentsTool to list attachments for a specific Outlook calendar event.
List event calendar permissionsTool to list calendar permissions for the calendar containing a specific event.
List event instancesTool to retrieve individual occurrences of a recurring calendar event within a specified time range.
List eventsRetrieves events from a user's Outlook calendar via Microsoft Graph API.
List Inference Classification OverridesTool to list inference classification overrides that control Focused Inbox sender rules.
List mail folder message attachmentsTool to get attachments from a message in a specific mail folder.
List mail folder message rulesTool to list message rules for a specific mail folder.
List mail folder messagesTool to list messages from a specific mail folder including subfolders.
List mail foldersTool to list a user's top-level mail folders.
List mail folders deltaTool to get incremental changes to mail folders.
List user calendar permissionsTool to list calendar permissions for a specific user's calendar.
List message attachments from child folderTool to list attachments from a message in a nested child mail folder.
List MessagesRetrieves a list of email messages from a specified mail folder in an Outlook mailbox, with options for filtering (including by conversationId to get all messages in a thread), pagination, and sorting; ensure 'user_id' and 'folder' are valid, and all date/time strings are in ISO 8601 format.
List Outlook attachmentsLists metadata (name, size, contentType, isInline — but not `contentBytes`) for all attachments of a specified Outlook email message.
List placesRetrieves a collection of place objects defined in a tenant by type.
List primary calendar permissionsTool to list calendar permissions from a user's primary calendar.
List event remindersTool to retrieve reminders for events occurring within a specified time range.
List sent items messagesTool to list all messages in the SentItems mail folder of the signed-in user's mailbox.
List To Do task listsTool to list Microsoft To Do task lists for the signed-in user.
List tasks from a To Do listTool to list tasks within a specified Microsoft To Do task list, including status and due dates.
List calendar event instancesTool to retrieve instances (occurrences) of a recurring event from a specific calendar within a date range.
List user calendar event attachmentsTool to list attachments for a user's calendar event.
List event instancesTool to list instances (occurrences) of a recurring event within a specified date range from a user's calendar in a calendar group.
Get Calendar View from User Calendar GroupTool to get calendar view from a specific calendar within a calendar group for a user.
List user calendar permissionsTool to list calendar permissions for a specific user's specific calendar.
List user calendars eventsTool to retrieve events from a specific calendar for a user.
Get calendar view from user's calendarTool to get calendar view from a specific user's calendar.
List user contactsTool to retrieve contacts from a specific user's mailbox.
List usersTool to list users in Microsoft Entra ID.
Move mail folderTool to move a mail folder and its contents to another mail folder.
Move child mail folderTool to move a child mail folder to a different parent folder.
Move message to folderMove a message to another folder within the specified user's mailbox.
Move message from child folderTool to move a message from a child folder to another destination folder.
Move message from folderTool to move a message from a specific mail folder to another destination folder.
Permanently Delete MessagePermanently deletes an Outlook message by moving it to the Purges folder in the dumpster.
Pin messageTool to pin a message in an Outlook chat.
Query EmailsQuery Outlook emails within a SINGLE folder using OData filters.
Reply to EmailSends a reply to an Outlook email message with optional HTML formatting, identified by `message_id`, allowing optional CC and BCC recipients.
Search Outlook messagesSearch Outlook messages using powerful KQL syntax.
Send draftTool to send an existing draft message.
Send emailSends an email with subject, body, recipients, and optional attachments via Microsoft Graph API.
Snooze user calendar group event reminderTool to snooze a reminder for a user's calendar event within a calendar group to a new time.
Snooze event reminderTool to postpone an event reminder until a new time.
Snooze user calendar event reminderTool to snooze a reminder for a calendar event in a specific user calendar to a new time.
Snooze user event reminderTool to snooze a reminder for a user's calendar event to a new time.
Update calendar eventUpdates specified fields of an existing Outlook calendar event.
Update event in specific calendarTool to update an event in a specific Outlook calendar.
Update calendar groupTool to update the properties of a calendar group object.
Update Calendar Group Calendar PermissionTool to update a calendar permission within a calendar group.
Update user calendar in calendar groupTool to update a calendar within a calendar group in a user's mailbox.
Update user calendar group eventTool to update an event in a calendar within a calendar group for a specific user.
Update calendar permissionTool to update calendar permission levels for share recipients or delegates.
Update child folder contactTool to update a contact in a child contact folder within a parent contact folder.
Update ContactUpdates an existing Outlook contact, identified by `contact_id` for the specified `user_id`, requiring at least one other field to be modified.
Update user contact folderTool to update the properties of a contact folder for a specific user.
Update user contact folder child folderTool to update a child folder within a contact folder for a specific user.
Update contact in folderTool to update a contact within a specific contact folder.
Update email messageUpdates specified properties of an existing email message; `message_id` must identify a valid message within the specified `user_id`'s mailbox.
Update Email RuleUpdate an existing email rule
Update event extensionTool to update an open extension on a calendar event in Microsoft Graph.
Update event extension in calendar groupTool to update an open extension on a calendar event within a calendar group.
Update Inference ClassificationTool to update the inferenceClassification resource for a user.
Update mailbox settingsTool to update mailbox settings for the signed-in user.
Update mail folderTool to update the display name of a mail folder.
Update master categoryTool to update the color of a category in the user's master category list.
Update contact extensionTool to update an open extension on a contact in a contact folder.
Update user calendarTool to update the properties of a user's calendar.
Update user calendar eventTool to update an event in a specific user's calendar.
Update user calendar permissionTool to update calendar permission levels for a specific user's calendar.
Update user calendar by IDTool to update properties of a specific calendar by ID for a specific user.
Update user child folder messageTool to update a message in a child folder within a user's mailbox.
Update user contact extensionTool to update an open extension on a contact in a user's contact folder.
Update user contact extensionTool to update an open extension on a contact in a user's contact folder.
Update user contact extension (v3)Tool to update an open extension on a contact directly under a user's contacts collection.
Update user events extensionsTool to update an open extension on a user's calendar event.
Update User Inference Classification OverrideTool to update the classification of messages from a specific sender in a user's Focused Inbox.
Update user mail folder messageTool to update properties of a message in a specific mail folder for a user.
Update user message extensionTool to update an open extension on a message within a specific user's mail folder.
Update user mail folder message ruleTool to update a message rule in a user's mail folder.
Update user mail folder child folderTool to update a child folder within a mail folder for a specific user.
Update user message extensionTool to update an open extension on a user's message.

What is the Composio tool router, and how does it fit here?

What is Composio SDK?

Composio's Composio SDK helps agents find the right tools for a task at runtime. You can plug in multiple toolkits (like Gmail, HubSpot, and GitHub), and the agent will identify the relevant app and action to complete multi-step workflows. This can reduce token usage and improve the reliability of tool calls. Read more here: Getting started with Composio SDK

The tool router generates a secure MCP URL that your agents can access to perform actions.

How the Composio SDK works

The Composio SDK follows a three-phase workflow:

  1. Discovery: Searches for tools matching your task and returns relevant toolkits with their details.
  2. Authentication: Checks for active connections. If missing, creates an auth config and returns a connection URL via Auth Link.
  3. Execution: Executes the action using the authenticated connection.

Step-by-step Guide

Prerequisites

Before starting this tutorial, make sure you have:
  • Python 3.10 or higher installed on your system
  • A Composio account with an API key
  • An OpenAI API key
  • Basic familiarity with Python and async programming

Getting API Keys for OpenAI and Composio

OpenAI API Key
  • Go to the OpenAI dashboard and create an API key. You'll need credits to use the models, or you can connect to another model provider.
  • Keep the API key safe.
Composio API Key
  • Log in to the Composio dashboard.
  • Navigate to your API settings and generate a new API key.
  • Store this key securely as you'll need it for authentication.

Install dependencies

pip install composio-langchain langchain-mcp-adapters langchain python-dotenv

Install the required packages for LangChain with MCP support.

What's happening:

  • composio-langchain provides Composio integration for LangChain
  • langchain-mcp-adapters enables MCP client connections
  • langchain is the core agent framework
  • python-dotenv loads environment variables

Set up environment variables

bash
COMPOSIO_API_KEY=your_composio_api_key_here
COMPOSIO_USER_ID=your_composio_user_id_here
OPENAI_API_KEY=your_openai_api_key_here

Create a .env file in your project root.

What's happening:

  • COMPOSIO_API_KEY authenticates your requests to Composio's API
  • COMPOSIO_USER_ID identifies the user for session management
  • OPENAI_API_KEY enables access to OpenAI's language models

Import dependencies

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent
from dotenv import load_dotenv
from composio import Composio
import asyncio
import os

load_dotenv()
What's happening:
  • We're importing LangChain's MCP adapter and Composio SDK
  • The dotenv import loads environment variables from your .env file
  • This setup prepares the foundation for connecting LangChain with Outlook functionality through MCP

Initialize Composio client

async def main():
    composio = Composio(api_key=os.getenv("COMPOSIO_API_KEY"))

    if not os.getenv("COMPOSIO_API_KEY"):
        raise ValueError("COMPOSIO_API_KEY is not set")
    if not os.getenv("COMPOSIO_USER_ID"):
        raise ValueError("COMPOSIO_USER_ID is not set")
What's happening:
  • We're loading the COMPOSIO_API_KEY from environment variables and validating it exists
  • Creating a Composio instance that will manage our connection to Outlook tools
  • Validating that COMPOSIO_USER_ID is also set before proceeding

Create a Tool Router session

# Create Tool Router session for Outlook
session = composio.create(
    user_id=os.getenv("COMPOSIO_USER_ID"),
    toolkits=['outlook']
)

url = session.mcp.url
What's happening:
  • We're creating a Tool Router session that gives your agent access to Outlook tools
  • The create method takes the user ID and specifies which toolkits should be available
  • The returned session.mcp.url is the MCP server URL that your agent will use
  • This approach allows the agent to dynamically load and use Outlook tools as needed

Configure the agent with the MCP URL

client = MultiServerMCPClient({
    "outlook-agent": {
        "transport": "streamable_http",
        "url": session.mcp.url,
        "headers": {
            "x-api-key": os.getenv("COMPOSIO_API_KEY")
        }
    }
})

tools = await client.get_tools()

agent = create_agent("gpt-5", tools)
What's happening:
  • We're creating a MultiServerMCPClient that connects to our Outlook MCP server via HTTP
  • The client is configured with a name and the URL from our Tool Router session
  • get_tools() retrieves all available Outlook tools that the agent can use
  • We're creating a LangChain agent using the GPT-5 model

Set up interactive chat interface

conversation_history = []

print("Chat started! Type 'exit' or 'quit' to end the conversation.\n")
print("Ask any Outlook related question or task to the agent.\n")

while True:
    user_input = input("You: ").strip()

    if user_input.lower() in ['exit', 'quit', 'bye']:
        print("\nGoodbye!")
        break

    if not user_input:
        continue

    conversation_history.append({"role": "user", "content": user_input})
    print("\nAgent is thinking...\n")

    response = await agent.ainvoke({"messages": conversation_history})
    conversation_history = response['messages']
    final_response = response['messages'][-1].content
    print(f"Agent: {final_response}\n")
What's happening:
  • We initialize an empty conversation_history list to maintain context across interactions
  • A while loop continuously accepts user input from the command line
  • When a user types a message, it's added to the conversation history and sent to the agent
  • The agent processes the request using the ainvoke() method with the full conversation history
  • Users can type 'exit', 'quit', or 'bye' to end the chat session gracefully

Run the application

if __name__ == "__main__":
    asyncio.run(main())
What's happening:
  • We call the main() function using asyncio.run() to start the application

Complete Code

Here's the complete code to get you started with Outlook and LangChain:

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent
from dotenv import load_dotenv
from composio import Composio
import asyncio
import os

load_dotenv()

async def main():
    composio = Composio(api_key=os.getenv("COMPOSIO_API_KEY"))
    
    if not os.getenv("COMPOSIO_API_KEY"):
        raise ValueError("COMPOSIO_API_KEY is not set")
    if not os.getenv("COMPOSIO_USER_ID"):
        raise ValueError("COMPOSIO_USER_ID is not set")
    
    session = composio.create(
        user_id=os.getenv("COMPOSIO_USER_ID"),
        toolkits=['outlook']
    )

    url = session.mcp.url
    
    client = MultiServerMCPClient({
        "outlook-agent": {
            "transport": "streamable_http",
            "url": url,
            "headers": {
                "x-api-key": os.getenv("COMPOSIO_API_KEY")
            }
        }
    })
    
    tools = await client.get_tools()
  
    agent = create_agent("gpt-5", tools)
    
    conversation_history = []
    
    print("Chat started! Type 'exit' or 'quit' to end the conversation.\n")
    print("Ask any Outlook related question or task to the agent.\n")
    
    while True:
        user_input = input("You: ").strip()
        
        if user_input.lower() in ['exit', 'quit', 'bye']:
            print("\nGoodbye!")
            break
        
        if not user_input:
            continue
        
        conversation_history.append({"role": "user", "content": user_input})
        print("\nAgent is thinking...\n")
        
        response = await agent.ainvoke({"messages": conversation_history})
        conversation_history = response['messages']
        final_response = response['messages'][-1].content
        print(f"Agent: {final_response}\n")

if __name__ == "__main__":
    asyncio.run(main())

Conclusion

You've successfully built a LangChain agent that can interact with Outlook through Composio's Tool Router.

Key features of this implementation:

  • Dynamic tool loading through Composio's Tool Router
  • Conversation history maintenance for context-aware responses
  • Async Python provides clean, efficient execution of agent workflows
You can extend this further by adding error handling, implementing specific business logic, or integrating additional Composio toolkits to create multi-app workflows.

How to build Outlook MCP Agent with another framework

FAQ

What are the differences in Tool Router MCP and Outlook MCP?

With a standalone Outlook MCP server, the agents and LLMs can only access a fixed set of Outlook tools tied to that server. However, with the Composio Tool Router, agents can dynamically load tools from Outlook and many other apps based on the task at hand, all through a single MCP endpoint.

Can I use Tool Router MCP with LangChain?

Yes, you can. LangChain fully supports MCP integration. You get structured tool calling, message history handling, and model orchestration while Tool Router takes care of discovering and serving the right Outlook tools.

Can I manage the permissions and scopes for Outlook while using Tool Router?

Yes, absolutely. You can configure which Outlook scopes and actions are allowed when connecting your account to Composio. You can also bring your own OAuth credentials or API configuration so you keep full control over what the agent can do.

How safe is my data with Composio Tool Router?

All sensitive data such as tokens, keys, and configuration is fully encrypted at rest and in transit. Composio is SOC 2 Type 2 compliant and follows strict security practices so your Outlook data and credentials are handled as safely as possible.

Used by agents from

Context
Letta
glean
HubSpot
Agent.ai
Altera
DataStax
Entelligence
Rolai
Context
Letta
glean
HubSpot
Agent.ai
Altera
DataStax
Entelligence
Rolai
Context
Letta
glean
HubSpot
Agent.ai
Altera
DataStax
Entelligence
Rolai

Never worry about agent reliability

We handle tool reliability, observability, and security so you never have to second-guess an agent action.