|
| 1 | +# KrakenD AI Gateway: MCP Server Demo |
| 2 | + |
| 3 | +This demo showcases KrakenD as an MCP (Model Context Protocol) server that provides unified access to multiple external APIs. It demonstrates how KrakenD can act as a tool provider for AI agents by aggregating REST and GraphQL endpoints into a single, AI-friendly interface. |
| 4 | + |
| 5 | +An MCP server allows AI agents to access external tools and data sources through a standardized protocol. This example shows how KrakenD can orchestrate multiple API calls, transform data, and expose it as MCP tools. |
| 6 | + |
| 7 | +## What This Demonstrates |
| 8 | + |
| 9 | +**MCP Server Implementation**: KrakenD exposes an MCP endpoint that AI agents can use to retrieve comprehensive country information and weather data. |
| 10 | + |
| 11 | +**Key capabilities**: |
| 12 | +- MCP server configuration with tool definitions |
| 13 | +- Sequential proxying to aggregate multiple APIs (REST + GraphQL) |
| 14 | +- Data propagation between backend calls |
| 15 | +- Response transformation using JMESPath and Lua |
| 16 | +- Unified response from heterogeneous data sources |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### Prerequisites |
| 21 | + |
| 22 | +- Docker and Docker Compose |
| 23 | +- KrakenD Enterprise license (need a trial license? [Contact us](https://www.krakend.io/contact-sales/)) |
| 24 | + |
| 25 | +### Setup |
| 26 | + |
| 27 | +1. Add your KrakenD Enterprise license as `LICENSE` in the root directory |
| 28 | + |
| 29 | +2. Start services: |
| 30 | +```bash |
| 31 | +docker-compose up -d |
| 32 | +``` |
| 33 | + |
| 34 | +3. Test the MCP server by calling the endpoint: |
| 35 | +```bash |
| 36 | +curl -X POST http://localhost:8080/mcp \ |
| 37 | + -H "Content-Type: application/json" \ |
| 38 | + -d '{ |
| 39 | + "jsonrpc": "2.0", |
| 40 | + "method": "tools/call", |
| 41 | + "params": { |
| 42 | + "name": "get_country_info", |
| 43 | + "arguments": { |
| 44 | + "country_code": "ES" |
| 45 | + } |
| 46 | + }, |
| 47 | + "id": 1 |
| 48 | + }' |
| 49 | +``` |
| 50 | + |
| 51 | +## How It Works |
| 52 | + |
| 53 | +1. **MCP Tool Definition**: The `get_country_info` tool is defined with its input schema and workflow |
| 54 | +2. **Sequential Backend Calls**: |
| 55 | + - First: REST Countries API fetches geography, population, borders, and flag data |
| 56 | + - Second: GraphQL Countries API retrieves currency, languages, and emoji |
| 57 | + - Third: Open-Meteo Weather API gets current weather for the capital city |
| 58 | +3. **Data Propagation**: Capital coordinates from the first call are passed to the weather API |
| 59 | +4. **Response Aggregation**: All data is merged into a unified response using JMESPath |
| 60 | +5. **Lua Processing**: Custom Lua script flattens capital coordinates for easier access |
| 61 | + |
| 62 | +## Configuration |
| 63 | + |
| 64 | +The MCP server configuration is in `config/krakend/krakend.json`. Lua transformations are in `config/krakend/lua/`. |
| 65 | + |
| 66 | +The MCP endpoint definition includes: |
| 67 | +- Server metadata (name, title, version, instructions) |
| 68 | +- Tool definitions with input schemas |
| 69 | +- Workflow configuration with backend orchestration |
| 70 | + |
| 71 | +## Additional Features |
| 72 | + |
| 73 | +**Sequential Proxying**: Demonstrates how to chain API calls and propagate data between them |
| 74 | + |
| 75 | +**Multi-Protocol Aggregation**: Combines REST and GraphQL APIs in a single workflow |
| 76 | + |
| 77 | +**Error Handling**: Returns error messages when tool execution fails |
| 78 | + |
| 79 | +## Resources |
| 80 | + |
| 81 | +- [KrakenD AI Gateway Documentation](https://www.krakend.io/docs/enterprise/ai-gateway/) |
| 82 | +- [MCP Server Configuration](https://www.krakend.io/docs/enterprise/ai-gateway/mcp/) |
| 83 | +- [Sequential Proxying](https://www.krakend.io/docs/endpoints/sequential-proxy/) |
| 84 | +- [GraphQL Integration](https://www.krakend.io/docs/backends/graphql/) |
0 commit comments