How to integrate Zoho invoice MCP with Vercel AI SDK v6

This guide walks you through connecting Zoho invoice to Vercel AI SDK v6 using the Composio tool router. By the end, you'll have a working Zoho invoice agent that can list all unpaid invoices from last month, show expenses categorized by project for may, find payments received from a specific client through natural language commands. This guide will help you understand how to give your Vercel AI SDK agent real control over a Zoho invoice account through Composio's Zoho invoice MCP server. Before we dive in, let's take a quick look at the key ideas and tools involved.

Zoho invoice logoZoho invoice
Oauth2

Zoho Invoice is an online invoicing and billing platform for freelancers and small businesses. It streamlines professional invoice creation, recurring payments, and expense tracking.

137 Tools

Introduction

This guide walks you through connecting Zoho invoice to Vercel AI SDK v6 using the Composio tool router. By the end, you'll have a working Zoho invoice agent that can list all unpaid invoices from last month, show expenses categorized by project for may, find payments received from a specific client through natural language commands.

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

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

Also integrate Zoho invoice with

TL;DR

Here's what you'll learn:
  • How to set up and configure a Vercel AI SDK agent with Zoho invoice integration
  • Using Composio's Tool Router to dynamically load and access Zoho invoice tools
  • Creating an MCP client connection using HTTP transport
  • Building an interactive CLI chat interface with conversation history management
  • Handling tool calls and results within the Vercel AI SDK framework

What is Vercel AI SDK?

The Vercel AI SDK is a TypeScript library for building AI-powered applications. It provides tools for creating agents that can use external services and maintain conversation state.

Key features include:

  • streamText: Core function for streaming responses with real-time tool support
  • MCP Client: Built-in support for Model Context Protocol via @ai-sdk/mcp
  • Step Counting: Control multi-step tool execution with stopWhen: stepCountIs()
  • OpenAI Provider: Native integration with OpenAI models

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

The Zoho invoice 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 Invoice account. It provides structured and secure access to your invoicing, billing, and expense data, so your agent can perform actions like listing invoices, fetching payments, retrieving contacts, and managing expenses on your behalf.

  • Comprehensive invoice management: Let your agent list and review all invoices, making it easy to track billing history, filter by status, or check for outstanding payments.
  • Automated expense tracking: Have your agent retrieve and organize expense records, helping you monitor spending and simplify bookkeeping.
  • Contact catalog access: Quickly pull a list of clients, vendors, or customers from your Zoho Invoice account to streamline outreach and relationship management.
  • Real-time payment tracking: Direct your agent to list all payments, filter by customer or date range, and ensure nothing falls through the cracks.
  • Itemized inventory insights: Fetch detailed item catalogs or retrieve specific item details to keep your invoicing accurate and up to date.

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 you begin, make sure you have:
  • Node.js and npm installed
  • A Composio account with API key
  • An OpenAI API key
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 required dependencies

bash
npm install @ai-sdk/openai @ai-sdk/mcp @composio/core ai dotenv

First, install the necessary packages for your project.

What you're installing:

  • @ai-sdk/openai: Vercel AI SDK's OpenAI provider
  • @ai-sdk/mcp: MCP client for Vercel AI SDK
  • @composio/core: Composio SDK for tool integration
  • ai: Core Vercel AI SDK
  • dotenv: Environment variable management
4

Set up environment variables

bash
OPENAI_API_KEY=your_openai_api_key_here
COMPOSIO_API_KEY=your_composio_api_key_here
COMPOSIO_USER_ID=your_user_id_here

Create a .env file in your project root.

What's needed:

  • OPENAI_API_KEY: Your OpenAI API key for GPT model access
  • COMPOSIO_API_KEY: Your Composio API key for tool access
  • COMPOSIO_USER_ID: A unique identifier for the user session
5

Import required modules and validate environment

typescript
import "dotenv/config";
import { openai } from "@ai-sdk/openai";
import { Composio } from "@composio/core";
import * as readline from "readline";
import { streamText, type ModelMessage, stepCountIs } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";

const composioAPIKey = process.env.COMPOSIO_API_KEY;
const composioUserID = process.env.COMPOSIO_USER_ID;

if (!process.env.OPENAI_API_KEY) throw new Error("OPENAI_API_KEY is not set");
if (!composioAPIKey) throw new Error("COMPOSIO_API_KEY is not set");
if (!composioUserID) throw new Error("COMPOSIO_USER_ID is not set");

