|
| 1 | +--- |
| 2 | +title: Building a Data-Aware Chatbot with VoltAgent and Peaka |
| 3 | +description: Learn how to integrate Peaka's powerful data access into your VoltAgent AI applications using the Model Context Protocol (MCP). Build data-aware chatbots easily. |
| 4 | +slug: data-aware-chatbot-voltagent-peaka |
| 5 | +tags: [mcp, peaka, integration, tutorial] |
| 6 | +image: https://cdn.voltagent.dev/blog/peaka-mcp-voltagent/social.png # Placeholder - Update if needed |
| 7 | +authors: omeraplak |
| 8 | +--- |
| 9 | + |
| 10 | +import GitHubExampleLink from '@site/src/components/blog-widgets/GitHubExampleLink'; |
| 11 | + |
| 12 | +Hey everyone! So, I built this kinda neat thing the other day: an AI agent that can actually go and look up data. I got it working by mixing **VoltAgent** and **Peaka** together. |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | +In this post, I'll quickly cover: |
| 17 | + |
| 18 | +- [Wait, What's Peaka?](#wait-whats-peaka) |
| 19 | +- [And VoltAgent?](#and-voltagent) |
| 20 | +- [Making My Agent Talk to Peaka](#making-my-agent-talk-to-peaka) |
| 21 | + - [1. Starting a New VoltAgent Project](#1-starting-a-new-voltagent-project) |
| 22 | + - [2. Telling VoltAgent About Peaka (The MCP Bit)](#2-telling-voltagent-about-peaka-the-mcp-bit) |
| 23 | + - [3. Running It and Asking Stuff](#3-running-it-and-asking-stuff) |
| 24 | +- [Conclusion](#conclusion) |
| 25 | + |
| 26 | +## Wait, What's Peaka? |
| 27 | + |
| 28 | +Right, before I show you the code stuff, lemme tell you about [Peaka](https://www.peaka.com/). I just found them, but their idea is pretty simple: make it less annoying to work with data. Think of it like a data middleman. You hook up your databases, spreadsheets, whatever, to Peaka. Then you can ask it questions (using fancy SQL code or just regular English), and it pulls the info together from all those places for you. |
| 29 | + |
| 30 | +Usually, connecting different data sources is a real pain and costs a lot. Peaka feels like a simpler option, especially if you're not a huge company or just don't want to mess with complicated data pipelines. They wanna be the easy button for getting data. |
| 31 | + |
| 32 | +## And VoltAgent? |
| 33 | + |
| 34 | +Now, about VoltAgent. That's the framework _we_ built! If you haven't checked it out, it's our toolkit for putting together AI applications, especially things like chatbots and assistants. We provide the core engine (`@voltagent/core`) to get you started, and then you can add extra capabilities, like voice interaction (`@voltagent/voice`) or support for different LLMs (OpenAI, Google, etc.). Our goal with it is to handle some of the tricky plumbing, like managing conversation history or connecting to external tools, so you can focus more on what makes your agent unique. |
| 35 | + |
| 36 | +We designed VoltAgent to hit a nice sweet spot. It gives you more helpful structure than trying to build everything from raw AI libraries, but it offers a lot more freedom and customization than the simpler no-code platforms out there. We also built the [VoltAgent Console](https://console.voltagent.dev) a web interface that lets you monitor your agents, see exactly how they're working, and chat with them directly. We find it incredibly useful ourselves for debugging and testing! |
| 37 | + |
| 38 | +## Making My Agent Talk to Peaka |
| 39 | + |
| 40 | +Okay, so my plan was: build a chatbot with VoltAgent that could answer questions by checking data in Peaka. To make these two talk, I used something called **MCP (Model Context Protocol)**. It sounds fancy, but it's basically just a standard way for different programs to give each other tasks. If you wanna know more, I wrote about [what MCP is over here](https://voltagent.dev/blog/what-is-mcp/). For this project, it lets VoltAgent tell Peaka, "Hey, go run this data query!" |
| 41 | + |
| 42 | +To follow along, you'll want to sign up for a free Peaka account first over at [https://www.peaka.com/](https://www.peaka.com/). For this example, I'm just using the sample data they provide, which you'll have access to once you sign up. |
| 43 | + |
| 44 | +Here's how I did it. |
| 45 | + |
| 46 | +### 1. Starting a New VoltAgent Project |
| 47 | + |
| 48 | +First up, I needed a blank VoltAgent project. Their setup tool makes this easy: |
| 49 | + |
| 50 | +```bash |
| 51 | +npm create voltagent-app@latest my-peaka-agent |
| 52 | +# Answer the questions it asks |
| 53 | +cd my-peaka-agent |
| 54 | +``` |
| 55 | + |
| 56 | +That just makes a folder with the basic files I need to get started. |
| 57 | + |
| 58 | +### 2. Telling VoltAgent About Peaka (The MCP Bit) |
| 59 | + |
| 60 | +This is where the magic happens. I had to edit the main code file (`src/index.ts`) to tell VoltAgent how to find and talk to the Peaka tool using MCP. |
| 61 | + |
| 62 | +This is the key chunk of code I put in: |
| 63 | + |
| 64 | +```typescript title="src/index.ts" |
| 65 | +import { VoltAgent, Agent, MCPConfiguration } from "@voltagent/core"; |
| 66 | +import { VercelAIProvider } from "@voltagent/vercel-ai"; // Using Vercel's helper stuff for the AI |
| 67 | +import { openai } from "@ai-sdk/openai"; // And using OpenAI's model |
| 68 | + |
| 69 | +// 1. Set up the connection to the Peaka MCP tool |
| 70 | +const mcp = new MCPConfiguration({ |
| 71 | + id: "peaka-mcp", // Just a nickname for this setup |
| 72 | + servers: { |
| 73 | + // Here's the info for the Peaka tool |
| 74 | + peaka: { |
| 75 | + type: "stdio", // Means it runs like a command-line program |
| 76 | + command: "npx", // The command to start it |
| 77 | + // npx is neat, it grabs the latest Peaka MCP tool automatically |
| 78 | + args: ["-y", "@peaka/mcp-server-peaka@latest"], |
| 79 | + // Gotta give it my Peaka API key (stored safely elsewhere!) |
| 80 | + env: { PEAKA_API_KEY: process.env.PEAKA_API_KEY || "" }, |
| 81 | + }, |
| 82 | + }, |
| 83 | +}); |
| 84 | + |
| 85 | +// 2. Find out what the Peaka tool can actually *do* |
| 86 | +// (Need this `async` stuff because it takes a moment to connect) |
| 87 | +(async () => { |
| 88 | + // Ask the MCP connection: "What tools does Peaka give us?" |
| 89 | + const tools = await mcp.getTools(); |
| 90 | + |
| 91 | + // 3. Create our actual chatbot agent |
| 92 | + const agent = new Agent({ |
| 93 | + name: "Peaka Data Assistant", |
| 94 | + description: "I can look things up in Peaka's data.", |
| 95 | + llm: new VercelAIProvider(), // Which AI service to use |
| 96 | + model: openai("gpt-4o-mini"), // Which specific AI brain |
| 97 | + tools, // <-- Super important! Give the agent the tools from Peaka! |
| 98 | + }); |
| 99 | + |
| 100 | + // 4. Fire up VoltAgent |
| 101 | + new VoltAgent({ |
| 102 | + agents: { |
| 103 | + // Make our agent live |
| 104 | + agent, |
| 105 | + }, |
| 106 | + }); |
| 107 | + |
| 108 | + console.log("VoltAgent is running with Peaka powers!"); |
| 109 | +})(); |
| 110 | +``` |
| 111 | + |
| 112 | +So, what's happening here? |
| 113 | + |
| 114 | +1. **`MCPConfiguration`**: I'm telling VoltAgent, "There's this Peaka tool you can run. Use `npx` to find the `@peaka/mcp-server-peaka` thing, and give it my API key when you run it." The `stdio` part just means it runs like a regular program on my computer. |
| 115 | +2. **`mcp.getTools()`**: This is the clever bit. VoltAgent starts the Peaka tool and then asks it, "What can you do?" Peaka sends back a list of its abilities (like querying data). |
| 116 | +3. **`new Agent(...)`**: I'm making the chatbot itself. I give it a name, tell it what AI brain to use (`gpt-4o-mini`), and crucially, pass in those `tools` I got from Peaka. Now the chatbot knows it has these extra data powers. |
| 117 | +4. **`new VoltAgent(...)`**: This just starts the main VoltAgent system with my new agent included. |
| 118 | + |
| 119 | +Before running, I needed my API keys. I made a file called `.env` in the project folder and put them in there: |
| 120 | + |
| 121 | +```.env title=".env" |
| 122 | +PEAKA_API_KEY=your_secret_peaka_key |
| 123 | +# Don't forget your OpenAI key! |
| 124 | +OPENAI_API_KEY=your_secret_openai_key |
| 125 | +``` |
| 126 | + |
| 127 | +(Use your real keys, obviously! Keep 'em secret!) |
| 128 | + |
| 129 | +### 3. Running It and Asking Stuff |
| 130 | + |
| 131 | +Okay, code's ready, keys are in place. Time to run it! |
| 132 | + |
| 133 | +```bash |
| 134 | +npm run dev |
| 135 | +``` |
| 136 | + |
| 137 | +My terminal showed VoltAgent starting up, and it also started the Peaka tool automatically in the background. I saw something like this: |
| 138 | + |
| 139 | +```bash |
| 140 | +══════════════════════════════════════════════════ |
| 141 | + VOLTAGENT SERVER STARTED SUCCESSFULLY |
| 142 | +══════════════════════════════════════════════════ |
| 143 | + ✓ HTTP Server: http://localhost:3141 |
| 144 | + |
| 145 | + Developer Console: https://console.voltagent.dev |
| 146 | +══════════════════════════════════════════════════ |
| 147 | +``` |
| 148 | + |
| 149 | +Now the fun test: |
| 150 | + |
| 151 | +1. I popped open the [VoltAgent Console](https://console.voltagent.dev) in my browser. |
| 152 | +2. Found my agent ("Peaka Data Assistant"). |
| 153 | +3. Opened the chat window. |
| 154 | +4. Asked it something that needed data from Peaka, maybe like: |
| 155 | + |
| 156 | + > "Hey, what was my Stripe balance yesterday?" |
| 157 | +
|
| 158 | +Here's the cool part of what goes on: |
| 159 | + |
| 160 | +- The chatbot AI gets my question. |
| 161 | +- It figures out I need data and sees it has that Peaka tool. |
| 162 | +- It decides to use the tool. |
| 163 | +- VoltAgent sends the request over to the Peaka tool (using MCP). |
| 164 | +- The Peaka tool does its thing, querying my actual Stripe data (or whatever I connected). |
| 165 | +- Peaka sends the answer back to VoltAgent. |
| 166 | +- VoltAgent gives the raw answer back to the chatbot AI. |
| 167 | +- The AI turns that raw data into a normal sentence and shows it to me in the chat. |
| 168 | + |
| 169 | +It looks something like this: |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +<GitHubExampleLink |
| 174 | + repoUrl="https://github.com/VoltAgent/voltagent/tree/main/examples/with-peaka-mcp" |
| 175 | + npmCommand="npm create voltagent-app@latest -- --example with-peaka-mcp" |
| 176 | +/> |
| 177 | + |
| 178 | +## Conclusion |
| 179 | + |
| 180 | +Getting Peaka hooked up to my VoltAgent bot with MCP wasn't too bad! It's pretty awesome to have a chatbot that can actually use real-time data from different places. I can see this being useful for building smarter internal tools, helpdesk bots that know current info, or anything where the AI needs to know more than just what it was trained on. |
| 181 | + |
| 182 | +Definitely worth playing around with if you're building AI stuff! |
0 commit comments