How to integrate Zoho MCP with Pydantic AI

Connect Pydantic AI to Zoho MCP. Convert new leads to contacts in crm, add a note to an existing zoho deal, and more using natural language, with authentication handled for you.

Zoho logoZoho
Oauth2

Zoho is a suite of cloud business apps for CRM, email marketing, and collaboration. It helps teams automate workflows and scale operations effortlessly.

108 Tools

Introduction

This guide walks you through connecting Zoho to Pydantic AI using the Composio tool router. By the end, you'll have a working Zoho agent that can create and convert leads, track deals, manage contacts and accounts, add notes and events, and search your CRM records through natural language commands.

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

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

Also integrate Zoho with

TL;DR

Here's what you'll learn:
  • How to set up your Composio API key and User ID
  • How to create a Composio Tool Router session for Zoho
  • How to attach an MCP Server to a Pydantic AI agent
  • How to stream responses and maintain chat history
  • How to build a simple REPL-style chat interface to test your Zoho workflows

What is Pydantic AI?

Pydantic AI is a Python framework for building AI agents with strong typing and validation. It leverages Pydantic's data validation capabilities to create robust, type-safe AI applications.

Key features include:

  • Type Safety: Built on Pydantic for automatic data validation
  • MCP Support: Native support for Model Context Protocol servers
  • Streaming: Built-in support for streaming responses
  • Async First: Designed for async/await patterns

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

The Zoho MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Zoho account. It provides structured and secure access to your Zoho CRM data, so your agent can create contacts and leads, manage deals, search records, track activities, and draft emails on your behalf.

  • Contact and lead management: Have your agent create contacts and leads, find existing records, and review prospect details in Zoho CRM.
  • Deal and account tracking: Let the agent create and update deals, review sales opportunities, search accounts, and update account details.
  • Tasks, calls, and event coordination: Direct your agent to find tasks, review logged calls, create events, and check upcoming meetings.
  • Notes, emails, and attachments: Instruct your agent to add notes to CRM records, review related emails and attachments, and prepare email drafts.
  • CRM record discovery: Have your agent search across Zoho CRM modules, list available modules, and retrieve related records for added context.

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 step09 STEPS
1

Prerequisites

Before starting, make sure you have:
  • Python 3.9 or higher
  • A Composio account with an active API key
  • Basic familiarity with Python and async programming
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 pydantic-ai python-dotenv

Install the required libraries.

What's happening:

  • composio connects your agent to external SaaS tools like Zoho
  • pydantic-ai lets you create structured AI agents with tool support
  • python-dotenv loads your environment variables securely from a .env file
4

Set up environment variables

bash
COMPOSIO_API_KEY=your_composio_api_key_here
USER_ID=your_user_id_here
OPENAI_API_KEY=your_openai_api_key

Create a .env file in your project root.

What's happening:

  • COMPOSIO_API_KEY authenticates your agent to Composio's API
  • USER_ID associates your session with your account for secure tool access
  • OPENAI_API_KEY to access OpenAI LLMs
5

Import dependencies

python
import asyncio
import os
from dotenv import load_dotenv
from composio import Composio
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStreamableHTTP

load_dotenv()
What's happening:
  • We load environment variables and import required modules
  • Composio manages connections to Zoho
  • MCPServerStreamableHTTP connects to the Zoho MCP server endpoint
  • Agent from Pydantic AI lets you define and run the AI assistant
6

Create a Tool Router Session

python
async def main():
    api_key = os.getenv("COMPOSIO_API_KEY")
    user_id = os.getenv("USER_ID")
    if not api_key or not user_id:
        raise RuntimeError("Set COMPOSIO_API_KEY and USER_ID in your environment")

    # Create a Composio Tool Router session for Zoho
    composio = Composio(api_key=api_key)
    session = composio.create(
        user_id=user_id,
        toolkits=["zoho"],
    )
    url = session.mcp.url
    if not url:
        raise ValueError("Composio session did not return an MCP URL")
What's happening:
  • We're creating a Tool Router session that gives your agent access to Zoho 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
7

Initialize the Pydantic AI Agent

python
# Attach the MCP server to a Pydantic AI Agent
zoho_mcp = MCPServerStreamableHTTP(url, headers={"x-api-key": COMPOSIO_API_KEY})
agent = Agent(
    "openai:gpt-5",
    toolsets=[zoho_mcp],
    instructions=(
        "You are a Zoho assistant. Use Zoho tools to help users "
        "with their requests. Ask clarifying questions when needed."
    ),
)
What's happening:
  • The MCP client connects to the Zoho endpoint
  • The agent uses GPT-5 to interpret user commands and perform Zoho operations
  • The instructions field defines the agent's role and behavior
8

Build the chat interface