const composio = new Composio({
  apiKey: composioAPIKey,
});
What's happening:
  • We're importing all necessary libraries including Vercel AI SDK's OpenAI provider and Composio
  • The dotenv/config import automatically loads environment variables
  • The MCP client import enables connection to Composio's tool server
6

Create Tool Router session and initialize MCP client

typescript
async function main() {
  // Create a tool router session for the user
  const session = await composio.create(composioUserID!, {
    toolkits: ["zoho_invoice"],
  });

  const mcpUrl = session.mcp.url;
What's happening:
  • We're creating a Tool Router session that gives your agent access to Zoho invoice tools
  • The create method takes the user ID and specifies which toolkits should be available
  • The returned mcp object contains the URL and authentication headers needed to connect to the MCP server
  • This session provides access to all Zoho invoice-related tools through the MCP protocol
7

Connect to MCP server and retrieve tools

typescript
const mcpClient = await createMCPClient({
  transport: {
    type: "http",
    url: mcpUrl,
    headers: session.mcp.headers, // Authentication headers for the Composio MCP server
  },
});

const tools = await mcpClient.tools();
What's happening:
  • We're creating an MCP client that connects to our Composio Tool Router session via HTTP
  • The mcp.url provides the endpoint, and mcp.headers contains authentication credentials
  • The type: "http" is important - Composio requires HTTP transport
  • tools() retrieves all available Zoho invoice tools that the agent can use
8

Initialize conversation and CLI interface

typescript
let messages: ModelMessage[] = [];

console.log("Chat started! Type 'exit' or 'quit' to end the conversation.\n");
console.log(
  "Ask any questions related to zoho_invoice, like summarize my last 5 emails, send an email, etc... :)))\n",
);

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  prompt: "> ",
});

rl.prompt();
What's happening:
  • We initialize an empty messages array to maintain conversation history
  • A readline interface is created to accept user input from the command line
  • Instructions are displayed to guide the user on how to interact with the agent
9

Handle user input and stream responses with real-time tool feedback

typescript
rl.on("line", async (userInput: string) => {
  const trimmedInput = userInput.trim();

  if (["exit", "quit", "bye"].includes(trimmedInput.toLowerCase())) {
    console.log("\nGoodbye!");
    rl.close();
    process.exit(0);
  }

  if (!trimmedInput) {
    rl.prompt();
    return;
  }

  messages.push({ role: "user", content: trimmedInput });
  console.log("\nAgent is thinking...\n");

  try {
    const stream = streamText({
      model: openai("gpt-5"),
      messages,
      tools,
      toolChoice: "auto",
      stopWhen: stepCountIs(10),
      onStepFinish: (step) => {
        for (const toolCall of step.toolCalls) {
          console.log(`[Using tool: ${toolCall.toolName}]`);
          }
          if (step.toolCalls.length > 0) {
            console.log(""); // Add space after tool calls
          }
        },
      });

      for await (const chunk of stream.textStream) {
        process.stdout.write(chunk);
      }

      console.log("\n\n---\n");

      // Get final result for message history
      const response = await stream.response;
      if (response?.messages?.length) {
        messages.push(...response.messages);
      }
    } catch (error) {
      console.error("\nAn error occurred while talking to the agent:");
      console.error(error);
      console.log(
        "\nYou can try again or restart the app if it keeps happening.\n",
      );
    } finally {
      rl.prompt();
    }
  });

  rl.on("close", async () => {
    await mcpClient.close();
    console.log("\n👋 Session ended.");
    process.exit(0);
  });
}

main().catch((err) => {
  console.error("Fatal error:", err);
  process.exit(1);
});
What's happening:
  • We use streamText instead of generateText to stream responses in real-time
  • toolChoice: "auto" allows the model to decide when to use Zoho invoice tools
  • stopWhen: stepCountIs(10) allows up to 10 steps for complex multi-tool operations
  • onStepFinish callback displays which tools are being used in real-time
  • We iterate through the text stream to create a typewriter effect as the agent responds
  • The complete response is added to conversation history to maintain context
  • Errors are caught and displayed with helpful retry suggestions

Complete Code

Here's the complete code to get you started with Zoho invoice and Vercel AI SDK:

typescript
import "dotenv/config";
import { openai } from "@ai-sdk/openai";
import { Composio } from "@composio/core";
import * as readline from "readline";
import { streamText, type ModelMessage, stepCountIs } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";

