How to integrate Bamboohr MCP with Vercel AI SDK

Framework Integration Gradient
Bamboohr Logo
Vercel AI SDK Logo
divider

Introduction

This guide walks you through connecting Bamboohr to Vercel AI SDK using the Composio tool router. By the end, you'll have a working Bamboohr agent that can add new dependent for employee john doe, update direct deposit details for sarah smith, log overtime hours for marketing team members, post interview feedback on jane roe's application through natural language commands.

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

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

TL;DR

Here's what you'll learn:
  • How to set up and configure a Vercel AI SDK agent with Bamboohr integration
  • Using Composio's Tool Router to dynamically load and access Bamboohr 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
  • Step Counting: Control multi-step tool execution
  • OpenAI Provider: Native integration with OpenAI models

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

The BambooHR MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your BambooHR account. It provides structured and secure access to your HR data, so your agent can perform actions like managing employee benefits, updating payroll records, tracking time, and assisting with applicant management on your behalf.

  • Employee benefits administration: Automatically enroll employees in benefit groups, create or update benefit records, and manage company-wide benefit offerings with ease.
  • Payroll and direct deposit management: Enable your agent to create paystubs, add unpaid pay periods, and update employee direct deposit information for seamless payroll processing.
  • Dependent and tax record updates: Empower your agent to add employee dependents and modify withholding details, keeping employee records accurate and compliant.
  • Time tracking automation: Let your agent log new time tracking records for employees, ensuring precise attendance and overtime data for reporting and payroll.
  • Applicant and recruitment collaboration: Allow your agent to post comments on applicant records, streamlining feedback and communication during the hiring process.

Supported Tools & Triggers

