How to integrate Google Drive MCP with Autogen

Connect Autogen to Google Drive MCP. Create a new folder named 'invoices', share last uploaded file with your team, and more using natural language, with authentication handled for you.

Google Drive logoGoogle Drive
Oauth2

Google Drive is a cloud storage platform for uploading, sharing, and collaborating on files. It's perfect for keeping your documents accessible and organized across devices.

92 Tools7 Triggers

Introduction

This guide walks you through connecting Google Drive to AutoGen using the Composio tool router. By the end, you'll have a working Google Drive agent that can upload and download files, organize folders, share files and set permissions, manage comments, and search your Drive through natural language commands.

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

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

Also integrate Google Drive with

TL;DR

Here's what you'll learn:
  • Get and set up your OpenAI and Composio API keys
  • Install the required dependencies for Autogen and Composio
  • Initialize Composio and create a Tool Router session for Google Drive
  • Wire that MCP URL into Autogen using McpWorkbench and StreamableHttpServerParams
  • Configure an Autogen AssistantAgent that can call Google Drive tools
  • Run a live chat loop where you ask the agent to perform Google Drive operations

What is AutoGen?

Autogen is a framework for building multi-agent conversational AI systems from Microsoft. It enables you to create agents that can collaborate, use tools, and maintain complex workflows.

Key features include:

  • Multi-Agent Systems: Build collaborative agent workflows
  • MCP Workbench: Native support for Model Context Protocol tools
  • Streaming HTTP: Connect to external services through streamable HTTP
  • AssistantAgent: Pre-built agent class for tool-using assistants

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

The Google Drive MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Google Drive account. It provides structured and secure access to your files, folders, comments, permissions, and shared drives, so your agent can search, create, download, share, and organize content on your behalf.

  • File and folder management: Have your agent find files, create files and folders, inspect file details, add shortcuts, and download stored content.
  • Workspace file exports and spreadsheet reads: Let the agent export Google Workspace files to supported formats or read multiple ranges from a Google Spreadsheet.
  • Sharing and permission control: Direct your agent to view, add, or remove access permissions for files and shared drives.
  • Comments and collaboration: Instruct your agent to list and create file comments, reply to existing comments, or remove comments and replies.
  • Shared drives and file history: Have your agent list, create, inspect, hide, or delete shared drives, and review or download file revisions.

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

Step by step08 STEPS
1

Prerequisites

