How to Build an MCP Server for Live Kenya eSIM Comparisons
This guide walks you through building a Model Context Protocol (MCP) server that fetches live eSIM prices and data plans for Kenya, letting an AI assistant query and compare options in real time. You’ll create a simple Node.js server that exposes a tool for retrieving current eSIM offers from a public API or a curated data source, and then connect it to an MCP-compatible client like Claude Desktop.
What You’ll Need
- Node.js 18 or newer installed on your machine
- An MCP client (e.g., Claude Desktop, or a custom client using the MCP SDK)
- A source of live eSIM data for Kenya – either a public API (like esimdb or airalo’s public endpoints) or a JSON file you update regularly
- Basic familiarity with JavaScript and terminal commands
Step-by-Step
- Set up your project directory. Create a new folder for your MCP server and initialize it with
npm init -y. This creates apackage.jsonfile. - Install the MCP SDK. Run
npm install @modelcontextprotocol/sdkto get the official TypeScript/JavaScript SDK. Also installaxios(or use built-in fetch) for HTTP requests:npm install axios. - Create the server file. Make a file named
server.jsin the root. This will hold your MCP server logic. - Import the MCP classes. At the top of
server.js, add:const { McpServer } = require('@modelcontextprotocol/sdk/server/mcp.js'); const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');This imports the server class and the stdio transport used for communication with the client.
- Define your data-fetching function. Write a function that retrieves eSIM plans for Kenya. For example:
async function getKenyaEsims() { const response = await axios.get('https://api.example.com/esims?country=KE'); return response.data; }Replace the URL with your actual data source. If you’re using a static JSON file, read it with
fs. - Create the MCP server instance. Instantiate the server with a name and version:
const server = new McpServer({ name: 'kenya-esim-comparison', version: '1.0.0' }); - Register a tool. Use
server.tool()to define a tool that the AI can call. For example:server.tool( 'get_kenya_esims', { maxPrice: 'number?', dataLimit: 'number?' }, async ({ maxPrice, dataLimit }) => { const plans = await getKenyaEsims(); let filtered = plans; if (maxPrice) filtered = filtered.filter(p => p.price <= maxPrice); if (dataLimit) filtered = filtered.filter(p => p.dataGB >= dataLimit); return { content: [{ type: 'text', text: JSON.stringify(filtered, null, 2) }] }; } );The first argument is the tool name, the second is a JSON schema of parameters, and the third is the async handler.
- Connect the server to stdio. At the bottom of the file, add:
const transport = new StdioServerTransport(); await server.connect(transport);This allows the MCP client to communicate with your server via standard input/output.
- Test the server manually. Run
node server.jsin the terminal. It should start without errors. You can send a JSON-RPC message to it to test, but it’s easier to test via an MCP client. - Configure your MCP client. If using Claude Desktop, edit its configuration file (e.g.,
claude_desktop_config.json) to add a new MCP server entry pointing to yourserver.jsfile. For example:{ "mcpServers": { "kenya-esim": { "command": "node", "args": ["/path/to/your/server.js"] } } }Restart the client.
- Test the tool. In the client, ask something like “What’s the cheapest eSIM for Kenya with 5GB of data?” The AI should call your tool and return the filtered results.
Common Mistakes
- Not handling async errors. If your API call fails, the tool throws an unhandled error. Wrap your logic in try/catch and return a friendly error message.
- Incorrect parameter schema. If the JSON schema for parameters is malformed, the client may not send the right arguments. Stick to simple types like
string,number, andboolean. - Forgetting to install dependencies. Ensure
@modelcontextprotocol/sdkandaxiosare in yourpackage.json. - Hardcoding data. If you’re not using a live API, your comparisons will be stale. Update your JSON file regularly or use a real API.
Tips
- Use environment variables for API keys or URLs to keep them out of your code.
- Add a second tool like
get_esim_detailsfor specific plan info to make the server more useful. - Validate inputs in the handler to avoid NaN comparisons.
- Log requests to a file for debugging.
Troubleshooting
- Server starts but client can’t connect: Make sure the path to
server.jsin the client config is absolute and correct. Check file permissions. - Tool returns empty results: Test your API call directly in the browser or with curl. If the API returns an array, ensure you’re filtering correctly.
- Errors about ‘McpServer’ not being a constructor: You may have installed the wrong package. Verify you’re using
@modelcontextprotocol/sdkand not an older version. - Client says ‘Tool not found’: Restart the client after adding the server. Also check the server name in the config matches the one in your code.
Frequently Asked Questions
Do I need a specific MCP client to test this?
No, but using Claude Desktop or any MCP-compatible client makes testing easier. You can also write a simple Node.js script using the MCP client SDK.
Can I use a free API for Kenya eSIM data?
Yes, some providers offer public endpoints. If not, you can scrape or manually update a JSON file, but that’s less reliable.
How do I add more filters like network type or validity?
Add more parameters to the tool’s schema and filter accordingly in the handler.
Is it possible to run this server on a remote host?
Yes, but you’d need to use a different transport (like HTTP/SSE) instead of stdio. The MCP SDK supports both.
What if my data source changes its API structure?
Update the parsing logic in the getKenyaEsims function. It’s a good idea to keep the data normalization separate from the tool handler.
Can I use this server with other AI assistants besides Claude?
Yes, any MCP-compatible client can use it, as long as they support the same protocol version.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.