const composioAPIKey = process.env.COMPOSIO_API_KEY;
const composioUserID = process.env.COMPOSIO_USER_ID;

if (!process.env.OPENAI_API_KEY) throw new Error("OPENAI_API_KEY is not set");
if (!composioAPIKey) throw new Error("COMPOSIO_API_KEY is not set");
if (!composioUserID) throw new Error("COMPOSIO_USER_ID is not set");

const composio = new Composio({
  apiKey: composioAPIKey,
});

async function main() {
  // Create a tool router session for the user
  const session = await composio.create(composioUserID!, {
    toolkits: ["zoho_invoice"],
  });

  const mcpUrl = session.mcp.url;

  const mcpClient = await createMCPClient({
    transport: {
      type: "http",
      url: mcpUrl,
      headers: session.mcp.headers, // Authentication headers for the Composio MCP server
    },
  });

  const tools = await mcpClient.tools();

  let messages: ModelMessage[] = [];

  console.log("Chat started! Type 'exit' or 'quit' to end the conversation.\n");
  console.log(
    "Ask any questions related to zoho_invoice, like summarize my last 5 emails, send an email, etc... :)))\n",
  );

  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    prompt: "> ",
  });

  rl.prompt();

  rl.on("line", async (userInput: string) => {
    const trimmedInput = userInput.trim();

    if (["exit", "quit", "bye"].includes(trimmedInput.toLowerCase())) {
      console.log("\nGoodbye!");
      rl.close();
      process.exit(0);
    }

    if (!trimmedInput) {
      rl.prompt();
      return;
    }

    messages.push({ role: "user", content: trimmedInput });
    console.log("\nAgent is thinking...\n");

    try {
      const stream = streamText({
        model: openai("gpt-5"),
        messages,
        tools,
        toolChoice: "auto",
        stopWhen: stepCountIs(10),
        onStepFinish: (step) => {
          for (const toolCall of step.toolCalls) {
            console.log(`[Using tool: ${toolCall.toolName}]`);
          }
          if (step.toolCalls.length > 0) {
            console.log(""); // Add space after tool calls
          }
        },
      });

      for await (const chunk of stream.textStream) {
        process.stdout.write(chunk);
      }

      console.log("\n\n---\n");

      // Get final result for message history
      const response = await stream.response;
      if (response?.messages?.length) {
        messages.push(...response.messages);
      }
    } catch (error) {
      console.error("\nAn error occurred while talking to the agent:");
      console.error(error);
      console.log(
        "\nYou can try again or restart the app if it keeps happening.\n",
      );
    } finally {
      rl.prompt();
    }
  });

  rl.on("close", async () => {
    await mcpClient.close();
    console.log("\n👋 Session ended.");
    process.exit(0);
  });
}

main().catch((err) => {
  console.error("Fatal error:", err);
  process.exit(1);
});

Conclusion

You've successfully built a Zoho invoice agent using the Vercel AI SDK with streaming capabilities! This implementation provides a powerful foundation for building AI applications with natural language interfaces and real-time feedback.

Key features of this implementation:

  • Real-time streaming responses for a better user experience with typewriter effect
  • Live tool execution feedback showing which tools are being used as the agent works
  • Dynamic tool loading through Composio's Tool Router with secure authentication
  • Multi-step tool execution with configurable step limits (up to 10 steps)
  • Comprehensive error handling for robust agent execution
  • Conversation history maintenance for context-aware responses

You can extend this further by adding custom error handling, implementing specific business logic, or integrating additional Composio toolkits to create multi-app workflows.
TOOLS

Supported Tools

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

Add Credit Note to Invoices

Tool to apply a credit note to one or more invoices.

Add Invoice Comment

Tool to add a comment to an invoice.

Apply Credits to Invoice

Tool to apply credit notes to an invoice in Zoho Invoice.

Cancel Write Off Invoice

Tool to cancel a write-off on an invoice.

Clone Zoho Invoice Project

Tool to clone an existing project.

Create Additional Address

Tool to add an additional address to a contact.

Create Contact

Tool to create a contact in Zoho Invoice.

Create Contact Person

Tool to create a contact person for an existing contact.

Create Credit Note

Tool to create a credit note to refund or give credit to a customer.

Create Credit Note Comment

Tool to add a comment to a credit note.

Create Currency

Tool to create a new currency in Zoho Invoice.

Create Customer Payment

Tool to create a customer payment in Zoho Invoice.

Create Employee