Tools
Add benefit group employee recordThis endpoint allows you to associate an employee with a specific benefit group in bamboohr for a defined period.
Create employee benefit entryCreates or updates an employee benefit in the bamboohr system.
Create employee dependent recordThis endpoint allows you to create a new dependent for an existing employee in the bamboohr system.
Modify employee withholding detailsThis endpoint updates an employee's withholding information for tax purposes in the bamboohr system.
Create employee direct deposit accountUpdates the direct deposit account information for a specific employee in the bamboohr system.
Post employee paystub detailsCreates a new employee pay stub in the bamboohr system.
Create employee unpaid paystubPosts unpaid pay stubs for a specific employee in the bamboohr system.
Create company benefitThis endpoint creates a new company benefit in bamboohr.
Add time tracking recordThis endpoint allows you to add a new time tracking record for an employee in the bamboohr system.
Post applicant commentThis endpoint allows you to post a comment on a specific application in bamboohr's applicant tracking system.
Update employee time off historyAdds a new time off history item to an employee's record in bamboohr.
Request employee time offThis endpoint allows you to add or update a time off request for a specific employee in bamboohr.
Store time tracking clock entriesThe "store time tracking clock entries" endpoint allows you to create or update multiple time tracking entries for employees in bamboohr.
Store hour entriesThis endpoint allows you to store or update multiple time tracking hour entries for employees in bamboohr.
Create new employeeCreates a new employee record in the bamboohr system.
Submit candidate applicationThis endpoint creates a new job application in the bamboohr applicant tracking system.
Post employee training recordThis endpoint allows you to create a new training record for a specific employee in the bamboohr system.
Create job opening postCreates a new job opening in the bamboohr applicant tracking system.
Add or update list field valuesAdds new values or updates existing values for a specific list field in the bamboohr system.
Update employee table rowThis endpoint allows you to update a specific row in an employee's table within bamboohr.
Employee clock in via taskidClocks in an employee in the bamboohr time tracking system, marking the start of their work period.
Post employee clock outThis endpoint clocks out an employee in the bamboohr time tracking system, marking the end of their working hours.
Post training category via domainCreates a new training category in the bamboohr system.
Post training object for a company domainCreates a new training type in the bamboohr system with specified attributes and settings.
Add webhook with monitoring fieldsThe addwebhook endpoint allows you to create a new webhook in bamboohr, enabling real-time notifications for specific employee data changes.
Adjust employee time off balanceThis endpoint allows you to adjust the time off balance for a specific employee in bamboohr.
Fetch goal alignment optionsRetrieves the available goal alignment options for a specific employee or the authenticated api user in bamboohr.
Approve timesheets with timestampThe approvetimesheets endpoint enables managers or authorized personnel to approve multiple employee timesheets in a single api call within the bamboohr time tracking system.
Approve timesheets for employees that are currently clocked inThis endpoint will approve all timesheets for employees that are currently clocked in.
Retrieve employee performance optionsRetrieves the list of employees with whom a specific employee's goals can be shared within bamboohr.
Check employee goal creation permissionThis endpoint checks whether a specific employee has the permission to create goals within the bamboohr performance management system.
Post application status updateUpdates the status of a specific application in the bamboohr applicant tracking system.
Update time off request statusThis endpoint updates the status of a specific time-off request in bamboohr.
Delete employee withholding by idDeletes a specific employee withholding record from the bamboohr system.
Delete employee direct deposit accountsDeletes a specific direct deposit account associated with an employee in the bamboohr system.
Delete employee unpaid pay stubThis endpoint deletes a specific unpaid pay stub for an employee in the bamboohr system.
Clock in employee with time and locationThis endpoint records a clock-in event for a specific employee in the bamboohr time tracking system.
Post employee clock out datetimeThis endpoint records the clock-out time for a specific employee in the bamboohr time tracking system.
Clock out employee with locationThe clockoutemployee endpoint allows you to record an employee's clock-out time and location in the bamboohr time tracking system.
Close employee goalThe closeemployeegoal endpoint allows you to mark a specific performance goal as completed or closed for an individual employee in bamboohr.
Create time tracking projectCreates a new time tracking project in bamboohr.
Add employee goalThis endpoint allows you to add a new goal for a specific employee in the bamboohr performance management system.
Add comment to employee goalThis endpoint allows you to post a comment on a specific employee's goal within the bamboohr performance management system.
Delete company benefit by idDeletes a specific company benefit from the bamboohr system.
Delete employee pay stub by idDeletes a specific employee pay stub from the bamboohr system.
Delete time tracking entryThe deletetimetrackingentry endpoint allows for the deletion of a specific time tracking entry from the bamboohr system.
Delete clock entry idsDeletes multiple clock entries from the bamboohr time tracking system.
Delete file by idDeletes a specific file from the bamboohr system for a given company.
Delete employee file by idDeletes a specific file associated with an employee in the bamboohr system.
Delete employee training recordDeletes a specific employee training record from the bamboohr system.
Delete employee goalThis endpoint deletes a specific goal associated with an employee in the bamboohr performance management system.
Delete employee goal commentDeletes a specific comment on an employee's performance goal in the bamboohr system.
Delete employee table rowThis endpoint deletes a specific row from an employee's table in bamboohr.
Delete clock entries via idsDeletes multiple clock entries from the bamboohr time tracking system.
Delete hour entries by idsDeletes multiple time tracking hour entries from the bamboohr system.
Delete training categoryDeletes a specific training category from the bamboohr system for a given company.
Delete training type by idDeletes a specific training type from the bamboohr system.
Delete webhook by idThe deletewebhook endpoint is used to remove a specific webhook from the bamboohr system.
Adjust time tracking hoursThis endpoint allows you to adjust existing time tracking records in bamboohr.
Edit Current Clock In EntryThis endpoint allows an employee to clock in and record their work start time in the bamboohr time tracking system.
Post employee table row updateUpdates a specific row in a custom table for an individual employee in bamboohr.
Calculate employee time offRetrieves the time off calculator information for a specific employee in bamboohr.
Get employee clock entriesRetrieves a specific clock entry for an employee from the bamboohr time tracking system.
Retrieve company benefit by idRetrieves detailed information about a specific company benefit offered by an organization using bamboohr.
Get employee daily entriesRetrieves a specific daily time tracking entry for an employee in bamboohr.
Get employee goal aggregateRetrieves aggregated performance data for a specific employee's goal within the bamboohr system.
Retrieve company benefitsRetrieves a comprehensive list of company-wide benefits offered by the organization as configured in bamboohr.
Retrieve company benefit typeRetrieves a list of company benefit types available in the specified bamboohr company account.
Retrieve employee benefit filtersRetrieves employee benefit information based on specified filters.
Retrieve meta fields for domainRetrieves metadata about available fields in the bamboohr api for a specific company.
Retrieve meta tables for companydomainRetrieves metadata information about the tables available in the bamboohr system for a specific company.
Retrieve user meta informationRetrieves metadata about users within a specific company's bamboohr instance.
Get whos out for companyRetrieves a list of employees who are currently out of office or on leave within your organization.
Aggregate employee goals by idRetrieves aggregated goal information for a specific employee within a company's bamboohr system.
Aggregate employee goalsRetrieves aggregated performance goal data for a specific employee within a company's bamboohr system.
Aggregate employee goalsRetrieves aggregated information about an employee's goals within the bamboohr performance management system.
Retrieve employee dependents by company domainRetrieves a list of dependents for all employees in the company.
Retrieve file by idRetrieves a specific employee file from the bamboohr system.
Retrieve employee file by idRetrieves a specific file associated with an employee from the bamboohr system.
Fetch employee photo by sizeRetrieves an employee's photo from the bamboohr system in a specified size.
Fetch employee withholding by idRetrieves the withholding information for a specific employee within a company's bamboohr system.
Retrieve employee direct deposit account by idRetrieves detailed information about a specific employee's direct deposit account within a bamboohr company instance.
Fetch employee pay stub by idRetrieves detailed pay stub information for a specific employee within a company's bamboohr system.
Retrieve employee unpaid pay stubs by idRetrieves the unpaid pay stubs for a specific employee within a company's bamboohr account.
Retrieve time tracking record by idRetrieves a specific time tracking record from bamboohr based on the provided company domain and record id.
Fetch application by idRetrieves detailed information about a specific job application from bamboohr's applicant tracking system.
Fetch applications by company domain pathRetrieves a list of applications submitted through the bamboohr applicant tracking system (ats).
Retrieve employee timesheet dataRetrieves a specific timesheet for a given employee within a bamboohr company environment.
Get benefit coverages by company domainRetrieves the benefit coverages information for employees within a specific company in bamboohr.
Get payroll deductions by idRetrieves detailed information about a specific payroll deduction by its id for a given company in bamboohr.
Retrieve all benefits deduction typesRetrieves a comprehensive list of all deduction types configured in the bamboohr system for a specific company.
List benefit group employeesRetrieves a list of employees associated with benefit groups within a specific bamboohr company instance.
Retrieve benefit group plan costsRetrieves the costs associated with benefit group plans for a specific company in bamboohr.
Retrieve benefit group plansRetrieves a list of benefit group plans for a specified company in bamboohr.
Fetch benefit groupsRetrieves a list of benefit groups for a specific company in bamboohr.
Retrieve benefit plan coverage dataRetrieves detailed information about benefit plan coverages for employees within a specific bamboohr company environment.
Retrieve employee plan by idRetrieves detailed information about a specific employee plan within a company's bamboohr system.
Retrieve benefit plans by company domainRetrieves a list of benefit plans available for the specified company in bamboohr.
Retrieve applicant location dataRetrieves a list of locations associated with the applicant tracking system for a specific bamboohr company account.
Fetch report by company domain and idRetrieves a specific report from the bamboohr system for a given company.
Retrieve meta listsRetrieves metadata about reference lists available in a company's bamboohr instance.
Get employee by idRetrieves detailed information for a specific employee within a company's bamboohr system.
Retrieve employee deduction detailsRetrieves detailed information about a specific employee deduction within a bamboohr company account.
Retrieve employee dependent by idRetrieves detailed information about a specific employee's dependent in bamboohr.
Fetch employee directoryRetrieves the employee directory for a specified bamboohr company.
Get employee project assignmentsRetrieves a list of projects assigned to a specific employee within a company's bamboohr account.
Get Employee Table RowsRetrieves specific table data for a given employee from a company's bamboohr instance.
Retrieve employee goal commentsRetrieves comments associated with a specific goal for a particular employee within a company's bamboohr environment.
Retrieve goals for employee performanceRetrieves the performance goals for a specific employee within a company's bamboohr account.
List employee goals filtersRetrieves the available filters for an employee's performance goals in bamboohr.
Retrieve employee goal filtersRetrieves the available filters for an employee's performance goals in bamboohr.
Fetch hiring leads for applicant trackingRetrieves a list of hiring leads from the bamboohr applicant tracking system (ats) for a specified company.
Fetch applicant tracking jobsRetrieves a list of job postings from the company's applicant tracking system (ats) in bamboohr.
Monitor webhook fieldsRetrieves a list of fields currently being monitored for webhook notifications in bamboohr.
Retrieve employee project assignmentsRetrieves a list of time tracking projects assigned to a specific employee within a bamboohr company environment.
Get changed employees by company domainRetrieves a list of employees whose records have been changed in the bamboohr system for a specific company.
Fetch employees changed for tableRetrieves information about changes made to a specific table in the bamboohr system for a given company.
Get webhooks for company domainRetrieves a list of all webhooks configured for a specific company in bamboohr.
Fetch applicant tracking statusesRetrieves a list of all applicant tracking statuses for a specific bamboohr company.
Get employee project tasksRetrieves a list of tasks assigned to a specific employee for a particular project within a company's bamboohr account.
Fetch time off policiesRetrieves metadata about time off policies for a specific company in the bamboohr system.
Get time off requestsRetrieves a list of time off requests for a specific company in the bamboohr system.
Retrieve time off typesRetrieves a list of available time off types for a specific company in bamboohr.
Retrieve timesheet entriesRetrieves timesheet entries for a specific company in bamboohr.
Retrieve timesheets using company domainRetrieves specific timesheet data from the bamboohr time tracking system.
Get webhook by idRetrieves detailed information about a specific webhook registered in the bamboohr system.
Retrieve webhook log by idRetrieves the log entries for a specific webhook in a company's bamboohr instance.
Check employee clockin statusRetrieves the current clock-in status for a specific employee within a company's bamboohr environment.
View company domain filesThe viewfile endpoint allows you to retrieve and view employee files stored in the bamboohr system.
View employee files by idThis endpoint allows you to view a specific file associated with an employee in the bamboohr system.
Retrieve employee training recordRetrieves the training record for a specific employee within a bamboohr company account.
Retrieve employee time off policiesRetrieves the time off policies applicable to a specific employee within a bamboohr company.
Get employee time off policiesRetrieves the time-off policies applicable to a specific employee within a bamboohr company account.
Access training categoryRetrieves all training categories for a specific company in bamboohr.
Fetch training types by domainRetrieves a list of training types configured in the company's bamboohr system.
Update employee table row infoThis endpoint updates a specific row in an employee's table within bamboohr.
Reopen employee goalReopens a previously closed or completed goal for a specific employee in the bamboohr performance management system.
Generate custom report for companyCreates a custom report in bamboohr with specified parameters.
Upload employee photo by idUpdates the photo for a specific employee in the bamboohr system.
Post clock entries for time trackingThe create clock entries endpoint allows you to add or update time tracking entries for employees in the bamboohr system.
Post daily time tracking entriesThe addorupdatedailytimeentries endpoint allows you to create new or update existing daily time entries for employees in the bamboohr time tracking system.
Update company benefit detailsUpdates an existing company benefit in the bamboohr system.
Update employee dependent detailsThe updateemployeedependent endpoint allows you to modify the information of an existing employee dependent in the bamboohr system.
Update company file detailsUpdates an existing company file in bamboohr, allowing modifications to the file's metadata such as name, category, and employee sharing permissions.
Update employee information via idUpdates an employee's basic information in the bamboohr system.
Update employee specific fileUpdates an existing file associated with a specific employee in the bamboohr system.
Update employee training recordThe updateemployeetrainingrecord endpoint allows you to update an existing training record for a specific employee in the bamboohr system.
Update employee goalUpdates an existing employee goal in the bamboohr system.
Update employee goal commentUpdates a specific comment on an employee's goal in bamboohr's performance management system.
Update employee goal progressUpdates the progress of a specific employee's goal in bamboohr.
Share employee goal with othersUpdates the list of employees with whom a specific performance goal is shared in bamboohr.
Update employee goal with milestonesThis endpoint updates an existing employee goal with milestones in the bamboohr performance management system.
Update employee table row by idUpdates a specific row in a table associated with an employee's record in bamboohr.
Update training categoryThis endpoint allows you to update the name of an existing training category in bamboohr.
Update training type by idUpdates an existing training type in the bamboohr system.
Update webhook for company domainUpdates an existing webhook configuration in bamboohr.
Upload file to company domainThis endpoint allows you to upload files to the bamboohr system for a specific company.
Upload employee fileThis endpoint allows you to upload a file to an employee's record in bamboohr.
Post company loginAuthenticates a user with the bamboohr system, initiating a session for subsequent api calls.

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

What is Tool Router?

Composio's Tool Router 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 Tool Router

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

How the Tool Router works

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

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

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

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 { experimental_createMCPClient as 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

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: ["bamboohr"],
  });

  const mcpUrl = session.mcp.url;
What's happening:
  • We're creating a Tool Router session that gives your agent access to Bamboohr 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 Bamboohr-related tools through the MCP protocol

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 Bamboohr tools that the agent can use

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 bamboohr, 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

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 Bamboohr 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 Bamboohr 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 { experimental_createMCPClient as 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: ["bamboohr"],
  });

  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 bamboohr, 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 Bamboohr 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.

How to build Bamboohr MCP Agent with another framework

FAQ

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

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

Can I use Tool Router MCP with Vercel AI SDK?

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

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

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