# How to integrate Shipengine MCP with LlamaIndex

```json
{
  "title": "How to integrate Shipengine MCP with LlamaIndex",
  "toolkit": "Shipengine",
  "toolkit_slug": "shipengine",
  "framework": "LlamaIndex",
  "framework_slug": "llama-index",
  "url": "https://composio.dev/toolkits/shipengine/framework/llama-index",
  "markdown_url": "https://composio.dev/toolkits/shipengine/framework/llama-index.md",
  "updated_at": "2026-05-12T10:25:50.365Z"
}
```

## Introduction

This guide walks you through connecting Shipengine to LlamaIndex using the Composio tool router. By the end, you'll have a working Shipengine agent that can generate shipping label for new order, track status of outgoing packages, validate customer address before shipping through natural language commands.
This guide will help you understand how to give your LlamaIndex agent real control over a Shipengine account through Composio's Shipengine MCP server.
Before we dive in, let's take a quick look at the key ideas and tools involved.

## Also integrate Shipengine with

- [OpenAI Agents SDK](https://composio.dev/toolkits/shipengine/framework/open-ai-agents-sdk)
- [Claude Agent SDK](https://composio.dev/toolkits/shipengine/framework/claude-agents-sdk)
- [Claude Code](https://composio.dev/toolkits/shipengine/framework/claude-code)
- [Claude Cowork](https://composio.dev/toolkits/shipengine/framework/claude-cowork)
- [Codex](https://composio.dev/toolkits/shipengine/framework/codex)
- [OpenClaw](https://composio.dev/toolkits/shipengine/framework/openclaw)
- [Hermes](https://composio.dev/toolkits/shipengine/framework/hermes-agent)
- [CLI](https://composio.dev/toolkits/shipengine/framework/cli)
- [Google ADK](https://composio.dev/toolkits/shipengine/framework/google-adk)
- [LangChain](https://composio.dev/toolkits/shipengine/framework/langchain)
- [Vercel AI SDK](https://composio.dev/toolkits/shipengine/framework/ai-sdk)
- [Mastra AI](https://composio.dev/toolkits/shipengine/framework/mastra-ai)
- [CrewAI](https://composio.dev/toolkits/shipengine/framework/crew-ai)

## TL;DR

Here's what you'll learn:
- Set your OpenAI and Composio API keys
- Install LlamaIndex and Composio packages
- Create a Composio Tool Router session for Shipengine
- Connect LlamaIndex to the Shipengine MCP server
- Build a Shipengine-powered agent using LlamaIndex
- Interact with Shipengine through natural language

## What is LlamaIndex?

LlamaIndex is a data framework for building LLM applications. It provides tools for connecting LLMs to external data sources and services through agents and tools.
Key features include:
- ReAct Agent: Reasoning and acting pattern for tool-using agents
- MCP Tools: Native support for Model Context Protocol
- Context Management: Maintain conversation context across interactions
- Async Support: Built for async/await patterns

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

The Shipengine MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Shipengine account. It provides structured and secure access to your shipping operations, so your agent can perform actions like generating shipping labels, tracking packages, validating addresses, and managing carrier integrations on your behalf.
- Automated label creation and management: Instantly generate, purchase, and void shipping labels across multiple carriers, letting your agent streamline fulfillment without manual entry.
- Real-time package tracking: Ask your agent to track shipments by carrier or tracking number to get up-to-date delivery statuses and shipment histories.
- Address validation and correction: Have your agent validate and standardize shipment addresses to prevent delivery errors and reduce returns.
- Carrier rate comparison: Enable your agent to fetch and compare real-time shipping rates from all connected carriers, helping you save on delivery costs.
- Shipping manifest and batch processing: Let your agent generate manifests or process batches of shipments in a single command, making high-volume shipping fast and efficient.

## Supported Tools

| Tool slug | Name | Description |
|---|---|---|
| `SHIPENGINE_ADD_TAG_TO_SHIPMENT` | Add Tag to Shipment | Tool to add a tag to a shipment for organization and filtering. Use when you need to categorize or label a shipment. |
| `SHIPENGINE_ADD_TO_BATCH` | Add to Batch | Tool to add shipments or rate IDs to an existing batch. Use when you need to add items to a batch after the batch has been created. At least one of shipment_ids or rate_ids must be provided. |
| `SHIPENGINE_CANCEL_SHIPMENT` | Cancel Shipment | Tool to cancel a shipment by ID. Use when you need to cancel a shipment that has been created but not yet shipped. Note that once a shipment is in transit, it may not be cancellable depending on carrier policies. |
| `SHIPENGINE_CONNECT_LTL_CARRIER` | Connect LTL Carrier | Tool to connect an LTL carrier account to ShipEngine. Use when you need to add an LTL carrier connection for freight shipping. For sandbox testing, use carrier codes TEST, WARN, or FAIL with empty credentials {}. |
| `SHIPENGINE_CONNECT_SHIPSURANCE` | Connect Shipsurance Account | Tool to connect a Shipsurance insurance account to ShipEngine. Use when you need to integrate a Shipsurance policy for insurance coverage on shipments. |
| `SHIPENGINE_CREATE_ACCOUNT_IMAGE` | Create Account Image | Tool to create a new account image in ShipEngine. Use when uploading a logo or image for use on shipping labels. |
| `SHIPENGINE_CREATE_PACKAGE_TYPE` | Create Package Type | Tool to create a custom package type definition in ShipEngine. Use when defining new package types with specific codes and optional dimensions. |
| `SHIPENGINE_CREATE_TAG` | Create Tag | Tool to create a new tag in ShipEngine. Use after determining the desired tag name for shipments. |
| `SHIPENGINE_CREATE_TAG2` | Create Tag 2 | Tool to create a new tag for organizing shipments. Use when you need to create a tag by specifying the tag name in the URL path. |
| `SHIPENGINE_CREATE_WAREHOUSE` | Create Warehouse | Tool to create a new warehouse. Use when adding a new inventory location after verifying its full address details. |
| `SHIPENGINE_CREATE_WEBHOOK` | Create Webhook | Tool to create a ShipEngine webhook. Use when you need to register a webhook for specific events. Use after confirming your event-handling endpoint is ready. |
| `SHIPENGINE_DELETE_ACCOUNT_IMAGE_BY_ID` | Delete Account Image by ID | Tool to delete a ShipEngine account image by its ID. Use when you need to remove an image from account settings. The image will be permanently removed from the account. |
| `SHIPENGINE_DELETE_BATCH` | Delete Batch | Tool to delete a batch by ID. Use when you need to remove a batch from ShipEngine. Note that this operation is destructive and cannot be undone. |
| `SHIPENGINE_DELETE_PACKAGE` | Delete Package | Tool to delete a custom package type by ID. Use when removing package types that are no longer needed. |
| `SHIPENGINE_DELETE_WAREHOUSE` | Delete Warehouse | Tool to delete a warehouse from your ShipEngine account. Use when you need to remove a warehouse that is no longer needed. The warehouse will be permanently removed from your account. |
| `SHIPENGINE_DELETE_WEBHOOK` | Delete Webhook | Tool to delete a ShipEngine webhook subscription. Use when you need to remove a webhook that is no longer needed. The webhook will be permanently removed and will no longer receive event notifications. |
| `SHIPENGINE_DISCONNECT_CARRIER` | Disconnect Carrier | Tool to disconnect a carrier account from ShipEngine. Use when you need to remove a carrier connection from your ShipEngine account. |
| `SHIPENGINE_DISCONNECT_SHIPSURANCE` | Disconnect Shipsurance | Tool to disconnect a Shipsurance insurance account from ShipEngine. Use when you need to remove the Shipsurance integration. |
| `SHIPENGINE_DOWNLOAD_FILE` | Download File | Tool to download a file from ShipEngine. Use when you need to retrieve a label PDF or other document from the ShipEngine downloads endpoint. |
| `SHIPENGINE_GET_ACCOUNT_IMAGE_BY_ID` | Get Account Image by ID | Tool to retrieve account image settings by label image ID. Use when you need to fetch image data for labels or display account branding information. |
| `SHIPENGINE_GET_BATCH_BY_EXTERNAL_ID` | Get Batch by External ID | Tool to retrieve batch details using an external batch ID. Use when you need to look up a batch by its client-assigned external identifier rather than ShipEngine's internal batch ID. |
| `SHIPENGINE_GET_BATCH_BY_ID` | Get Batch by ID | Tool to retrieve detailed information about a specific batch by its ID. Use when you need to check batch status, download labels, or view errors. |
| `SHIPENGINE_GET_BATCH_ERRORS` | Get Batch Errors | Tool to retrieve errors that occurred during batch processing. Use when you need to investigate or troubleshoot issues with a specific batch. |
| `SHIPENGINE_GET_BULK_RATES` | Get Bulk Rates | Tool to get shipping rates for multiple shipments in a single request. Use when you need to compare rates across multiple carriers or shipments efficiently. The request is processed asynchronously - use the returned rate_request_id to retrieve the actual rates once processing is complete. |
| `SHIPENGINE_GET_INSURANCE_BALANCE` | Get Insurance Balance | Tool to retrieve the current Shipsurance insurance funds balance. Use when you need to check available insurance balance before purchasing shipment insurance. |
| `SHIPENGINE_GET_LTL_CARRIER_CREDENTIAL_REQUIREMENTS` | Get LTL Carrier Credential Requirements | Tool to retrieve credential requirements for connecting an LTL carrier. Use when you need to discover what credentials (e.g., account number, username, password) are required before connecting a specific LTL carrier. |
| `SHIPENGINE_GET_LTL_CARRIER_FEATURES` | Get LTL Carrier Features | Tool to retrieve features supported by an LTL carrier. Use when you need to discover what capabilities (e.g., tracking, quotes, scheduled pickups) are available for a specific LTL carrier before creating shipments. |
| `SHIPENGINE_GET_LTL_CARRIER_OPTIONS` | Get LTL Carrier Options | Tool to list available options/accessorials for an LTL carrier. Use when you need to discover what accessorial services (e.g., hazardous material, inside pickup, lift gate) are available for a specific LTL carrier connection. |
| `SHIPENGINE_GET_LTL_CARRIER_PACKAGES` | Get LTL Carrier Packages | Tool to list available package/handling unit types for an LTL (Less Than Truckload) carrier. Use when you need to find valid package codes for LTL freight shipments. |
| `SHIPENGINE_GET_LTL_CARRIER_SERVICES` | Get LTL Carrier Services | Tool to list available services for an LTL carrier. Use when you need to discover what shipping services (e.g., standard, guaranteed morning/noon) are available for a specific LTL carrier connection. |
| `SHIPENGINE_GET_PACKAGE_BY_ID` | Get Package by ID | Tool to get details of a specific custom package type by ID. Use when you need to retrieve package specifications. |
| `SHIPENGINE_GET_SHIPMENT_BY_EXTERNAL_ID` | Get Shipment by External ID | Tool to retrieve shipment details using an external shipment ID. Use when you need to look up a shipment by its client-assigned external identifier rather than ShipEngine's internal shipment ID. |
| `SHIPENGINE_GET_SHIPMENT_BY_ID` | Get Shipment by ID | Tool to retrieve a shipment by ID. Use when you need detailed shipment information after creation. |
| `SHIPENGINE_GET_SHIPMENT_RATES` | Get Shipment Rates | Tool to retrieve shipping rates for an existing shipment. Use when you need to get rate quotes for a shipment that has already been created. |
| `SHIPENGINE_GET_TRACKING_INFO` | Get Tracking Information | Tool to retrieve tracking information for a shipment. Use when you need to track the status and location of a package using its tracking number and carrier code. |
| `SHIPENGINE_GET_WAREHOUSE_BY_ID` | Get Warehouse by ID | Tool to retrieve details of a specific warehouse by ID. Use when you need warehouse information including addresses and default status. |
| `SHIPENGINE_GET_WEBHOOK_BY_ID` | Get Webhook by ID | Tool to retrieve details of a specific webhook by ID. Use when you need to view the configuration of an existing webhook. |
| `SHIPENGINE_LIST_ACCOUNT_IMAGES` | List Account Images | Tool to list all account images. Use when you need to retrieve all images configured for the ShipEngine account, such as logos or branding images used on shipping labels. |
| `SHIPENGINE_LIST_ACCOUNT_SETTINGS` | List Account Settings | Tool to list all account settings for the ShipEngine account. Use when you need to retrieve account configuration, preferences, or settings information. |
| `SHIPENGINE_LIST_BATCHES2` | List Batches (v2) | Tool to list all batches with comprehensive filtering options. Use when you need to retrieve batches with filters for status, creation/processing dates, batch number, or pagination. |
| `SHIPENGINE_LIST_CARRIER_PACKAGE_TYPES` | List Carrier Package Types | Tool to list all available package types for a specific carrier. Use when you need to find valid package_code values before creating shipments. |
| `SHIPENGINE_LIST_LABELS2` | List Labels (Extended) | Tool to list all shipping labels with comprehensive filtering options. Use when you need to retrieve labels with filters like status, carrier, tracking number, batch, or date ranges. Supports sorting and pagination. |
| `SHIPENGINE_LIST_LTL_CARRIERS` | List LTL Carriers | Tool to list all LTL (Less-Than-Truckload) carrier accounts connected to your ShipEngine account. Use when you need to discover available LTL carriers, their services, container types, and accessorial services before creating LTL shipments. |
| `SHIPENGINE_LIST_MANIFESTS2` | List Manifests (Advanced) | Tool to list all manifests with optional filtering by warehouse and carrier. Use when you need to retrieve manifests with advanced filtering options. |
| `SHIPENGINE_LIST_PACKAGES` | List Packages | Tool to list all package types. Use when selecting package options before shipment creation. |
| `SHIPENGINE_LIST_PICKUPS` | List Scheduled Pickups | Tool to list all scheduled pickups with optional filters. Use when you need to retrieve scheduled pickups with pagination support. |
| `SHIPENGINE_LIST_SHIPMENTS2` | List Shipments (v2) | Tool to list all shipments with optional filtering parameters. Use when you need to retrieve shipments with filters like status, batch, tags, or date ranges. |
| `SHIPENGINE_LIST_TAGS2` | List Tags (v2) | Tool to list all tags in your account. Use when you need to retrieve all available tags for display or selection purposes. |
| `SHIPENGINE_LIST_WAREHOUSES` | List Warehouses | Tool to list all warehouses. Use when you need to retrieve warehouse locations with pagination. Call after creating or updating warehouses. |
| `SHIPENGINE_LIST_WEBHOOK_EVENTS` | List Webhook Events | Retrieve a list of available webhook event types supported by ShipEngine. Returns static documentation of all supported webhook events that can be used when creating webhooks. Always call this before SHIPENGINE_CREATE_WEBHOOK to obtain valid event type names — unsupported or mistyped event names result in no callbacks being received. Note: This is based on ShipEngine's documented event types as there is no API endpoint for listing events. |
| `SHIPENGINE_LIST_WEBHOOKS` | List Webhooks | Tool to list all webhooks configured on your account. Use when you need to view all registered webhooks. |
| `SHIPENGINE_PARSE_ADDRESS` | Parse Address | Tool to parse unstructured address text and extract structured address components. Use when you have raw address text and need to extract individual fields like street, city, state, and postal code. |
| `SHIPENGINE_PROCESS_BATCH_LABELS` | Process Batch Labels | Tool to process a batch to create and purchase shipping labels for all shipments in the batch. Use after creating a batch with shipments. The API returns HTTP 204 on success. |
| `SHIPENGINE_REMOVE_FROM_BATCH` | Remove From Batch | Tool to remove shipments or rate IDs from a batch. Use when you need to modify batch contents by removing specific shipments or rates. At least one of shipment_ids or rate_ids must be provided. |
| `SHIPENGINE_REMOVE_TAG_FROM_SHIPMENT` | Remove Tag from Shipment | Tool to remove a tag from a shipment. Use when you need to un-categorize or remove a specific tag from an existing shipment. |
| `SHIPENGINE_START_TRACKING` | Start Tracking Package | Tool to subscribe to tracking updates for a package via webhooks. Use when you need to start monitoring a shipment's status. The package tracking information will be sent to configured webhooks when updates occur. |
| `SHIPENGINE_STOP_TRACKING` | Stop Tracking Package | Tool to unsubscribe from tracking updates for a package. Use when you no longer need to receive tracking notifications for a specific shipment. Once stopped, you will not receive further tracking updates for this package. |
| `SHIPENGINE_TRACK_LTL_SHIPMENT` | Track LTL Shipment | Tool to track an LTL shipment using carrier code and PRO number. Use when you need to retrieve real-time tracking information for an LTL shipment, including current status, delivery dates, and event history. |
| `SHIPENGINE_UPDATE_ACCOUNT_IMAGE_BY_ID` | Update Account Image By ID | Tool to update an account image by ID in ShipEngine. Use when modifying image properties like name or default status. |
| `SHIPENGINE_UPDATE_LTL_CONNECTION` | Update LTL Connection | Tool to update LTL carrier connection credentials in ShipEngine. Use when you need to modify authentication credentials for an existing LTL carrier connection without disconnecting and reconnecting. You must provide all credential properties for the carrier, not just the property you wish to update. |
| `SHIPENGINE_UPDATE_PACKAGE` | Update Package Type | Tool to update an existing custom package type definition. Use when modifying package details such as name, code, description, or dimensions. |
| `SHIPENGINE_UPDATE_SHIPMENT` | Update Shipment | Tool to update an existing shipment's details. Use when you need to modify shipment information such as addresses, packages, weight, or carrier options before creating a label. |
| `SHIPENGINE_UPDATE_SHIPMENTS_TAGS` | Update Shipments Tags | Tool to update tags on one or more shipments in bulk. Use when you need to assign existing tags to shipments. Tags must be created before assignment using the Create Tag action. |
| `SHIPENGINE_UPDATE_WAREHOUSE` | Update Warehouse | Tool to update an existing warehouse's details and address. Use when modifying warehouse information such as name, origin address, return address, or default status. |
| `SHIPENGINE_UPDATE_WEBHOOK` | Update Webhook | Tool to update a ShipEngine webhook. Use when you need to modify webhook URL, name, headers, or store association. Returns success on 204 status code. |
| `SHIPENGINE_VALIDATE_ADDRESS` | Validate Address | Tool to validate and normalize shipping addresses. Use after collecting raw addresses to ensure they are correct and standardized before shipping. |

## Supported Triggers

None listed.

## Creating MCP Server - Stand-alone vs Composio SDK

The Shipengine MCP server is an implementation of the Model Context Protocol that connects your AI agent to Shipengine. It provides structured and secure access so your agent can perform Shipengine operations on your behalf through a secure, permission-based interface.
With Composio's managed implementation, you don't have to create your own developer app. For production, if you're building an end product, we recommend using your own credentials. The managed server helps you prototype fast and go from 0-1 faster.

## Step-by-step Guide

### 1. Prerequisites

Before you begin, make sure you have:
- Python 3.8/Node 16 or higher installed
- A Composio account with the API key
- An OpenAI API key
- A Shipengine account and project
- Basic familiarity with async Python/Typescript

### 1. Getting API Keys for OpenAI, Composio, and Shipengine

No description provided.

### 2. Installing dependencies

No description provided.
```python
pip install composio-llamaindex llama-index llama-index-llms-openai llama-index-tools-mcp python-dotenv
```

```typescript
npm install @composio/llamaindex @llamaindex/openai @llamaindex/tools @llamaindex/workflow dotenv
```

### 3. Set environment variables

Create a .env file in your project root:
These credentials will be used to:
- Authenticate with OpenAI's GPT-5 model
- Connect to Composio's Tool Router
- Identify your Composio user session for Shipengine access
```bash
OPENAI_API_KEY=your-openai-api-key
COMPOSIO_API_KEY=your-composio-api-key
COMPOSIO_USER_ID=your-user-id
```

### 4. Import modules

No description provided.
```python
import asyncio
import os
import dotenv

from composio import Composio
from composio_llamaindex import LlamaIndexProvider
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.workflow import Context
from llama_index.llms.openai import OpenAI
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

dotenv.load_dotenv()
```

```typescript
import "dotenv/config";
import readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { Composio } from "@composio/core";

import { mcp } from "@llamaindex/tools";
import { agent as createAgent } from "@llamaindex/workflow";
import { openai } from "@llamaindex/openai";

dotenv.config();
```

### 5. Load environment variables and initialize Composio

No description provided.
```python
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
COMPOSIO_USER_ID = os.getenv("COMPOSIO_USER_ID")

if not OPENAI_API_KEY:
    raise ValueError("OPENAI_API_KEY is not set in the environment")
if not COMPOSIO_API_KEY:
    raise ValueError("COMPOSIO_API_KEY is not set in the environment")
if not COMPOSIO_USER_ID:
    raise ValueError("COMPOSIO_USER_ID is not set in the environment")
```

```typescript
const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const COMPOSIO_API_KEY = process.env.COMPOSIO_API_KEY;
const COMPOSIO_USER_ID = process.env.COMPOSIO_USER_ID;

if (!OPENAI_API_KEY) throw new Error("OPENAI_API_KEY is not set");
if (!COMPOSIO_API_KEY) throw new Error("COMPOSIO_API_KEY is not set");
if (!COMPOSIO_USER_ID) throw new Error("COMPOSIO_USER_ID is not set");
```

### 6. Create a Tool Router session and build the agent function

What's happening here:
- We create a Composio client using your API key and configure it with the LlamaIndex provider
- We then create a tool router MCP session for your user, specifying the toolkits we want to use (in this case, shipengine)
- The session returns an MCP HTTP endpoint URL that acts as a gateway to all your configured tools
- LlamaIndex will connect to this endpoint to dynamically discover and use the available Shipengine tools.
- The MCP tools are mapped to LlamaIndex-compatible tools and plug them into the Agent.
```python
async def build_agent() -> ReActAgent:
    composio_client = Composio(
        api_key=COMPOSIO_API_KEY,
        provider=LlamaIndexProvider(),
    )

    session = composio_client.create(
        user_id=COMPOSIO_USER_ID,
        toolkits=["shipengine"],
    )

    mcp_url = session.mcp.url
    print(f"Composio MCP URL: {mcp_url}")

    mcp_client = BasicMCPClient(mcp_url, headers={"x-api-key": COMPOSIO_API_KEY})
    mcp_tool_spec = McpToolSpec(client=mcp_client)
    tools = await mcp_tool_spec.to_tool_list_async()

    llm = OpenAI(model="gpt-5")

    description = "An agent that uses Composio Tool Router MCP tools to perform Shipengine actions."
    system_prompt = """
    You are a helpful assistant connected to Composio Tool Router.
    Use the available tools to answer user queries and perform Shipengine actions.
    """
    return ReActAgent(tools=tools, llm=llm, description=description, system_prompt=system_prompt, verbose=True)
```

```typescript
async function buildAgent() {

  console.log(`Initializing Composio client...${COMPOSIO_USER_ID!}...`);
  console.log(`COMPOSIO_USER_ID: ${COMPOSIO_USER_ID!}...`);

  const composio = new Composio({
    apiKey: COMPOSIO_API_KEY,
    provider: new LlamaindexProvider(),
  });

  const session = await composio.create(
    COMPOSIO_USER_ID!,
    {
      toolkits: ["shipengine"],
    },
  );

  const mcpUrl = session.mcp.url;
  console.log(`Composio Tool Router MCP URL: ${mcpUrl}`);

  const server = mcp({
    url: mcpUrl,
    clientName: "composio_tool_router_with_llamaindex",
    requestInit: {
      headers: {
        "x-api-key": COMPOSIO_API_KEY!,
      },
    },
    // verbose: true,
  });

  const tools = await server.tools();

  const llm = openai({ apiKey: OPENAI_API_KEY, model: "gpt-5" });

  const agent = createAgent({
    name: "composio_tool_router_with_llamaindex",
        description : "An agent that uses Composio Tool Router MCP tools to perform actions.",
    systemPrompt:
      "You are a helpful assistant connected to Composio Tool Router."+
"Use the available tools to answer user queries and perform Shipengine actions." ,
    llm,
    tools,
  });

  return agent;
}
```

### 7. Create an interactive chat loop

No description provided.
```python
async def chat_loop(agent: ReActAgent) -> None:
    ctx = Context(agent)
    print("Type 'quit', 'exit', or Ctrl+C to stop.")

    while True:
        try:
            user_input = input("\nYou: ").strip()
        except (KeyboardInterrupt, EOFError):
            print("\nBye!")
            break

        if not user_input or user_input.lower() in {"quit", "exit"}:
            print("Bye!")
            break

        try:
            print("Agent: ", end="", flush=True)
            handler = agent.run(user_input, ctx=ctx)

            async for event in handler.stream_events():
                # Stream token-by-token from LLM responses
                if hasattr(event, "delta") and event.delta:
                    print(event.delta, end="", flush=True)
                # Show tool calls as they happen
                elif hasattr(event, "tool_name"):
                    print(f"\n[Using tool: {event.tool_name}]", flush=True)

            # Get final response
            response = await handler
            print()  # Newline after streaming
        except KeyboardInterrupt:
            print("\n[Interrupted]")
            continue
        except Exception as e:
            print(f"\nError: {e}")
```

```typescript
async function chatLoop(agent: ReturnType<typeof createAgent>) {
  const rl = readline.createInterface({ input, output });

  console.log("Type 'quit' or 'exit' to stop.");

  while (true) {
    let userInput: string;

    try {
      userInput = (await rl.question("\nYou: ")).trim();
    } catch {
      console.log("\nAgent: Bye!");
      break;
    }

    if (!userInput) {
      continue;
    }

    const lower = userInput.toLowerCase();
    if (lower === "quit" || lower === "exit") {
      console.log("Agent: Bye!");
      break;
    }

    try {
      process.stdout.write("Agent: ");

      const stream = agent.runStream(userInput);
      let finalResult: any = null;

      for await (const event of stream) {
        // The event.data contains the streamed content
        const data: any = event.data;

        // Check for streaming delta content
        if (data?.delta) {
          process.stdout.write(data.delta);
        }

        // Store final result for fallback
        if (data?.result || data?.message) {
          finalResult = data;
        }
      }

      // If no streaming happened, show the final result
      if (finalResult) {
        const answer =
          finalResult.result ??
          finalResult.message?.content ??
          finalResult.message ??
          "";
        if (answer && typeof answer === "string" && !answer.includes("[object")) {
          process.stdout.write(answer);
        }
      }

      console.log(); // New line after streaming completes
    } catch (err: any) {
      console.error("\nAgent error:", err?.message ?? err);
    }
  }

  rl.close();
}
```

### 8. Define the main entry point

What's happening here:
- We're orchestrating the entire application flow
- The agent gets built with proper error handling
- Then we kick off the interactive chat loop so you can start talking to Shipengine
```python
async def main() -> None:
    agent = await build_agent()
    await chat_loop(agent)

if __name__ == "__main__":
    # Handle Ctrl+C gracefully
    signal.signal(signal.SIGINT, lambda s, f: (print("\nBye!"), exit(0)))
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nBye!")
```

```typescript
async function main() {
  try {
    const agent = await buildAgent();
    await chatLoop(agent);
  } catch (err) {
    console.error("Failed to start agent:", err);
    process.exit(1);
  }
}

main();
```

### 9. Run the agent

When prompted, authenticate and authorise your agent with Shipengine, then start asking questions.
```bash
python llamaindex_agent.py
```

```typescript
npx ts-node llamaindex-agent.ts
```

## Complete Code

```python
import asyncio
import os
import signal
import dotenv

from composio import Composio
from composio_llamaindex import LlamaIndexProvider
from llama_index.core.agent.workflow import ReActAgent
from llama_index.core.workflow import Context
from llama_index.llms.openai import OpenAI
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec

dotenv.load_dotenv()

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
COMPOSIO_API_KEY = os.getenv("COMPOSIO_API_KEY")
COMPOSIO_USER_ID = os.getenv("COMPOSIO_USER_ID")

if not OPENAI_API_KEY:
    raise ValueError("OPENAI_API_KEY is not set")
if not COMPOSIO_API_KEY:
    raise ValueError("COMPOSIO_API_KEY is not set")
if not COMPOSIO_USER_ID:
    raise ValueError("COMPOSIO_USER_ID is not set")

async def build_agent() -> ReActAgent:
    composio_client = Composio(
        api_key=COMPOSIO_API_KEY,
        provider=LlamaIndexProvider(),
    )

    session = composio_client.create(
        user_id=COMPOSIO_USER_ID,
        toolkits=["shipengine"],
    )

    mcp_url = session.mcp.url
    print(f"Composio MCP URL: {mcp_url}")

    mcp_client = BasicMCPClient(mcp_url, headers={"x-api-key": COMPOSIO_API_KEY})
    mcp_tool_spec = McpToolSpec(client=mcp_client)
    tools = await mcp_tool_spec.to_tool_list_async()

    llm = OpenAI(model="gpt-5")
    description = "An agent that uses Composio Tool Router MCP tools to perform Shipengine actions."
    system_prompt = """
    You are a helpful assistant connected to Composio Tool Router.
    Use the available tools to answer user queries and perform Shipengine actions.
    """
    return ReActAgent(
        tools=tools,
        llm=llm,
        description=description,
        system_prompt=system_prompt,
        verbose=True,
    );

async def chat_loop(agent: ReActAgent) -> None:
    ctx = Context(agent)
    print("Type 'quit', 'exit', or Ctrl+C to stop.")

    while True:
        try:
            user_input = input("\nYou: ").strip()
        except (KeyboardInterrupt, EOFError):
            print("\nBye!")
            break

        if not user_input or user_input.lower() in {"quit", "exit"}:
            print("Bye!")
            break

        try:
            print("Agent: ", end="", flush=True)
            handler = agent.run(user_input, ctx=ctx)

            async for event in handler.stream_events():
                # Stream token-by-token from LLM responses
                if hasattr(event, "delta") and event.delta:
                    print(event.delta, end="", flush=True)
                # Show tool calls as they happen
                elif hasattr(event, "tool_name"):
                    print(f"\n[Using tool: {event.tool_name}]", flush=True)

            # Get final response
            response = await handler
            print()  # Newline after streaming
        except KeyboardInterrupt:
            print("\n[Interrupted]")
            continue
        except Exception as e:
            print(f"\nError: {e}")

async def main() -> None:
    agent = await build_agent()
    await chat_loop(agent)

if __name__ == "__main__":
    # Handle Ctrl+C gracefully
    signal.signal(signal.SIGINT, lambda s, f: (print("\nBye!"), exit(0)))
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        print("\nBye!")
```

```typescript
import "dotenv/config";
import readline from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

import { Composio } from "@composio/core";
import { LlamaindexProvider } from "@composio/llamaindex";

import { mcp } from "@llamaindex/tools";
import { agent as createAgent } from "@llamaindex/workflow";
import { openai } from "@llamaindex/openai";

dotenv.config();

const OPENAI_API_KEY = process.env.OPENAI_API_KEY;
const COMPOSIO_API_KEY = process.env.COMPOSIO_API_KEY;
const COMPOSIO_USER_ID = process.env.COMPOSIO_USER_ID;

if (!OPENAI_API_KEY) {
    throw new Error("OPENAI_API_KEY is not set in the environment");
  }
if (!COMPOSIO_API_KEY) {
    throw new Error("COMPOSIO_API_KEY is not set in the environment");
  }
if (!COMPOSIO_USER_ID) {
    throw new Error("COMPOSIO_USER_ID is not set in the environment");
  }

async function buildAgent() {

  console.log(`Initializing Composio client...${COMPOSIO_USER_ID!}...`);
  console.log(`COMPOSIO_USER_ID: ${COMPOSIO_USER_ID!}...`);

  const composio = new Composio({
    apiKey: COMPOSIO_API_KEY,
    provider: new LlamaindexProvider(),
  });

  const session = await composio.create(
    COMPOSIO_USER_ID!,
    {
      toolkits: ["shipengine"],
    },
  );

  const mcpUrl = session.mcp.url;
  console.log(`Composio Tool Router MCP URL: ${mcpUrl}`);

  const server = mcp({
    url: mcpUrl,
    clientName: "composio_tool_router_with_llamaindex",
    requestInit: {
      headers: {
        "x-api-key": COMPOSIO_API_KEY!,
      },
    },
    // verbose: true,
  });

  const tools = await server.tools();

  const llm = openai({ apiKey: OPENAI_API_KEY, model: "gpt-5" });

  const agent = createAgent({
    name: "composio_tool_router_with_llamaindex",
    description:
      "An agent that uses Composio Tool Router MCP tools to perform actions.",
    systemPrompt:
      "You are a helpful assistant connected to Composio Tool Router."+
"Use the available tools to answer user queries and perform Shipengine actions." ,
    llm,
    tools,
  });

  return agent;
}

async function chatLoop(agent: ReturnType<typeof createAgent>) {
  const rl = readline.createInterface({ input, output });

  console.log("Type 'quit' or 'exit' to stop.");

  while (true) {
    let userInput: string;

    try {
      userInput = (await rl.question("\nYou: ")).trim();
    } catch {
      console.log("\nAgent: Bye!");
      break;
    }

    if (!userInput) {
      continue;
    }

    const lower = userInput.toLowerCase();
    if (lower === "quit" || lower === "exit") {
      console.log("Agent: Bye!");
      break;
    }

    try {
      process.stdout.write("Agent: ");

      const stream = agent.runStream(userInput);
      let finalResult: any = null;

      for await (const event of stream) {
        // The event.data contains the streamed content
        const data: any = event.data;

        // Check for streaming delta content
        if (data?.delta) {
          process.stdout.write(data.delta);
        }

        // Store final result for fallback
        if (data?.result || data?.message) {
          finalResult = data;
        }
      }

      // If no streaming happened, show the final result
      if (finalResult) {
        const answer =
          finalResult.result ??
          finalResult.message?.content ??
          finalResult.message ??
          "";
        if (answer && typeof answer === "string" && !answer.includes("[object")) {
          process.stdout.write(answer);
        }
      }

      console.log(); // New line after streaming completes
    } catch (err: any) {
      console.error("\nAgent error:", err?.message ?? err);
    }
  }

  rl.close();
}

async function main() {
  try {
    const agent = await buildAgent();
    await chatLoop(agent);
  } catch (err: any) {
    console.error("Failed to start agent:", err?.message ?? err);
    process.exit(1);
  }
}

main();
```

## Conclusion

You've successfully connected Shipengine to LlamaIndex through Composio's Tool Router MCP layer.
Key takeaways:
- Tool Router dynamically exposes Shipengine tools through an MCP endpoint
- LlamaIndex's ReActAgent handles reasoning and orchestration; Composio handles integrations
- The agent becomes more capable without increasing prompt size
- Async Python provides clean, efficient execution of agent workflows
You can easily extend this to other toolkits like Gmail, Notion, Stripe, GitHub, and more by adding them to the toolkits parameter.

## How to build Shipengine MCP Agent with another framework

- [OpenAI Agents SDK](https://composio.dev/toolkits/shipengine/framework/open-ai-agents-sdk)
- [Claude Agent SDK](https://composio.dev/toolkits/shipengine/framework/claude-agents-sdk)
- [Claude Code](https://composio.dev/toolkits/shipengine/framework/claude-code)
- [Claude Cowork](https://composio.dev/toolkits/shipengine/framework/claude-cowork)
- [Codex](https://composio.dev/toolkits/shipengine/framework/codex)
- [OpenClaw](https://composio.dev/toolkits/shipengine/framework/openclaw)
- [Hermes](https://composio.dev/toolkits/shipengine/framework/hermes-agent)
- [CLI](https://composio.dev/toolkits/shipengine/framework/cli)
- [Google ADK](https://composio.dev/toolkits/shipengine/framework/google-adk)
- [LangChain](https://composio.dev/toolkits/shipengine/framework/langchain)
- [Vercel AI SDK](https://composio.dev/toolkits/shipengine/framework/ai-sdk)
- [Mastra AI](https://composio.dev/toolkits/shipengine/framework/mastra-ai)
- [CrewAI](https://composio.dev/toolkits/shipengine/framework/crew-ai)

## Related Toolkits

- [Addresszen](https://composio.dev/toolkits/addresszen) - Addresszen is a real-time address autocomplete and verification service. It helps capture accurate, deliverable addresses with instant suggestions and validation.
- [Asin data api](https://composio.dev/toolkits/asin_data_api) - Asin data api gives you detailed, real-time product data from Amazon, including price, rank, and reviews. Perfect for e-commerce pros and data-driven marketers who need instant marketplace insights.
- [Baselinker](https://composio.dev/toolkits/baselinker) - BaseLinker is an all-in-one e-commerce management platform connecting stores, marketplaces, carriers, and more. It streamlines order processing, inventory control, and automates your sales operations.
- [Bestbuy](https://composio.dev/toolkits/bestbuy) - Best Buy is a leading retailer offering APIs for product, store, and recommendation data. Instantly access up-to-date retail insights for smarter shopping and decision-making.
- [Btcpay server](https://composio.dev/toolkits/btcpay_server) - BTCPay Server is a free, open-source, self-hosted Bitcoin payment processor. It lets merchants accept Bitcoin payments directly, cutting out middlemen and boosting privacy.
- [Cdr platform](https://composio.dev/toolkits/cdr_platform) - Cdr platform is an API for purchasing carbon dioxide removal services. It enables businesses to offset emissions by accessing verified carbon removal projects.
- [Cloudcart](https://composio.dev/toolkits/cloudcart) - CloudCart is an e-commerce platform for building and managing online stores. It helps businesses streamline product listings, orders, and customer engagement.
- [Countdown api](https://composio.dev/toolkits/countdown_api) - Countdown API gives you real-time, structured eBay product data, reviews, and seller feedback. Perfect for powering price monitoring, product research, or marketplace analytics workflows.
- [Dpd2](https://composio.dev/toolkits/dpd2) - Dpd2 is a robust email management platform for handling, sorting, and automating email workflows. Streamline your communications and boost productivity with advanced sorting, labeling, and response tools.
- [Finerworks](https://composio.dev/toolkits/finerworks) - FinerWorks is an online platform for fine art and photo printing services. Artists and photographers use it to order custom prints and manage print inventory efficiently.
- [Fingertip](https://composio.dev/toolkits/fingertip) - Fingertip is a business management platform for selling, booking, and customer engagement—all from a single link. It helps businesses streamline operations and connect with customers across social channels.
- [Fraudlabs pro](https://composio.dev/toolkits/fraudlabs_pro) - FraudLabs Pro is an online payment fraud detection service for e-commerce and merchants. It helps minimize chargebacks and revenue loss by detecting and preventing fraudulent transactions.
- [Gift up](https://composio.dev/toolkits/gift_up) - Gift Up! is a digital platform for selling, managing, and redeeming gift cards online. It streamlines promotions and gift card transactions for businesses and their customers.
- [Goody](https://composio.dev/toolkits/goody) - Goody is a gifting platform that lets users send gifts and physical products without handling logistics. It streamlines gifting by managing delivery, fulfillment, and recipient experience.
- [Gumroad](https://composio.dev/toolkits/gumroad) - Gumroad is a platform for selling digital products, physical goods, and memberships with a simple checkout and marketing tools. It streamlines creator payouts and helps you grow your audience effortlessly.
- [Instacart](https://composio.dev/toolkits/instacart) - Instacart is an online grocery delivery and pickup service platform. It lets you discover local retailers and create shoppable lists and recipes with ease.
- [Junglescout](https://composio.dev/toolkits/junglescout) - Junglescout is an Amazon product research and analytics platform for sellers. It delivers sales estimates, competitive insights, and optimization tools to boost your Amazon business.
- [Ko fi](https://composio.dev/toolkits/ko_fi) - Ko-fi is a platform that lets creators receive donations, memberships, and sales from fans. It helps creators monetize their work and grow their audience with minimal friction.
- [Lemon squeezy](https://composio.dev/toolkits/lemon_squeezy) - Lemon Squeezy is a payments and subscription platform built for software companies. It makes managing payments, taxes, and customer subscriptions effortless.
- [Loyverse](https://composio.dev/toolkits/loyverse) - Loyverse is a point-of-sale (POS) platform for small businesses, offering tools for sales, inventory, and customer loyalty. It helps streamline retail operations and boost customer engagement.

## Frequently Asked Questions

### What are the differences in Tool Router MCP and Shipengine MCP?

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

### Can I use Tool Router MCP with LlamaIndex?

Yes, you can. LlamaIndex 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 Shipengine tools.

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

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

---
[See all toolkits](https://composio.dev/toolkits) · [Composio docs](https://docs.composio.dev/llms.txt)