python
# Simple REPL with message history
history = []
print("Chat started! Type 'exit' or 'quit' to end.\n")
print("Try asking the agent to help you with Zoho.\n")

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", flush=True)

    async with agent.run_stream(user_input, message_history=history) as stream_result:
        collected_text = ""
        async for chunk in stream_result.stream_output():
            text_piece = None
            if isinstance(chunk, str):
                text_piece = chunk
            elif hasattr(chunk, "delta") and isinstance(chunk.delta, str):
                text_piece = chunk.delta
            elif hasattr(chunk, "text"):
                text_piece = chunk.text
            if text_piece:
                collected_text += text_piece
        result = stream_result

    print(f"Agent: {collected_text}\n")
    history = result.all_messages()
What's happening:
  • The agent reads input from the terminal and streams its response
  • Zoho API calls happen automatically under the hood
  • The model keeps conversation history to maintain context across turns
9

Run the application

python
if __name__ == "__main__":
    asyncio.run(main())
What's happening:
  • The asyncio loop launches the agent and keeps it running until you exit

Complete Code

Here's the complete code to get you started with Zoho and Pydantic AI:

python
import asyncio
import os
from dotenv import load_dotenv
from composio import Composio
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStreamableHTTP

load_dotenv()

async def main():
    api_key = os.getenv("COMPOSIO_API_KEY")
    user_id = os.getenv("USER_ID")
    if not api_key or not user_id:
        raise RuntimeError("Set COMPOSIO_API_KEY and USER_ID in your environment")

    # Create a Composio Tool Router session for Zoho
    composio = Composio(api_key=api_key)
    session = composio.create(
        user_id=user_id,
        toolkits=["zoho"],
    )
    url = session.mcp.url
    if not url:
        raise ValueError("Composio session did not return an MCP URL")

    # Attach the MCP server to a Pydantic AI Agent
    zoho_mcp = MCPServerStreamableHTTP(url, headers={"x-api-key": COMPOSIO_API_KEY})
    agent = Agent(
        "openai:gpt-5",
        toolsets=[zoho_mcp],
        instructions=(
            "You are a Zoho assistant. Use Zoho tools to help users "
            "with their requests. Ask clarifying questions when needed."
        ),
    )

    # Simple REPL with message history
    history = []
    print("Chat started! Type 'exit' or 'quit' to end.\n")
    print("Try asking the agent to help you with Zoho.\n")

    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", flush=True)

        async with agent.run_stream(user_input, message_history=history) as stream_result:
            collected_text = ""
            async for chunk in stream_result.stream_output():
                text_piece = None
                if isinstance(chunk, str):
                    text_piece = chunk
                elif hasattr(chunk, "delta") and isinstance(chunk.delta, str):
                    text_piece = chunk.delta
                elif hasattr(chunk, "text"):
                    text_piece = chunk.text
                if text_piece:
                    collected_text += text_piece
            result = stream_result

        print(f"Agent: {collected_text}\n")
        history = result.all_messages()

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

Conclusion

You've built a Pydantic AI agent that can interact with Zoho through Composio's Tool Router. With this setup, your agent can perform real Zoho actions through natural language. You can extend this further by:
  • Adding other toolkits like Gmail, HubSpot, or Salesforce
  • Building a web-based chat interface around this agent
  • Using multiple MCP endpoints to enable cross-app workflows (for example, Gmail + Zoho for workflow automation)
This architecture makes your AI agent "agent-native", able to securely use APIs in a unified, composable way without custom integrations.
TOOLS

Supported Tools

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

Add Tags to Zoho CRM Records

Apply one or more existing tags to up to 500 records in a Zoho CRM module, optionally replacing each record's existing tags.

Associate Email with Zoho CRM Record

Add an existing sent or received email to a Zoho CRM record's history.

Convert Zoho CRM Lead

Converts a lead into a contact, account, and optionally a deal in Zoho CRM.

Count Zoho CRM Records

Count all records or records matching one filter in a Zoho CRM module.

Create Zoho CRM Automation Task

Create an automation task with typed static, merge, date, or datetime mappings.

Create Contact in Zoho CRM

Creates a new contact record in Zoho CRM.

Create Zoho CRM Custom Fields

Create one to five custom fields in a Zoho CRM module.

Create Zoho CRM Custom View

Create one custom view for a Zoho CRM module.

Create Deal in Zoho CRM

Creates a new deal in Zoho CRM representing a sales opportunity with deal name, stage, amount, and closing date.

Create Email Draft in Zoho CRM

Creates email drafts for a specific record in Zoho CRM.

Create Zoho Event

Creates a new Event record in Zoho CRM.

Create Zoho CRM Function

Create a Zoho CRM function.

Create Lead in Zoho CRM

Creates a new lead record in Zoho CRM with the specified details.

Create Note in Zoho CRM

Creates a new note attached to a specific record in Zoho CRM.