Tool to create an employee in Zoho Invoice.

Create Estimate

Tool to create a new estimate (quote) for a customer.

Create Estimate Comment

Tool to add a comment to an estimate.

Create Exchange Rate

Tool to create an exchange rate for a specified currency.

Create Expense Category

Tool to create a new expense category in Zoho Invoice.

Create Invoice

Tool to create a new invoice for a customer in Zoho Invoice.

Create Item

Tool to create a new item in Zoho Invoice.

Create Project Comment

Tool to post a comment to a project.

Create Recurring Invoice

Tool to create a recurring invoice profile that automatically generates invoices at specified intervals.

Create Refund Credit Note Refunds

Tool to create a refund for a credit note.

Create Task

Tool to create a new task in a Zoho Invoice project.

Create Tax

Tool to create a new tax in Zoho Invoice.

Create Tax Group

Tool to create a new tax group in Zoho Invoice.

Create Time Entry

Tool to log time entries for projects in Zoho Invoice.

Create Zoho Invoice User

Tool to create a new user in Zoho Invoice.

Delete Additional Address

Tool to delete an additional address from a contact.

Delete Contact

Tool to delete a contact from Zoho Invoice.

Delete Contact Person

Tool to delete a contact person from Zoho Invoice.

Delete Credit Notes Applied to Invoice

Tool to delete invoices credited from a credit note.

Delete Currency

Tool to delete a currency from Zoho Invoice settings.

Delete Customer Payment

Tool to delete an existing payment from Zoho Invoice.

Delete Employee

Tool to delete an employee from Zoho Invoice.

Delete Estimate Comment

Tool to delete a comment from an estimate.

Delete Estimates

Tool to delete one or more estimates (quotes).

Delete Expense

Tool to delete an expense from Zoho Invoice.

Delete Expense Category

Tool to delete an expense category from Zoho Invoice.

Delete Invoice

Tool to delete an existing invoice from Zoho Invoice.

Delete Invoice Attachment

Tool to delete an attachment from an invoice.

Delete Invoice Comment

Tool to delete a comment from an invoice.

Delete Invoice Expense Receipt

Tool to delete the receipt attached to an expense in Zoho Invoice.

Delete Item

Tool to delete an existing item from Zoho Invoice.

Delete Project

Tool to delete a project from Zoho Invoice.

Delete Project Comment

Tool to delete a comment from a project.

Delete Tax

Tool to delete a simple or compound tax from Zoho Invoice settings.

Delete Task

Tool to delete a task from a Zoho Invoice project.

Delete Time Entry

Tool to delete a time entry from Zoho Invoice.

Delete User

Tool to delete a user from Zoho Invoice.

Disable Contact Payment Reminders

Tool to disable payment reminders for a contact.

Disable Invoice Payment Reminder

Tool to disable payment reminders for an invoice.

Email Contact Statement

Tool to email a statement to a contact in Zoho Invoice.

Email Estimate

Tool to email an estimate to a customer.

Email Invoice

Tool to email an invoice to customers.

Email Multiple Estimates

Tool to send estimates via email to customers in bulk.

Enable Invoice Payment Reminder

Tool to enable payment reminders for an invoice.

Enable Payment Reminders

Tool to enable payment reminders for a contact.

Enable Portal Access

Tool to enable portal access for contact persons in Zoho Invoice.

Bulk Export Invoices

Tool to bulk export multiple invoices as a single PDF file.

Get All Tasks

Tool to list all tasks in a Zoho Invoice project.

Get Client Review

Tool to retrieve details of a particular client review by comment ID.

Get Contact

Tool to retrieve a specific contact by ID.

Get Contact Addresses

Tool to retrieve all addresses for a contact.

Get Contact Person

Tool to retrieve details of a specific contact person.

Get Credit Note

Tool to retrieve the details of a specific credit note by creditnote_id.

Get Credit Note Email History

Tool to retrieve email history for a credit note.

Get Credit Note Refund

Tool to retrieve details of a specific credit note refund.

Get Expense

Tool to retrieve a specific expense by ID.

Get Invoice

Tool to retrieve the details of a specific invoice by invoice_id.

Get Invoice Attachment

Tool to get invoice attachment details.

Get Invoice Email Content

Tool to retrieve the email content for a specific invoice.

Get Zoho Invoice Item

Tool to retrieve the details of a specific item by item_id.

Get Payment Reminder Mail Content

Tool to retrieve payment reminder mail content for a specific invoice.

