DEV Community

Cover image for I built the first eSewa and Khalti MCP servers — here's how
Abidit Shrestha
Abidit Shrestha

Posted on

I built the first eSewa and Khalti MCP servers — here's how

The Model Context Protocol (MCP) lets Claude AI interact with external tools and APIs. I just shipped the first MCP servers for Nepal's two biggest payment gateways: eSewa and Khalti.

Why this matters

Nepal's digital payment landscape is booming. eSewa has over 8 million users and dominates the market, while Khalti is the second-largest payment gateway. But until now, there was no way for Claude to interact with these systems programmatically. If you're building an AI-powered app that needs to process payments in Nepal, you were stuck writing custom integrations.

What these servers do

esewa-mcp exposes three tools:

  • esewa_initiate_payment – Start a transaction
  • esewa_verify_payment – Confirm a payment succeeded
  • esewa_get_transaction_status – Check payment status anytime

khalti-mcp exposes three tools:

  • khalti_initiate_payment – Create a payment request
  • khalti_lookup_payment – Retrieve payment details
  • khalti_verify_payment – Verify transaction completion

Both work directly with the official APIs and sandbox environments for safe testing.

The interesting technical challenge: eSewa's HMAC signature

Here's where it got tricky. eSewa uses HMAC-SHA256 signatures to authorize requests, but the fields must be signed in exact order: total_amount,transaction_uuid,product_code. Sign them out of order and the payment fails silently. This tight coupling between field order and cryptography meant I had to be surgical about how the signature is computed. Any deviation — even a typo in field names — breaks the whole flow.

Getting started

Install either server with a single command:

npx -y esewa-mcp
npx -y khalti-mcp
Enter fullscreen mode Exit fullscreen mode

Then add to Claude Desktop config:

{
  "mcpServers": {
    "khalti": {
      "command": "npx",
      "args": ["-y", "khalti-mcp"],
      "env": {
        "KHALTI_SECRET_KEY": "your_secret_key",
        "KHALTI_ENVIRONMENT": "sandbox"
      }
    },
    "esewa": {
      "command": "npx",
      "args": ["-y", "esewa-mcp"],
      "env": {
        "ESEWA_MERCHANT_CODE": "EPAYTEST",
        "ESEWA_PRODUCT_CODE": "EPAYTEST",
        "ESEWA_SECRET_KEY": "your_secret_key",
        "ESEWA_ENVIRONMENT": "sandbox"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Then just ask Claude naturally:

"Initiate a Khalti payment for NPR 500, order ID invoice-001"

"Verify eSewa transaction UUID abc-123"

A testing tip

Both eSewa and Khalti provide sandbox environments with free test credentials — no real money involved. I built these servers to use sandbox by default so you can develop safely.

What's next

These are production-ready v1.0.1. If you're building AI-powered commerce for Nepal, check the repo and open an issue.

npm: khalti-mcp · esewa-mcp

GitHub: https://github.com/Abidit/eSewa-Khalti-mcp

Top comments (0)