> Connect ApiPay to AI assistants with the @apipay.vn/mcp MCP server.

Source: https://docs.apipay.vn/en/integrations/mcp

# MCP Server

`@apipay.vn/mcp` is the ApiPay Model Context Protocol (MCP) server. AI assistants (Claude, Cursor, Codex, Gemini, Copilot…) use it to create payments, manage products and prices, view bank accounts and transactions, manage webhooks, and read metrics.

Open **Integrations > Web App > MCP Server** in the dashboard to copy a config with your API key filled in.

[Open MCP Server in dashboard](https://my.apipay.vn/en/integrations/mcp)

## Prerequisites

- Node.js `>=18.0.0`
- An API key from the [ApiPay dashboard](https://my.apipay.vn): `ak_test_...` for sandbox, a key with no prefix for production.

## API Key

The server reads your API key from environment variables:

- `APIPAY_ACCESS_KEY` — access key (`ak_test_...` for sandbox)
- `APIPAY_SECRET_KEY` — secret key
- `APIPAY_API_URL` — optional, defaults to `https://app.apipay.vn/v1`

If these are not set, the server uses the API key saved by the ApiPay CLI (`apipay login`, then `apipay keys:create`).

## Client Setup

### JSON Config File

```json
{
  "mcpServers": {
    "apipay": {
      "command": "npx",
      "args": ["-y", "@apipay.vn/mcp"],
      "env": {
        "APIPAY_ACCESS_KEY": "ak_test_your_access_key",
        "APIPAY_SECRET_KEY": "your_secret_key"
      }
    }
  }
}
```

Use the JSON config above for these clients:

| Client | Where to add it |
| --- | --- |
| Claude Desktop | `claude_desktop_config.json` (macOS: `~/Library/Application Support/Claude/`) |
| Cursor | `.cursor/mcp.json` or **Cursor Settings > MCP** |
| Windsurf | `.windsurf/mcp_config.json` |
| Cline | `cline_mcp_settings.json` |
| JetBrains AI Assistant | **Settings > Tools > AI Assistant > Model Context Protocol (MCP) > Add** |
| Warp | **Settings > AI > Manage MCP Servers > + Add** |

### CLI

```bash
# Claude Code
claude mcp add apipay --scope user \
  --env APIPAY_ACCESS_KEY=ak_test_your_access_key \
  --env APIPAY_SECRET_KEY=your_secret_key \
  -- npx -y @apipay.vn/mcp

# Codex
codex mcp add apipay \
  --env APIPAY_ACCESS_KEY=ak_test_your_access_key \
  --env APIPAY_SECRET_KEY=your_secret_key \
  -- npx -y @apipay.vn/mcp

# Copilot CLI
copilot mcp add apipay \
  --env APIPAY_ACCESS_KEY=ak_test_your_access_key \
  --env APIPAY_SECRET_KEY=your_secret_key \
  -- npx -y @apipay.vn/mcp

# Gemini CLI (add -s user to use it in every project)
gemini mcp add apipay \
  -e APIPAY_ACCESS_KEY=ak_test_your_access_key \
  -e APIPAY_SECRET_KEY=your_secret_key \
  -- npx -y @apipay.vn/mcp

# Grok Build
grok mcp add apipay \
  -e APIPAY_ACCESS_KEY=ak_test_your_access_key \
  -e APIPAY_SECRET_KEY=your_secret_key \
  -- npx -y @apipay.vn/mcp

# Command Code
cmd mcp add --transport stdio \
  --env APIPAY_ACCESS_KEY=ak_test_your_access_key \
  --env APIPAY_SECRET_KEY=your_secret_key \
  apipay -- npx -y @apipay.vn/mcp
```

These CLIs do not pass the API key on the command line. Run `apipay login`, then `apipay keys:create` first:

```bash
amp mcp add apipay -- npx -y @apipay.vn/mcp       # Amp
devin mcp add apipay -- npx -y @apipay.vn/mcp     # Devin CLI
droid mcp add apipay "npx -y @apipay.vn/mcp"      # Factory CLI
qodercli mcp add apipay -- npx -y @apipay.vn/mcp  # Qoder CLI
```

### VS Code (Copilot)

Add to `.vscode/mcp.json`:

```json
{
  "servers": {
    "apipay": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "@apipay.vn/mcp"],
      "env": {
        "APIPAY_ACCESS_KEY": "ak_test_your_access_key",
        "APIPAY_SECRET_KEY": "your_secret_key"
      }
    }
  }
}
```

### OpenCode

Add to `opencode.json` (project) or `~/.config/opencode/opencode.json` (global):

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "apipay": {
      "type": "local",
      "command": ["npx", "-y", "@apipay.vn/mcp"],
      "environment": {
        "APIPAY_ACCESS_KEY": "ak_test_your_access_key",
        "APIPAY_SECRET_KEY": "your_secret_key"
      }
    }
  }
}
```

## Available Tools

### Connection

- `self_test` — Checks your API key and connection; returns the key prefix and a bank account summary.

### Banks

- `list_banks` — Lists connected bank accounts with the `bankPublicId` used to create payments and webhooks.

### Payment Requests

- `create_payment` — Creates a payment link. Requires `bankPublicId` and either `amount` or `priceId` (not both); optional `content`, `title`, `expiresAt`, `redirectUrl`. Have a lookup key? Call `list_prices` to get the `priceId`.
- `list_payments` — Lists payment requests, filtered by status, search term, or date range.
- `cancel_payment` — Cancels an `ACTIVE` payment request.
- `simulate_payment` — Simulates a sandbox payment (`publicId` starts with `test_pr_`) and sends a test webhook.

### Products & Prices

- `list_products` — Lists products.
- `get_product` — Gets a product with its prices.
- `create_product` — Creates a product; optional `defaultPriceData` also creates its default price.
- `update_product` — Updates name, description, archive/restore, or the default price.
- `list_prices` — Lists prices, filtered by `productId` or `lookupKey`.
- `get_price` — Gets a price by id.
- `create_price` — Creates a price. The amount cannot be edited later.
- `update_price` — Updates nickname, lookup key, or archive/restore.
- `delete_price` — Deletes an unused price. Prices already used for payments can only be archived.

### Customers & Invoices

- `list_commerce_customers` — Lists customers, searchable by name, email, or tax code.
- `get_commerce_customer` — Gets a customer with recent payment requests and invoices.
- `create_commerce_customer` — Creates a customer. Email must be unique.
- `update_commerce_customer` — Updates customer details.
- `delete_commerce_customer` — Deletes a customer with no payment requests or invoices.
- `send_commerce_invoice` — Emails a payment link for a price to a customer.
- `list_commerce_invoices` — Lists sales invoices, searchable by invoice number, buyer, or product name.
- `get_commerce_invoice` — Gets one invoice in detail.

### Webhooks

- `list_webhooks` — Lists registered webhooks.
- `create_webhook` — Registers a webhook URL. Covers all your bank accounts unless you pick some.
- `update_webhook` — Changes a webhook's URL, banks, events, timeout or extra header.
- `toggle_webhook` — Turns a webhook on or off.
- `remove_webhook` — Deletes a webhook.
- `list_webhook_deliveries` — Shows webhook delivery history.
- `resend_webhook` — Resends a failed webhook.

### Metrics & Transactions

- `get_overview` — Transaction overview: totals, averages, success rate, and volume by bank.
- `list_transactions` — Lists recent transactions, filtered by date, bank, or search term.

## Try It in Sandbox

1. Call `self_test` to check your API key.
2. Call `list_banks` to get a `bankPublicId`.
3. Optional: call `create_product` with `defaultPriceData`, or `list_prices` with a `lookupKey` to get a `priceId`.
4. Call `create_payment` with `bankPublicId` and either `amount` (for example `"100000"`) or `priceId`. A sandbox key returns a `publicId` like `test_pr_...`.
5. Call `simulate_payment` with that `publicId` to simulate the customer paying.
6. Call `list_webhook_deliveries` and `list_transactions` to check the result.

See also [Sandbox & Live Test](/en/sandbox).

## Irreversible Actions

These tools delete data or send real requests and emails. Have your AI assistant confirm with you before running them:

- `cancel_payment` — Cancels an active payment link.
- `delete_price` — Deletes a price.
- `delete_commerce_customer` — Deletes a customer.
- `send_commerce_invoice` — Emails a payment link to a customer.
- `remove_webhook` — Deletes a webhook.
- `resend_webhook` — Sends a real request to your webhook URL.
