# How to integrate Zep MCP with LlamaIndex

```json
{
  "title": "How to integrate Zep MCP with LlamaIndex",
  "toolkit": "Zep",
  "toolkit_slug": "zep",
  "framework": "LlamaIndex",
  "framework_slug": "llama-index",
  "url": "https://composio.dev/toolkits/zep/framework/llama-index",
  "markdown_url": "https://composio.dev/toolkits/zep/framework/llama-index.md",
  "updated_at": "2026-03-29T06:56:18.302Z"
}
```

## Introduction

This guide walks you through connecting Zep to LlamaIndex using the Composio tool router. By the end, you'll have a working Zep agent that can store a memory about today's meeting, retrieve all memories tagged urgent, summarize knowledge about client preferences through natural language commands.
This guide will help you understand how to give your LlamaIndex agent real control over a Zep account through Composio's Zep MCP server.
Before we dive in, let's take a quick look at the key ideas and tools involved.

## Also integrate Zep with

- [ChatGPT](https://composio.dev/toolkits/zep/framework/chatgpt)
- [OpenAI Agents SDK](https://composio.dev/toolkits/zep/framework/open-ai-agents-sdk)
- [Claude Agent SDK](https://composio.dev/toolkits/zep/framework/claude-agents-sdk)
- [Claude Code](https://composio.dev/toolkits/zep/framework/claude-code)
- [Claude Cowork](https://composio.dev/toolkits/zep/framework/claude-cowork)
- [Codex](https://composio.dev/toolkits/zep/framework/codex)
- [Cursor](https://composio.dev/toolkits/zep/framework/cursor)
- [VS Code](https://composio.dev/toolkits/zep/framework/vscode)
- [OpenCode](https://composio.dev/toolkits/zep/framework/opencode)
- [OpenClaw](https://composio.dev/toolkits/zep/framework/openclaw)
- [Hermes](https://composio.dev/toolkits/zep/framework/hermes-agent)
- [CLI](https://composio.dev/toolkits/zep/framework/cli)
- [Google ADK](https://composio.dev/toolkits/zep/framework/google-adk)
- [LangChain](https://composio.dev/toolkits/zep/framework/langchain)
- [Vercel AI SDK](https://composio.dev/toolkits/zep/framework/ai-sdk)
- [Mastra AI](https://composio.dev/toolkits/zep/framework/mastra-ai)
- [CrewAI](https://composio.dev/toolkits/zep/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 Zep
- Connect LlamaIndex to the Zep MCP server
- Build a Zep-powered agent using LlamaIndex
- Interact with Zep 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 Zep MCP server, and what's possible with it?

The Zep MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Zep account. It provides structured and secure access so your agent can perform Zep operations on your behalf.

## Supported Tools

| Tool slug | Name | Description |
|---|---|---|
| `ZEP_ADD_FACT_TRIPLE` | Add Fact Triple | Tool to add a manually specified fact triple (subject-predicate-object) to the Zep knowledge graph. Use when you need to add explicit relationships between entities. Returns a task_id to monitor processing status. |
| `ZEP_ADD_SESSION_MEMORY` | Add Session Memory | Tool to add memory messages to a specified Zep session. Use when you need to store conversation history or context in a session. |
| `ZEP_ADD_THREAD_MESSAGES` | Add Thread Messages | Tool to add chat messages to a thread in Zep and ingest them into the user knowledge graph. Use when you need to add conversation history to a thread - for best results, add messages on every chat turn in the order they were created. |
| `ZEP_CLONE_GRAPH` | Clone Graph | Tool to clone a user or group graph with new identifiers in Zep. Use when you need to create test copies of user data, migrate user graphs to new identifiers, or set up template graphs for new users. This is an asynchronous operation that returns a task_id for tracking progress. |
| `ZEP_CREATE_GRAPH` | Create Graph | Tool to create a new graph by adding data to Zep. Use when you need to add text, message, or JSON data to a user's graph or a specific graph. The data is processed and an episode node is created in the graph. |
| `ZEP_CREATE_GROUP` | Create Group | Tool to create a new group in Zep for multi-user graph management. Use when you need to create a namespace for shared context across multiple users. |
| `ZEP_CREATE_SESSION` | Create Session | Tool to create a new session in Zep for storing conversation memory. Use when you need to establish a new conversation context linked to an existing user. The user must be created first before creating a session. |
| `ZEP_CREATE_THREAD` | Create Thread | Tool to create a new thread in Zep for a specific user. Use when you need to start a new conversation thread. The user must be created first before creating a thread. Zep automatically warms the cache for that user's graph data in the background to improve query latency. |
| `ZEP_CREATE_USER` | Create User | Tool to create a new user in Zep with properties like user_id, email, and metadata. Use when you need to add a new user to the system. It is recommended to provide at least first_name and ideally last_name for better user association. |
| `ZEP_DELETE_GRAPH` | Delete Graph | Tool to delete a graph from Zep. Use when you need to permanently remove a graph and all associated data. |
| `ZEP_DELETE_GROUP` | Delete Group | Tool to delete a group from Zep. Use when you need to permanently remove a group and its associated data. |
| `ZEP_DELETE_SESSION_MEMORY` | Delete Session Memory | Tool to delete a session and its memory from Zep. Use when you need to permanently remove all memory data associated with a specific session. |
| `ZEP_DELETE_THREAD` | Delete Thread | Tool to delete a thread and its messages from Zep. Note that deleting a thread removes the thread and its messages from the thread history but does not delete associated data in the user's knowledge graph. |
| `ZEP_DELETE_USER` | Delete User | Tool to delete a user and all associated threads and artifacts from Zep. Use when you need to permanently remove a user and handle Right To Be Forgotten requests. Deleting a user will delete all threads and thread artifacts associated with that user. |
| `ZEP_GET_EDGE_BY_UUID` | Get Edge by UUID | Tool to retrieve a specific edge by its UUID from the Zep knowledge graph. Use when you need to fetch detailed information about a relationship between nodes, including the semantic fact, connected nodes, and temporal metadata. |
| `ZEP_GET_GRAPH_BY_ID` | Get Graph by ID | Tool to retrieve a graph by its unique identifier from Zep. Use when you need to fetch details about a specific graph including its name, description, and timestamps. |
| `ZEP_GET_GROUP_BY_ID` | Get Group by ID | Tool to retrieve a group by ID from Zep. Use when you need to fetch detailed information about a specific group including its configuration and metadata. |
| `ZEP_GET_NODE_ENTITY_EDGES` | Get Node Entity Edges | Tool to retrieve all entity edges for a specific node in the Zep knowledge graph. Use when you need to fetch relationship information, facts, and connections for a given node UUID. |
| `ZEP_GET_PROJECT_INFO` | Get Project Info | Tool to retrieve project information based on the provided API key. Use when you need to fetch project details including UUID, name, description, and creation timestamp. |
| `ZEP_GET_SESSION_BY_ID` | Get Session by ID | Tool to retrieve a session by its unique identifier from Zep. Use when you need to fetch details about a specific session including user association, timestamps, classifications, and metadata. |
| `ZEP_GET_SESSION_MEMORY` | Get Session Memory | Tool to retrieve memory for a given session including relevant facts and entities. Use when you need contextual information and historical data from a session. |
| `ZEP_GET_SESSION_MESSAGE_BY_UUID` | Get Session Message by UUID | Tool to retrieve a specific message by UUID from a Zep session. Use when you need to fetch a single message's details by its unique identifier from a particular session. |
| `ZEP_GET_SESSION_MESSAGES` | Get Session Messages | Tool to retrieve messages for a given session from Zep. Use when you need to fetch the message history for a specific session with optional pagination support. |
| `ZEP_GET_TASK_STATUS` | Get Task Status | Tool to check the status of asynchronous operations in Zep. Use when monitoring batch adds, clone operations, or fact triple additions. Returns comprehensive task information including status, progress, timestamps, and error details if applicable. |
| `ZEP_GET_THREAD_MESSAGES` | Get Thread Messages | Tool to retrieve conversation history for a specific thread from Zep. Use when you need to fetch the chat message history with optional pagination support via limit, cursor, or lastn parameters. |
| `ZEP_GET_THREAD_USER_CONTEXT` | Get Thread User Context | Tool to retrieve the most relevant user context from the user graph based on thread messages. Use when you need to get context including memory from past threads that is most relevant to the current thread. |
| `ZEP_GET_USER_BY_ID` | Get User by ID | Tool to retrieve a user by their user ID from Zep. Use when you need to fetch detailed information about a specific user including their profile, metadata, and configuration settings. |
| `ZEP_GET_USER_NODE` | Get User Node | Tool to retrieve a user's graph node and summary from Zep. Use when you need to access the user summary generated from instructions, build custom context blocks, or retrieve facts and information associated with a specific user. |
| `ZEP_GET_USER_NODES` | Get User Nodes | Tool to retrieve all nodes for a specific user from their graph in Zep. Use when you need to fetch entity information, preferences, and knowledge graph data for a user. Supports pagination via limit and uuid_cursor parameters. |
| `ZEP_GET_USER_SESSIONS` | Get User Sessions | Tool to retrieve all sessions for a user from Zep. Use when you need to fetch session history for a specific user ID. Returns an array of session objects with metadata, classifications, and timestamps. |
| `ZEP_GET_USER_THREADS` | Get User Threads | Tool to retrieve all threads for a specific user from Zep. Use when you need to fetch thread history for a specific user ID. Returns an array of thread objects with identifiers and timestamps. |
| `ZEP_GRAPH_SEARCH` | Graph Search | Tool to perform hybrid graph search combining semantic similarity and BM25 full-text search across the Zep knowledge graph. Use when you need to search for entities, relationships, or episodes within a user, group, or specific graph. Supports various reranking methods and filtering options. |
| `ZEP_LIST_GRAPHS` | List Graphs | Tool to retrieve all graphs from Zep with pagination support. Use when you need to fetch a list of graphs with optional pagination via page_number and page_size parameters. |
| `ZEP_LIST_GROUPS_ORDERED` | List Groups Ordered | Tool to retrieve all groups from Zep with pagination support. Use when you need to fetch a list of groups with optional pagination via pageNumber and pageSize parameters. |
| `ZEP_LIST_SESSIONS_ORDERED` | List Sessions Ordered | Tool to retrieve all sessions from Zep with pagination and ordering support. Use when you need to fetch a list of sessions with optional pagination via page_number and page_size parameters. |
| `ZEP_LIST_THREADS` | List Threads | Tool to retrieve all threads from Zep with pagination support. Use when you need to fetch a list of threads with optional pagination and sorting via page_number, page_size, order_by, and asc parameters. |
| `ZEP_LIST_USERS_ORDERED` | List Users Ordered | Tool to retrieve all users from Zep with pagination support. Use when you need to fetch a list of users with optional pagination via pageNumber and pageSize parameters. |
| `ZEP_LIST_ALL_THREADS` | List All Threads | Tool to list all threads with pagination and ordering support. Use when you need to retrieve threads with optional pagination (page_number, page_size) and ordering (order_by, asc) parameters. |
| `ZEP_UPDATE_GRAPH` | Update Graph | Tool to update graph information in Zep including name and description. Use when you need to modify graph properties after creation. |
| `ZEP_UPDATE_GROUP` | Update Group | Tool to update group information in Zep including name, description, and fact rating instructions. Use when you need to modify an existing group's properties. |
| `ZEP_UPDATE_MESSAGE` | Update Message | Tool to update a message in a Zep thread. Use when you need to modify message content, metadata, role, or other properties of an existing message. Particularly useful for adding or modifying metadata after a message has been created. |
| `ZEP_UPDATE_SESSION_METADATA` | Update Session Metadata | Tool to update session metadata in Zep. Use when you need to modify or add metadata to an existing session. Metadata is merged, so existing keys are preserved unless explicitly overwritten. |
| `ZEP_UPDATE_USER` | Update User | Tool to update an existing user's information in Zep including email, metadata, and ontology settings. Use when you need to modify user properties after creation. |

## Supported Triggers

None listed.

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

The Zep MCP server is an implementation of the Model Context Protocol that connects your AI agent to Zep. It provides structured and secure access so your agent can perform Zep 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 Zep account and project
- Basic familiarity with async Python/Typescript

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

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 Zep 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, zep)
- 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 Zep 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=["zep"],
    )

    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 Zep actions."
    system_prompt = """
    You are a helpful assistant connected to Composio Tool Router.
    Use the available tools to answer user queries and perform Zep 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: ["zep"],
    },
  );

  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 Zep 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 Zep
```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 Zep, 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=["zep"],
    )

    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 Zep actions."
    system_prompt = """
    You are a helpful assistant connected to Composio Tool Router.
    Use the available tools to answer user queries and perform Zep 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: ["zep"],
    },
  );

  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 Zep 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 Zep to LlamaIndex through Composio's Tool Router MCP layer.
Key takeaways:
- Tool Router dynamically exposes Zep 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 Zep MCP Agent with another framework

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

## Related Toolkits

- [Google Sheets](https://composio.dev/toolkits/googlesheets) - Google Sheets is a cloud-based spreadsheet tool for real-time collaboration and data analysis. It lets teams work together from anywhere, updating information instantly.
- [Composio](https://composio.dev/toolkits/composio) - Composio is an integration platform that connects AI agents with hundreds of business tools. It streamlines authentication and lets you trigger actions across services—no custom code needed.
- [Notion](https://composio.dev/toolkits/notion) - Notion is a collaborative workspace for notes, docs, wikis, and tasks. It streamlines team knowledge, project tracking, and workflow customization in one place.
- [Airtable](https://composio.dev/toolkits/airtable) - Airtable combines the flexibility of spreadsheets with the power of a database for easy project and data management. Teams use Airtable to organize, track, and collaborate with custom views and automations.
- [Asana](https://composio.dev/toolkits/asana) - Asana is a collaborative work management platform for teams to organize and track projects. It streamlines teamwork, boosts productivity, and keeps everyone aligned on goals.
- [Google Tasks](https://composio.dev/toolkits/googletasks) - Google Tasks is a to-do list and task management tool integrated into Gmail and Google Calendar. It helps you organize, track, and complete tasks across your Google ecosystem.
- [Linear](https://composio.dev/toolkits/linear) - Linear is a modern issue tracking and project planning tool for fast-moving teams. It helps streamline workflows, organize projects, and boost productivity.
- [Composio search](https://composio.dev/toolkits/composio_search) - Composio search is a unified web search toolkit spanning travel, e-commerce, news, financial markets, images, and more. It lets you and your apps tap into up-to-date web data from a single, easy-to-integrate service.
- [Jira](https://composio.dev/toolkits/jira) - Jira is Atlassian’s platform for bug tracking, issue tracking, and agile project management. It helps teams organize work, prioritize tasks, and deliver projects efficiently.
- [Clickup](https://composio.dev/toolkits/clickup) - ClickUp is an all-in-one productivity platform for managing tasks, docs, goals, and team collaboration. It streamlines project workflows so teams can work smarter and stay organized in one place.
- [Monday](https://composio.dev/toolkits/monday) - Monday.com is a customizable work management platform for project planning and collaboration. It helps teams organize tasks, automate workflows, and track progress in real time.
- [Perplexityai](https://composio.dev/toolkits/perplexityai) - Perplexityai delivers natural, conversational AI models for generating human-like text. Instantly get context-aware, high-quality responses for chat, search, or complex workflows.
- [Browser tool](https://composio.dev/toolkits/browser_tool) - Browser tool is a virtual browser integration that lets AI agents interact with the web programmatically. It enables automated browsing, scraping, and action-taking from any AI workflow.
- [Addressfinder](https://composio.dev/toolkits/addressfinder) - Addressfinder is a data quality platform for verifying addresses, emails, and phone numbers. It helps you ensure accurate customer and contact data every time.
- [Agiled](https://composio.dev/toolkits/agiled) - Agiled is an all-in-one business management platform for CRM, projects, and finance. It helps you streamline workflows, consolidate client data, and manage business processes in one place.
- [Ai ml api](https://composio.dev/toolkits/ai_ml_api) - Ai ml api is a suite of AI/ML models for natural language and image tasks. It provides fast, scalable access to advanced AI capabilities for your apps and workflows.
- [Aivoov](https://composio.dev/toolkits/aivoov) - Aivoov is an AI-powered text-to-speech platform offering 1,000+ voices in over 150 languages. Instantly turn written content into natural, human-like audio for any application.
- [All images ai](https://composio.dev/toolkits/all_images_ai) - All-Images.ai is an AI-powered image generation and management platform. It helps you create, search, and organize images effortlessly with advanced AI capabilities.
- [Anthropic administrator](https://composio.dev/toolkits/anthropic_administrator) - Anthropic administrator is an API for managing Anthropic organizational resources like members, workspaces, and API keys. It helps you automate admin tasks and streamline resource management across your Anthropic organization.
- [Api labz](https://composio.dev/toolkits/api_labz) - Api labz is a platform offering a suite of AI-driven APIs and workflow tools. It helps developers automate tasks and build smarter, more efficient applications.

## Frequently Asked Questions

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

With a standalone Zep MCP server, the agents and LLMs can only access a fixed set of Zep tools tied to that server. However, with the Composio Tool Router, agents can dynamically load tools from Zep 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 Zep tools.

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

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

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