You will need:

  • A Composio API key
  • An OpenAI API key (used by Autogen's OpenAIChatCompletionClient)
  • A Google Drive account you can connect to Composio
  • Some basic familiarity with Autogen and Python async
2

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.
3

Install dependencies

bash
pip install composio python-dotenv
pip install autogen-agentchat autogen-ext-openai autogen-ext-tools

Install Composio, Autogen extensions, and dotenv.

What's happening:

  • composio connects your agent to Google Drive via MCP
  • autogen-agentchat provides the AssistantAgent class
  • autogen-ext-openai provides the OpenAI model client
  • autogen-ext-tools provides MCP workbench support

4

Set up environment variables

bash
COMPOSIO_API_KEY=your-composio-api-key
OPENAI_API_KEY=your-openai-api-key
USER_ID=your-user-identifier@example.com

Create a .env file in your project folder.

What's happening:

  • COMPOSIO_API_KEY is required to talk to Composio
  • OPENAI_API_KEY is used by Autogen's OpenAI client
  • USER_ID is how Composio identifies which user's Google Drive connections to use
5

Import dependencies and create Tool Router session

python
import asyncio
import os
from dotenv import load_dotenv
from composio import Composio

from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import McpWorkbench, StreamableHttpServerParams

load_dotenv()

async def main():
    # Initialize Composio and create a Google Drive session
    composio = Composio(api_key=os.getenv("COMPOSIO_API_KEY"))
    session = composio.create(
        user_id=os.getenv("USER_ID"),
        toolkits=["googledrive"]
    )
    url = session.mcp.url
What's happening:
  • load_dotenv() reads your .env file
  • Composio(api_key=...) initializes the SDK
  • create(...) creates a Tool Router session that exposes Google Drive tools
  • session.mcp.url is the MCP endpoint that Autogen will connect to
6

Configure MCP parameters for Autogen

python
# Configure MCP server parameters for Streamable HTTP
server_params = StreamableHttpServerParams(
    url=url,
    timeout=30.0,
    sse_read_timeout=300.0,
    terminate_on_close=True,
    headers={"x-api-key": os.getenv("COMPOSIO_API_KEY")}
)

Autogen expects parameters describing how to talk to the MCP server. That is what StreamableHttpServerParams is for.

What's happening:

  • url points to the Tool Router MCP endpoint from Composio
  • timeout is the HTTP timeout for requests
  • sse_read_timeout controls how long to wait when streaming responses
  • terminate_on_close=True cleans up the MCP server process when the workbench is closed
7

Create the model client and agent

python
# Create model client
model_client = OpenAIChatCompletionClient(
    model="gpt-5",
    api_key=os.getenv("OPENAI_API_KEY")
)

# Use McpWorkbench as context manager
async with McpWorkbench(server_params) as workbench:
    # Create Google Drive assistant agent with MCP tools
    agent = AssistantAgent(
        name="googledrive_assistant",
        description="An AI assistant that helps with Google Drive operations.",
        model_client=model_client,
        workbench=workbench,
        model_client_stream=True,
        max_tool_iterations=10
    )

What's happening:

  • OpenAIChatCompletionClient wraps the OpenAI model for Autogen
  • McpWorkbench connects the agent to the MCP tools
  • AssistantAgent is configured with the Google Drive tools from the workbench
8

Run the interactive chat loop

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

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

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

    if not user_input:
        continue

    print("\nAgent is thinking...\n")

    # Run the agent with streaming
    try:
        response_text = ""
        async for message in agent.run_stream(task=user_input):
            if hasattr(message, "content") and message.content:
                response_text = message.content

        # Print the final response
        if response_text:
            print(f"Agent: {response_text}\n")
        else:
            print("Agent: I encountered an issue processing your request.\n")

    except Exception as e:
        print(f"Agent: Sorry, I encountered an error: {str(e)}\n")
What's happening:
  • The script prompts you in a loop with You:
  • Autogen passes your input to the model, which decides which Google Drive tools to call via MCP
  • agent.run_stream(...) yields streaming messages as the agent thinks and calls tools
  • Typing exit, quit, or bye ends the loop

Complete Code

Here's the complete code to get you started with Google Drive and AutoGen:

python
import asyncio
import os
from dotenv import load_dotenv
from composio import Composio

from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.tools.mcp import McpWorkbench, StreamableHttpServerParams

load_dotenv()

async def main():
    # Initialize Composio and create a Google Drive session
    composio = Composio(api_key=os.getenv("COMPOSIO_API_KEY"))
    session = composio.create(
        user_id=os.getenv("USER_ID"),
        toolkits=["googledrive"]
    )
    url = session.mcp.url

    # Configure MCP server parameters for Streamable HTTP
    server_params = StreamableHttpServerParams(
        url=url,
        timeout=30.0,
        sse_read_timeout=300.0,
        terminate_on_close=True,
        headers={"x-api-key": os.getenv("COMPOSIO_API_KEY")}
    )

    # Create model client
    model_client = OpenAIChatCompletionClient(
        model="gpt-5",
        api_key=os.getenv("OPENAI_API_KEY")
    )

    # Use McpWorkbench as context manager
    async with McpWorkbench(server_params) as workbench:
        # Create Google Drive assistant agent with MCP tools
        agent = AssistantAgent(
            name="googledrive_assistant",
            description="An AI assistant that helps with Google Drive operations.",
            model_client=model_client,
            workbench=workbench,
            model_client_stream=True,
            max_tool_iterations=10
        )

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

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

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

            if not user_input:
                continue

            print("\nAgent is thinking...\n")

            # Run the agent with streaming
            try:
                response_text = ""
                async for message in agent.run_stream(task=user_input):
                    if hasattr(message, 'content') and message.content:
                        response_text = message.content

                # Print the final response
                if response_text:
                    print(f"Agent: {response_text}\n")
                else:
                    print("Agent: I encountered an issue processing your request.\n")

            except Exception as e:
                print(f"Agent: Sorry, I encountered an error: {str(e)}\n")

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

Conclusion

You now have an Autogen assistant wired into Google Drive through Composio's Tool Router and MCP. From here you can:
  • Add more toolkits to the toolkits list, for example notion or hubspot
  • Refine the agent description to point it at specific workflows
  • Wrap this script behind a UI, Slack bot, or internal tool
Once the pattern is clear for Google Drive, you can reuse the same structure for other MCP-enabled apps with minimal code changes.
TOOLS & TRIGGERS

Supported Tools and Triggers

Every Google Drive action and event your agent gets out of the box.

Insert File Parent (v2)

Tool to add a parent folder for a file using Google Drive API v2.

Insert Property (v2 API)

Tool to add a property to a file, or update it if it already exists (v2 API).

Batch Get Spreadsheet Values

Read multiple explicit ranges from one Google Spreadsheet in one request.

Batch Update Spreadsheet Values

Write values to multiple Google Sheets ranges in one batch request.

Clear Spreadsheet Values

Permanently clear values from one range while preserving formatting, notes, and validation.

Copy file with advanced options

Creates a copy of a file and applies any requested updates with patch semantics.

Create Comment

Tool to create a comment on a file in Google Drive.

Create Shared Drive

Creates a Google shared drive for collaboration or storage.

Create File or Folder

Creates a new file or folder in Google Drive.

Create a File from Text

Creates a Google Drive file from text, with support for Google Workspace formats and an optional parent folder.

Create a folder

Creates a Google Drive folder, optionally inside an existing parent specified by ID or exact name.

Create Permission

Tool to create a permission for a file or shared drive.

Create Permissions Batch

Creates multiple permissions for files or shared drives in a single batch request.

Create Reply

Create a plain-text reply to a comment on a Google Drive file, optionally resolving or reopening the parent comment.

Create Shortcut to File/Folder

Tool to create a shortcut to a file or folder in Google Drive.

Delete Child (v2)

Tool to remove a child from a folder using Google Drive API v2.

Delete Comment

Permanently deletes a comment thread (and all its replies) from a Google Drive file — this action is irreversible.

Delete Shared Drive

Tool to permanently delete a shared drive.

Delete Parent (v2)

Tool to remove a parent from a file using Google Drive API v2.

Delete Permission

Deletes a specified permission from a file or shared drive by permission ID; deleting other permissions does not remove an existing public-access permission.

Delete Property (v2 API)

Delete a custom property from a Google Drive file using API v2.

Delete Reply

Tool to delete a specific reply by reply ID.

Delete Revision

Tool to permanently delete a file revision.

Download a file from Google Drive

Downloads a Drive file's content and returns it in `downloaded_file_content`.

Download file via operation

Starts a long-running operation to download a Drive file, including Google Vids files, or export supported Google Workspace documents.

Download File Revision

Download the stored bytes of one blob-file revision.

Edit File

Replaces the entire content of an existing Google Drive binary file with UTF-8 text while retaining its file ID.

Empty Trash

Tool to permanently and irreversibly delete ALL trashed files in the user's Google Drive or a specified shared drive.

Export Google Workspace file

Exports a Google Workspace document to the requested MIME type and returns exported file content.

Find file

The comprehensive Google Drive search tool that handles all file and folder discovery needs.

Find folder

Finds one page of Google Drive folders by name and optional parent.

Generate File IDs

Generates a set of file IDs which can be provided in create or copy requests.

Get about

Tool to retrieve information about the user, the user's Drive, and system capabilities.

Get App

Tool to get information about a specific Drive app by ID.

Get Changes Start Page Token

Tool to get the starting pageToken for listing future changes in Google Drive.

Get Child Reference (v2)

Tool to get a specific child reference for a folder using Drive API v2.

Get Comment

Tool to get a comment by ID.

Get Document

Retrieve a native Google Docs document's structured content and metadata by ID.

Get Shared Drive

Tool to get a shared drive by ID.

Get File Metadata

Gets a Drive file's metadata by ID, optionally returning only the metadata selected by `fields`.

Get Property (v2)

Tool to get a property by its key using Google Drive API v2.

Get Google Form

Retrieve a Google Form's definition, questions, settings, and publishing state by ID.

Get Parent Reference (v2)

Tool to get a specific parent reference for a file using Drive API v2.

Get Permission

Gets a permission by ID.

Get Permission ID for Email

Tool to get the permission ID for an email address using the Drive API v2.

Get Google Slides Presentation

Retrieves a Google Slides presentation by ID, including its page structures.

Get Presentation Page Thumbnail

Generate one short-lived page thumbnail URL using an expensive Slides quota read.

Get Reply

Tool to get a specific reply to a comment on a file.

Get Revision

Tool to get a specific revision's metadata (name, modifiedTime, keepForever, etc.

Get Spreadsheet

Retrieve a Google Spreadsheet's structure, metadata, and selected grid data.

Get Spreadsheet Values

Read values from one range in a Google Spreadsheet.

Delete folder or file

Tool to delete a file or folder in Google Drive.

Hide Shared Drive

Tool to hide a shared drive from the default view.

Insert Child Into Folder (v2)

Tool to insert a file into a folder using Drive API v2.

List Access Proposals

Tool to list pending access proposals on a file.

List Approvals

Lists a page of approvals associated with a Google Drive file, with pagination for browsing subsequent pages.

List Changes

Lists a page of changes for a user or shared drive; without a page token, it obtains a current start token and lists subsequent changes rather than earlier activity.

List Folder Children (v2)

Lists a page of child references for a folder using Google Drive API v2.

List Comments

Lists comments on a Google Drive file, with pagination, an option to include deleted comments, and a minimum modification-time filter.

List File Labels

Lists labels applied to a Google Drive file, including label IDs and applied field IDs.

List Properties (v2 API)

Tool to list a file's properties in Google Drive API v2.

List Google Form Responses

Return one page of submissions for a Google Form.

List Label Definitions

Lists available Google Drive labels, returning each label's ID and display name without requiring a file ID.

List Permissions

Lists a page of permissions for a file or shared drive.

List Replies to Comment

List a page of replies to a specific comment on a Google Drive file.

List File Revisions

Tool to list a file's revision metadata (not content) in Google Drive.

List Shared Drives

Tool to list the user's shared drives.

Modify File Labels

Modifies the set of labels applied to a file.

Move File

Moves a file to another Google Drive folder.

Patch Permission

Tool to update a permission using patch semantics.

Patch Property (v2 API)

Tool to update a property on a file using PATCH semantics (v2 API).

Read Spreadsheet Values

Read values from one or more ranges in a Google spreadsheet.

Resumable Upload

Upload a file to Google Drive using a resumable session, creating a new file or updating an existing file by ID.

Stop Watch Channel

Tool to stop watching resources through a specified channel.

Trash File

Tool to move a file or folder to trash (soft delete).

Unhide Shared Drive

Tool to unhide a shared drive.

Untrash File

Restore a file from Google Drive trash.

Update Comment

Tool to update an existing comment on a Google Drive file.

Update Shared Drive

Tool to update the metadata for a shared drive.

Update File Metadata (PATCH v2)

Tool to update file metadata using the Drive API v2 PATCH method.

Update Property (v2 API)

Tool to update a property on a file using Google Drive API v2.

Update File (Metadata)

Updates file metadata.

Update File Revision Metadata

Updates ONLY the metadata properties of a specific file revision (keepForever, published, publishAuto, publishedOutsideDomain).

Update Permission

Tool to update a permission with patch semantics.

Update Reply

Tool to update a reply to a comment on a Google Drive file.

Update Spreadsheet Values

Write values to one exact Google Sheets range.

Upload File

Upload a new file to Google Drive, optionally placing it in a specified folder.

Upload File from URL to Drive

Tool to fetch a file from a provided URL server-side and upload it into Google Drive.

Upload/Update File Content

Tool to update file content in Google Drive by uploading new binary content.

Watch Drive Changes

Subscribe to Google Drive changes for a user or shared drive and receive notifications at a webhook URL.

Watch File for Changes

Tool to subscribe to push notifications for changes to a specific file.

Write Spreadsheet Values

Replace values in one range of a Google spreadsheet.

FAQ

Frequently asked questions

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

Yes, you can. Autogen 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 Google Drive tools.

Yes, absolutely. You can configure which Google Drive 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.

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 Google Drive data and credentials are handled as safely as possible.

Start with Google Drive.It takes 30 seconds.

Managed auth, hosted MCP servers, and every Google Drive tool your agent needs.Free to start.

Start building