Get Price List

Tool to retrieve the details of a specific price list by pricebook_id.

Get Project

Tool to retrieve details of a specific project by project ID.

Get Project User

Tool to retrieve a specific user from a project.

Get Recurring Invoice

Tool to retrieve the details of a specific recurring invoice by recurring_invoice_id.

Get Statement Mail Content

Tool to retrieve statement mail content for a specific contact.

Get Task

Tool to retrieve a specific task from a Zoho Invoice project.

Get Tax

Tool to retrieve details of a specific tax by tax_id.

Get Tax Group

Tool to retrieve a specific tax group by ID.

Get Time Entry

Tool to retrieve a specific time entry from Zoho Invoice.

Inactivate Project

Tool to deactivate a project in Zoho Invoice.

List Child Expenses Created

Tool to list child expenses created from a recurring expense.

List Client Reviews

Tool to retrieve all client reviews for contacts.

List Contact Comments

Tool to list all comments on a contact.

List Contact Refunds

Tool to list refunds associated with a contact.

List Contacts

Tool to list contacts.

List Credit Notes

Tool to list credit notes.

List Currencies

Tool to list all currencies configured for the organization.

List Customer Payment Refunds

Tool to list refunds of a customer payment.

List Employees

Tool to list all employees in the organization.

List Estimates

Tool to list all estimates.

List Expense Categories

Tool to list all expense categories with optional filtering, sorting, and pagination.

List Expense Comments

Tool to list expense history and comments.

List Expenses

List all expenses with optional filtering, sorting, and pagination.

List Invoice Comments

Tool to list all comments and history for an invoice.

List Invoice Payments

Tool to list payments for a specific invoice.

List Invoices

Tool to list invoices.

List Invoices Credited

Tool to list invoices to which a specific credit note has been applied.

List Items

Tool to list all items.

List Organizations

Tool to list all organizations.

List Payments

Tool to list payments.

List Price Lists

Tool to list all price lists.

List Project Comments

Tool to list all comments for a project.

List Project Invoices

Tool to list all invoices for a specific project.

List Projects

Tool to list all projects.

List Project Users

Tool to list all users assigned to a specific project.

List Recurring Invoices

Tool to list recurring invoices.

List Retainer Invoices

Tool to list retainer invoices.

List Retainer Invoice Templates

Tool to list retainer invoice templates.

List Users

Tool to list users in a Zoho Invoice organization.

Mark Contact as Active

Tool to mark an inactive contact as active.

Mark Contact as Inactive

Tool to mark a contact as inactive in Zoho Invoice.

Mark Contact Person as Primary

Tool to mark a contact person as primary in Zoho Invoice.

Mark Estimate as Declined

Tool to mark an estimate as declined.

Mark Expense Category as Active

Tool to mark an inactive expense category as active.

Mark Invoice as Sent

Tool to mark an invoice as sent.

Mark Invoice as Void

Tool to mark an invoice as void.

Mark Item as Inactive

Tool to mark an active item as inactive.

Mark Retainer Invoice as Sent

Tool to mark a retainer invoice as sent.

Bulk Print Estimates

Tool to bulk print multiple estimates as PDF.

Bulk Print Invoices

Tool to bulk print invoices as PDF.

Refund Customer Payment

Tool to refund an excess customer payment.

Resume Recurring Invoice

Tool to resume a recurring invoice in Zoho Invoice.

Send Bulk Invoice Reminder

Tool to send payment reminders for multiple invoices in bulk.

Send Contact Email

Tool to send an email to a contact in Zoho Invoice.

Start Timer

Tool to start a timer on an existing time entry in Zoho Invoice.

Stop Recurring Invoice

Tool to stop a recurring invoice in Zoho Invoice.

Update Additional Address

Tool to update an additional address for a contact.

Update Contact

Tool to update an existing contact in Zoho Invoice.

Update Contact Person

Tool to update a contact person in Zoho Invoice.

Update Credit Note

Tool to update an existing credit note in Zoho Invoice.

Update Credit Note Template

Tool to update the template associated with a credit note.

Update Customer Payment Refund

Tool to update an existing customer payment refund.

Update Estimate Shipping Address

Tool to update the shipping address for an estimate.

Write Off Invoice

Tool to write off an invoice.

FAQ

Frequently asked questions

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

Yes, you can. Vercel AI SDK v6 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 invoice tools.

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

Start with Zoho invoice.It takes 30 seconds.

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

Start building