Create Zoho CRM Workflow Rule

Create one Zoho CRM workflow rule with typed triggers, criteria, and actions.

Create Zoho CRM Record

Creates new records in a specified Zoho CRM module.

Create Zoho CRM Tag

Creates a new tag in Zoho CRM for a specific module.

Delete Zoho Account

Deletes an existing account record from Zoho CRM.

Delete Zoho CRM Contact

Deletes a contact from Zoho CRM by its ID, with an optional workflow trigger setting.

Delete Zoho CRM Deal

Deletes a deal record from Zoho CRM.

Delete Zoho CRM Email Draft

Delete one unsent email draft associated with a Zoho CRM record.

Delete Zoho CRM Event

Move one Zoho CRM Event record to the recycle bin.

Delete Zoho CRM Lead

Move one Zoho CRM Lead record to the recycle bin.

Delete Zoho CRM Note

Move one Zoho CRM note to the recycle bin.

Delete Zoho CRM Records

Move up to 100 records from a Zoho CRM module to the recycle bin.

Delete Zoho CRM Tag

Delete one Zoho CRM tag definition by its tag ID.

Download Zoho CRM Record Attachment

Download one attachment from a Zoho CRM record as a file.

Download Zoho CRM Record Email Attachment

Download one attachment from an email associated with a CRM record.

Download Zoho CRM Record Photo

Download the binary profile photo attached to a supported CRM record.

Export Zoho CRM Audit Logs

Export Zoho CRM audit logs and return the completed CSV or ZIP file.

Get Zoho CRM Account

Retrieves a specific Zoho CRM Account record by its unique identifier, with optional field selection.

Get Zoho CRM Assignment Rule

Retrieve one assignment rule and its module-specific configuration.

Get Zoho CRM Automation Task

Retrieve one configured Zoho CRM automation task and its field mappings.

Get Zoho CRM Blueprint

Retrieve one Zoho CRM blueprint and optional configuration details.

Get Zoho CRM Blueprint Transition

Retrieve one Zoho CRM blueprint transition and its configuration.

Get Call

Retrieves a specific Call record by its unique identifier from Zoho CRM.

Get Zoho CRM Contact

Retrieves a single Zoho CRM contact record by ID, optionally selecting fields by their API names.

Get Zoho CRM Custom Views

List custom views for a Zoho CRM module or inspect one view by ID.

Get Zoho CRM Deal

Retrieve one Zoho CRM Deal by record ID without a field projection.

Get Email Drafts for Zoho CRM Record

Retrieves email drafts associated with a specific record in Zoho CRM.

Get Zoho Event

Retrieves a specific Zoho CRM event or meeting by its unique identifier, optionally selecting fields.

Get From Addresses

Retrieves the list of from addresses configured for email operations in Zoho CRM.

Get Zoho CRM Kiosk States

List a kiosk's states or retrieve one state and its associated elements.

Get Zoho CRM Layouts

List layouts for a CRM module or retrieve one complete layout definition.

Get Zoho CRM Module Fields Metadata

Retrieves field metadata for a Zoho CRM module including API names, data types, permissions, and configuration details.

Get Zoho CRM Note

Retrieves a single Zoho CRM note by its unique identifier, with a selectable set of fields.

Get Zoho CRM Organization Details

Retrieve identity, locale, currency, contact, and license metadata for the connected Zoho CRM organization.

Get Zoho CRM Pipelines

Retrieve pipeline and stage configuration for a Zoho CRM Deals layout.

Get Zoho CRM Product

Retrieve one Zoho CRM Product by record ID.

Get Zoho CRM Profile

Retrieve one Zoho CRM permission profile and its expanded permissions.

Get Zoho CRM Record

Retrieve one record from a standard or custom Zoho CRM module by ID.

Get Zoho CRM Record Email

Retrieve one email associated with a Zoho CRM record, including its body.

Get Zoho CRM Record Emails

Retrieves a page of emails associated with a specific record in Zoho CRM.

Get Zoho CRM Record Timeline

Retrieve chronological field and related-record history for a Zoho CRM record.

Get Zoho CRM Related Lists Metadata

Retrieves related list metadata for a Zoho CRM module to discover correct api_name values.

Get Zoho CRM Related Records

Fetch related-list records (e.

Get Zoho CRM Task

Retrieves a specific Zoho CRM task by its unique record ID, with an optional selection of fields.

Get Zoho CRM User

Retrieves a Zoho CRM user by ID, including name, email, role, profile, status, and preferences.

Get Zoho CRM Webform

Retrieve one configured Zoho CRM webform by ID.

Get Zoho CRM Workflow Rule

Retrieve one Zoho CRM workflow rule and its complete configuration.

Get Zoho CRM Records

Retrieves records from a specified module in Zoho CRM.

Get Zoho CRM Users

Tool to retrieve users from Zoho CRM.

List Zoho CRM Access Settings

List roles or permission profiles configured in Zoho CRM.

List Zoho CRM Accounts

Retrieves a list of account records from Zoho CRM with pagination and filtering support.

List Zoho CRM Cadences

List Zoho CRM cadence definitions using optional filters.

List Zoho CRM Calls

Retrieves Call activity records from Zoho CRM with pagination support.

List Zoho CRM Connected Workflow Rules

List trigger conditions for a module's rules in a connected workflow.

List Contacts

Retrieves contact records from Zoho CRM with support for pagination, filtering, and sorting.

List Deals

Retrieves a list of deals from Zoho CRM with support for filtering, sorting, and pagination.

List Zoho CRM Events

Lists Zoho CRM Events (displayed as Meetings in the UI), with pagination and filtering.

List Zoho CRM Functions

List configured Zoho CRM functions and their metadata.

List Zoho CRM Leads

Retrieves lead records from Zoho CRM's Leads module with pagination support.

List Zoho CRM Modules

Lists all available Zoho CRM modules (standard + custom) to reliably select module API names/IDs for operations.

List Zoho CRM Notes

Retrieves one paginated list of notes across all Zoho CRM modules, with fields selected by the caller; notes are returned in chronological order (oldest first by default).

List Attachments for Zoho CRM Record

Tool to list attachment metadata (id, File_Name, Size, Created_Time, etc.

List Zoho CRM Tags

List the tags available for a Zoho CRM module.

List Zoho CRM Tasks

Retrieves tasks from the Tasks module in Zoho CRM with support for filtering, pagination, and sorting.

List Zoho CRM Variables

List Zoho CRM configuration variables and their current values.

List Zoho CRM Workflow Rules

List and filter workflow rules configured in Zoho CRM.

Merge Zoho CRM Leads

Merge duplicate leads into a retained master lead and delete the child leads.

Search Zoho CRM Accounts

Search for Account records within Zoho CRM using server-side queries.

Search Zoho CRM Calls

Search for Call records in Zoho CRM using server-side queries.

Search Zoho CRM Contacts

Search for contacts in Zoho CRM using server-side queries by criteria, email, phone, or keyword.

Search Deals in Zoho CRM

Search for Deal records in Zoho CRM using server-side queries.

Search Events

Search for Events in Zoho CRM using server-side queries.

Search Leads

Search for lead records in Zoho CRM using server-side queries.

Search Notes

Search for notes in Zoho CRM using server-side queries.

Search Zoho CRM Tasks

Search for tasks in Zoho CRM using flexible criteria.

Search Zoho CRM Records

Search for records within a Zoho CRM module using server-side queries.

Update Zoho CRM Account

Updates an existing Account record in Zoho CRM with the specified field values.

Update Zoho CRM Call

Updates existing call records in the Calls module in Zoho CRM.

Update Zoho CRM Custom Fields

Update custom-field definitions; some changes can alter existing record values.

Update Zoho CRM Custom View

Update the configuration of one Zoho CRM custom view.

Update Zoho CRM Deal

Updates an existing deal in Zoho CRM.

Update Zoho CRM Email Draft

Updates an existing email draft associated with a record in Zoho CRM.

Update Zoho CRM Event

Updates existing events in Zoho CRM.

Update Zoho CRM Layout

Update a custom layout's metadata, profile access, sections, or fields.

Update Lead

Updates existing lead records in Zoho CRM.

Update Zoho CRM Note

Updates an existing Zoho CRM note by ID, including its title, content, or portal-user sharing setting.

Update Related Records in Zoho CRM

Associates or updates relationships between records across different modules in Zoho CRM.

Update Zoho CRM User

Update a Zoho CRM user's name, email, contact details, locale, time preferences, role, profile, or status by ID.

Update Zoho CRM Webform

Replace one Zoho CRM webform configuration using the V8 path-ID route.

Update Zoho CRM Workflow Rule

Update a Zoho CRM workflow rule's name, description, or activation status by ID.

Update Zoho CRM Record

Updates up to 100 existing records in a specified Zoho CRM module using field API names and an ID for each record.

Upload Attachment to Zoho CRM Record

Tool to upload a file as an Attachment to a specific Zoho CRM record.

Upload Zoho CRM Record Photo

Set or replace the photo on a supported Zoho CRM record.

Upsert Zoho CRM Records

Insert or update up to 100 records using Zoho CRM duplicate matching.

Validate Zoho CRM Credentials

Validates Zoho CRM credentials by retrieving current user information.

FAQ

Frequently asked questions

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

Yes, you can. Pydantic AI 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 Zoho tools.

Yes, absolutely. You can configure which Zoho 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 Zoho data and credentials are handled as safely as possible.

Start with Zoho.It takes 30 seconds.

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

Start building