NonagonLink MCP Server — Setup and Verification Guide

Setup and verification guide for the NonagonLink MCP server


Quick start — connect by copy & paste (recommended)

With the npm package @nonagon-link/mcp you can connect without cloning the repository. Just add the following to your project's .claude/settings.json (or claude_desktop_config.json for Claude Desktop):

{
  "mcpServers": {
    "nonagon-link": {
      "command": "npx",
      "args": ["-y", "--ignore-scripts", "@nonagon-link/mcp@0.3.12"],
      "env": {
        "NONAGON_PRIVATE_KEY": "<Base58 secret key of your payment wallet>",
        "NONAGON_PAY_TO": "8yXpNyyPg9iGdMST8BRyz7HEJVbQG81VP6kHBCKXrdH8",
        "NONAGON_LINK_BASE_URL": "https://api.nnglink.ai"
      }
    }
  }
}

In Claude Code you can also add it with a single command:

claude mcp add nonagon-link -e NONAGON_PRIVATE_KEY=<Base58 secret key> -e NONAGON_LINK_BASE_URL=https://api.nnglink.ai -e NONAGON_PAY_TO=8yXpNyyPg9iGdMST8BRyz7HEJVbQG81VP6kHBCKXrdH8 -- npx -y --ignore-scripts @nonagon-link/mcp@0.3.12

⚠️ Security note: always pin an exact version (e.g. @nonagon-link/mcp@0.3.12). Because your private key is passed via env, running an unpinned latest version amplifies supply-chain risk. --ignore-scripts prevents dependency install scripts from running. Use a dedicated wallet with a small balance for payments. NONAGON_PAY_TO is the allow-list for Solana USDC payees; unset, every Solana USDC payment is refused. JPYC / EVM USDC payees are allowed separately by NONAGON_EVM_PAY_TO; unset, every EVM payment is refused (EVM payments also need NONAGON_EVM_PRIVATE_KEY). The NONAGON LINK payees (public values that appear as payTo in every 402) are below. Never copy them from an untrusted 402.

EnvironmentNONAGON_PAY_TO (Solana USDC)NONAGON_EVM_PAY_TO (JPYC / EVM USDC)
Production (Solana mainnet; Ethereum / Polygon / Base)8yXpNyyPg9iGdMST8BRyz7HEJVbQG81VP6kHBCKXrdH80x7b689c9b29e5e51700f19d4bb02b382fb418f34d
Testing (Solana devnet; Sepolia / Amoy / Base Sepolia)6JdW8xNvXrghY7acKXzMn2pJoK88g6nnAVU3YNo1YiF80xcaeb3ef5dcea1557765323379a292fc6b4011831

1. Overview

NonagonLink MCP is a Model Context Protocol (MCP) server that lets AI agents such as Claude / GPT-4 call paid APIs with USDC via NonagonLink's x402 payment infrastructure. Search (search_listings) → details of the chosen listing (get_listing) → capped purchase (pay_and_call) → token management (get_active_tokens) → payment history and spending (get_payment_history / get_spending) can all be completed through MCP alone.

Available Tools

Tool nameFunction
pay_and_callGET uses query; POST uses body. not_paid means MCP can determine payment was not executed; paymentSignatureSent records signing. Signed GET422 and gateway not_paid header classification require NONAGON_LINK_BASE_URL. Pay the specified paid API and fetch data. Solana USDC (maxPaymentUsdc required, default cap 0.100, payTo on NONAGON_PAY_TO). EVM inline upstream GET charges after receiving the complete body. Pre-send 429 limits (payer settlement failures, payer/provider concurrency) return not_paid / doNotPayAgain: false. Every 429 is decided after acquiring the authorization and abandons it; unconfirmed abandonment remains unknown. If another request is executing it, a 409 unknown comes first. On gateway not_paid sign a new authorization and never execute the old one. TX_TIMEOUT is unknown: do not pay again. Inspect the gateway outcome independently of the MCP display. With an EVM key and NONAGON_EVM_PAY_TO: JPYC / TEST_JPYSC (maxPaymentJpy); EVM USDC only when MCP_MAX_PAYMENT_EVM_USDC_CAP is set (maxPaymentEvmUsdc)
search_listingsSearch public listings with short space-separated words for the kind of data, subject area, or source, ranked by matched words, returning a summary of each candidate (price, payability, rating, health, missing information). Keep dates and values for the API out of the search words
get_listingFor one listing chosen from search_listings (providerId and listingId), get the proxyUrl, httpMethod and funnelAttribution to pass to pay_and_call, plus how to call it (parameter schema, input notes, query example) and response samples
get_active_tokensSummary of currently valid masked tokens and remaining validity. May be empty because inline payments issue no access token
get_payment_historyPayment history for this server's wallets (latest N, filterable by status). Includes inline payments, and the EVM wallet's payments when an EVM key is set
get_spendingCumulative spending for this server's wallets by period (day / week / month / all), with a per-currency breakdown, including the EVM wallet when an EVM key is set

Search terms for search_listings

Split the request into words that find the API and values that the API receives. Put 2–5 words for the kind of data, its subject area, or its source into q, separated by spaces (Japanese and English both work; up to 200 characters). Listings whose name, description, or category contains any word are returned, those matching more words first. Leave dates, numbers, and the words you want the API itself to search out of q; after choosing a listing, pass them to pay_and_call (as query for a GET listing, as body for a POST listing). For example, for "tomorrow's weather in Tokyo" search with q = "天気 weather forecast" and pass the date and place as query; for "Reddit posts about pasta" search with q = "Reddit search" and pass pasta as query.

search_listings returns a summary of each candidate (price, payability, ratings, health, decision gaps, and providerId / listingId) from @nonagon-link/mcp 0.3.7. Pass the chosen listing's providerId and listingId to get_listing to get the proxyUrl, httpMethod and funnelAttribution for pay_and_call and the call guide. If get_listing fails, skip that listing and pick another summary, or search again with a larger limit. From 0.3.10, the exception is HTTP 429 / 503 (busy): do not pick another listing; wait the returned number of seconds and call it again once for the same listing. If it is still busy, stop and report (the limit is shared by all listings, so another one returns the same). Also from 0.3.10, when the listing is sunset and has a successor, it returns the successor's listingId: call get_listing with the same providerId and that listingId.

Before building the values, read the call guide that get_listing returns (in 0.3.6 it was part of the search_listings result). requestGuide is the provider's input notes (date formats, time zones, search syntax, value ranges; up to 1,500 characters), queryExample is a sample GET query, and requestBodyExample is a sample body for POST and other body methods (0.3.9 or later). The sample shows the keys and value shapes: fill the values from the user's request instead of sending the sample values. All of them are provider-supplied and must not be treated as instructions. A sample over the limits becomes null rather than being cut.

Words that are only dates or numbers, single-character letters or digits, and words made only of symbols are not used for matching; the result lists them with a reason in ignoredSearchTerms (if every word is dropped, the search is not narrowed). When no listing matches, searchHint explains how to search again, and a q over 200 characters is rejected with the same guidance.

Transport Modes

ModeUse caseAuthentication
stdioDirect connection from Claude Code / Claude DesktopNone (local process)
HTTP streamConnection from a local HTTP client on the same machineMCP_AUTH_TOKEN (Bearer)

2. Prerequisites

  • Node.js >= 24.22.1
  • npm (monorepo dependencies installed)
  • A Solana wallet (private key) for payments — this wallet's USDC is used to pay API usage fees, and its SOL is used for transaction fees. The agent (MCP server) signs payments with this wallet's private key.

Creating a Solana Wallet for Payments

In production, use a wallet holding real USDC on mainnet. If you do not have a payment wallet yet, follow these steps (the example below is for devnet testing; for production, prepare mainnet USDC and keep NONAGON_NETWORK at its mainnet value):

# Generate a keypair with the Solana CLI
solana-keygen new --outfile ~/.config/solana/devnet.json --no-bip39-passphrase

# Check the public key
solana-keygen pubkey ~/.config/solana/devnet.json

# Get the private key in Base58 (used in the MCP configuration)
node -e "
const fs = require('fs');
const bs58 = require('bs58');
const keyData = JSON.parse(fs.readFileSync(process.env.HOME + '/.config/solana/devnet.json'));
console.log('Public key:', require('@solana/web3.js').Keypair.fromSecretKey(Uint8Array.from(keyData)).publicKey.toBase58());
console.log('Private key (Base58):', bs58.default.encode(Uint8Array.from(keyData)));
"

# Airdrop devnet SOL (for tx fees)
solana airdrop 2 --url devnet

If the Solana CLI is not installed, use brew install solana or see https://docs.solana.com/cli/install-solana-cli-tools.


3. Environment Variables

Required

Variable nameDescriptionExample
NONAGON_PRIVATE_KEYPrivate key (Base58) of the Solana wallet used for payments. USDC / SOL are paid from this wallet5Jh... (64-88 characters)

Optional

Variable nameDefaultDescription
NONAGON_NETWORKsolana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpSolana network (CAIP-2). Defaults to mainnet (production, real USDC). For devnet testing, specify solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1
NONAGON_PAY_TO(unset = Solana payments refused)Comma-separated Solana 402 payTo allow-list for pay_and_call (NONAGON LINK platform wallet; values in the quick-start table). Do not copy payTo from an untrusted 402. Unset refuses every Solana USDC payment; EVM payments are governed by NONAGON_EVM_PAY_TO
MCP_MAX_PAYMENT_USDC_CAP0.100Ceiling for maxPaymentUsdc (Solana USDC only). 0.1–10, decimal notation, at most 6 decimals
NONAGON_EVM_PRIVATE_KEY(unset = Solana USDC only)EVM wallet key (0x + 64 hex) for JPYC / TEST_JPYSC, for EVM USDC when MCP_MAX_PAYMENT_EVM_USDC_CAP is set, and for signing the EIP-712 AgentChallenge that reads the EVM wallet's history and spending. Only valid when NONAGON_NETWORK is Solana mainnet or devnet (the server refuses to start otherwise). Use a dedicated wallet with a small balance
NONAGON_EVM_PAY_TO(unset = EVM payments refused)Comma-separated EVM 402 payTo allow-list (NONAGON LINK EVM treasury; values in the quick-start table). Unset refuses every EVM payment (JPYC and EVM USDC)
MCP_MAX_PAYMENT_JPY_CAP100Ceiling for maxPaymentJpy (yen-denominated listings). 100–1000 (below 100 the server does not start), at most 4 decimals. Ethereum JPYC listings start at 300
MCP_MAX_PAYMENT_EVM_USDC_CAP(unset = EVM USDC never paid)Turns on EVM USDC and caps maxPaymentEvmUsdc per call (2–10 USDC). Needs NONAGON_EVM_PRIVATE_KEY and NONAGON_EVM_PAY_TO
NONAGON_LINK_BASE_URL(unset)Required for search_listings, get_listing, get_payment_history and get_spending. Base URL of the NonagonLink API (e.g. https://api.nnglink.ai). If unset, these tools return an error
MCP_AUTH_TOKEN(unset)Required only in HTTP stream mode (not needed in stdio mode, the default for Claude Desktop/Code). A Bearer authentication token generated by the operator to protect the local HTTP endpoint. Generate a random secret of at least 32 bytes with openssl rand -base64 32 or similar (at least 43 base64url characters or 64 hex characters)
LOG_LEVELinfoLog level

⚠️ EVM payments (JPYC, EVM USDC): an EVM payment is a signed EIP-3009 authorization, and any third party that receives it (such as the host you call) can execute it on-chain itself. The money can only go to the treasury in NONAGON_EVM_PAY_TO, but you then get no service and no payment record. There is no session or daily total limit: keep each cap as low as you need, keep the EVM wallet balance small, and do not pay_and_call URLs you do not trust. When paymentStatus is unknown, do not retry; check authorizationState(from, nonce) on the token contract.


4. How to Verify Operation

Method A: Run from source (for contributors)

Use this only when you have cloned the repository and want to run the development source directly. For normal usage, follow the "Quick start" section at the top of this page (npm package @nonagon-link/mcp).

1. Create the MCP configuration file

Add to your project's .claude/settings.json:

{
  "mcpServers": {
    "nonagon-link": {
      "command": "npx",
      "args": ["tsx", "apps/nonagon_link/src/mcp/server.ts"],
      "cwd": "/path/to/nonagon_link",
      "env": {
        "NONAGON_PRIVATE_KEY": "<private key (Base58) of the Solana wallet used for payments>",
        "NONAGON_NETWORK": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
        "NONAGON_LINK_BASE_URL": "https://api.nnglink.ai",
        "NONAGON_PAY_TO": "8yXpNyyPg9iGdMST8BRyz7HEJVbQG81VP6kHBCKXrdH8",
        "LOG_LEVEL": "debug"
      }
    }
  }
}

2. Check in Claude Code

> /mcp

If the server with the configuration key name (nonagon-link) is shown as connected, it worked.

3. Test a tool call

Ask Claude something like:

Use the get_active_tokens tool to fetch a summary of the currently valid masked tokens

get_active_tokens returns maskedToken, proxyUrl, expiresAt, and remainingMinutes; it never returns raw token values.

Example of a successful response:

{
  "tokens": [
    {
      "maskedToken": "agt_abcd...mnop",
      "proxyUrl": "https://api.nnglink.ai/api/proxy/weather-api/current",
      "expiresAt": "2026-05-11T12:00:00Z",
      "remainingMinutes": 45
    }
  ]
}

Method B: MCP Inspector (GUI)

Use the official MCP GUI debugging tool.

# Run from the project root
NONAGON_PRIVATE_KEY=<private-key> \
NONAGON_PAY_TO=8yXpNyyPg9iGdMST8BRyz7HEJVbQG81VP6kHBCKXrdH8 \
NONAGON_LINK_BASE_URL=https://api.nnglink.ai \
npx @modelcontextprotocol/inspector npx tsx apps/nonagon_link/src/mcp/server.ts

A browser window opens, where you can check the following:

  • Tools tab: pay_and_call / search_listings / get_listing / get_active_tokens / get_payment_history / get_spending are displayed
  • Tool execution: you can enter arguments and invoke tools directly
  • Schema check: verify that each tool's input schema is correct

Method C: HTTP stream mode

HTTP stream binds only to 127.0.0.1, so it is for local clients on the same machine. It cannot be exposed as a public endpoint over the network.

In HTTP stream mode, setting MCP_AUTH_TOKEN is required. Send Authorization: Bearer <MCP_AUTH_TOKEN> with every request.

Use a CSPRNG-generated secret of at least 32 bytes for MCP_AUTH_TOKEN. The configured value is expected to be at least 43 base64url characters or 64 hex characters.

# Terminal 1: start the server
NONAGON_PRIVATE_KEY=<private-key> \
NONAGON_PAY_TO=8yXpNyyPg9iGdMST8BRyz7HEJVbQG81VP6kHBCKXrdH8 \
NONAGON_LINK_BASE_URL=https://api.nnglink.ai \
NONAGON_NETWORK=solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp \
MCP_AUTH_TOKEN=<32-byte-random-base64url-token> \
npx tsx apps/nonagon_link/src/mcp/server.ts --transport http --port 3002
# Terminal 2: health check with curl (MCP initialize)
curl -X POST http://localhost:3002/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <32-byte-random-base64url-token>" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
      "protocolVersion": "2025-03-26",
      "capabilities": {},
      "clientInfo": { "name": "test", "version": "1.0" }
    }
  }'

Example of a successful response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2025-03-26",
    "capabilities": { "tools": {} },
    "serverInfo": { "name": "nonagon_link", "version": "1.0.0" }
  }
}

5. pay_and_call Example

GET listings take query (requires @nonagon-link/mcp 0.3.3 or later; older versions drop it silently; an object of strings, finite numbers or booleans); POST takes body (any JSON object / array / scalar / null). Map get_listing httpMethod to method. GET body, nonempty POST query, duplicate decoded keys and collisions with existing URL keys are rejected before any request; POST query:{} is treated as omitted. Existing URL encoding is preserved; query is limited to 64 parameters and 4096 serialized characters including existing values. Example: {"method":"GET","query":{"query":"日本語 & + %","page":0,"include":false}}. Only an unsigned GET402 whose final URL has zero query parameters is checked against an available queryParams schema before signing. If schema is absent, invalid, unsupported or over budget, validation is skipped and the existing payment policy still applies; payment proceeds as before. Nonempty queries use the gateway validation, including page-size clamping.

not_paid means the MCP can determine that payment was not executed. Every executed tool result includes boolean paymentSignatureSent; not_paid is not synonymous with unsigned. Classifying a signed GET422 as not_paid requires NONAGON_LINK_BASE_URL to be configured with an official (nnglink.ai / *.nnglink.ai) or local (localhost / 127.0.0.1) host, the same origin, the exact /api/proxy/{providerSlug}/{listingSlug} route, a complete JSON body within 8 KiB with code SCHEMA_VALIDATION_FAILED / QUERY_TOO_LARGE / SCHEMA_UNSUPPORTED, and no PAYMENT-RESPONSE, X-PAYMENT-RESPONSE (including the saved receipt) or X-Proxy-Payment-Id. This is the configured gateway's rejection before payment execution; correct query and retry. Any other signed failure is also not_paid when the configured gateway (same host, origin and exact proxy route conditions as above) returns X-Nonagon-Payment-Status: not_paid and X-Nonagon-Do-Not-Pay-Again: false with none of the three receipts above (@nonagon-link/mcp 0.3.5 or later; older versions keep showing unknown). The body paymentStatus is never used. Retry with a new signature at most once and stop if it fails again; do not execute the old authorization yourself. For EVM retain authorization (network / asset / from / nonce / validBefore): it remains valid until validBefore. A signed not_paid result does not independently prove on-chain non-execution. Other signed failures and communication failures retain paid / unknown according to the receipt; on unknown do not retry automatically and check authorizationState(from, nonce).

{
  "success": false,
  "error": "API returned 422",
  "httpStatus": 422,
  "paymentStatus": "not_paid",
  "paymentInfo": null,
  "authorization": {
    "network": "eip155:137",
    "asset": "<token contract>",
    "from": "<your wallet>",
    "nonce": "<signed nonce>",
    "validBefore": "<expiry>"
  },
  "paymentSignatureSent": true,
  "queryErrorHint": "The configured gateway rejected the query before executing payment; a signed request was sent. Correct the query and retry. For EVM, retain the authorization lookup fields; the authorization remains valid until validBefore."
}

Prerequisites

  • A Solana wallet holding USDC for payments (production = real USDC on mainnet / testing = fake USDC on devnet). You need USDC on the same network as your NONAGON_NETWORK setting
  • An API Provider registered on NonagonLink must exist

Calling from Claude Code

Use the pay_and_call tool to call the following API:
- URL: https://api.nnglink.ai/api/proxy/weather-api/current
- Method: POST
- Body: { "city": "Tokyo" }
- Payment cap: 0.05 USDC   # maxPaymentUsdc (required, greater than 0 up to a maximum of 0.100)

Response Structure

{
  "success": true,
  "data": { ... },
  "paymentSignatureSent": true,
  "paymentStatus": "paid",
  "paymentInfo": {
    "currency": "USDC",
    "amount": "0.01",
    "amountUsdc": "0.01",
    "txSignature": "5xKt...",
    "network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
    "payer": "<your wallet>",
    "paidAt": "2026-10-05T00:00:00.000Z"
  }
}

paymentStatus is paid, not_paid or unknown. On unknown (a signed payment was sent but the result is not confirmed), do not retry automatically: a retry can pay twice. For EVM payments, check authorizationState(from, nonce). For yen tokens (JPYC / TEST_JPYSC), amount is in that currency and amountUsdc is null.

For an unsigned result, confirm paymentSignatureSent:false together with paymentStatus being not_paid (a free API or a reused token, for example). paymentInfo can be null while paymentStatus is unknown (an EVM payment whose result is unknown), so a null paymentInfo alone does not mean nothing was paid.

On Error

Error responses carry paymentStatus too. An error after the payment was signed and sent can be paid or unknown, so do not treat success: false alone as «nothing was paid».

{
  "success": false,
  "error": "PAYMENT_EXCEEDS_LIMIT",
  "currency": "USDC",
  "required": "0.08",
  "max": "0.05",
  "requiredUsdc": "0.08",
  "maxPaymentUsdc": 0.05,
  "hint": "Increase maxPaymentUsdc if this price is acceptable, or choose a cheaper listing via search_listings.",
  "paymentStatus": "not_paid", "paymentSignatureSent": false
}

6. Security

SSRF Protection

The proxyUrl of pay_and_call is automatically validated as follows:

  • Private IPs rejected (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16)
  • Loopback rejected (127.0.0.0/8, ::1)
  • Link-local rejected (169.254.0.0/16)
  • DNS rebinding prevention (pinnedFetch couples DNS resolution and connection)
  • Only HTTPS URLs allowed
  • Exposing HTTP stream to anything other than 127.0.0.1 is prohibited

Log Redaction

  • URL query parameters/paths are masked (https://api.example.com/***)
  • Access tokens are masked (agt_abcd...mnop)
  • Private keys are never written to logs

HTTP Stream Mode Authentication

  • Bearer token authentication via MCP_AUTH_TOKEN
  • Binds only to 127.0.0.1 (local clients on the same machine only; remote exposure prohibited)
  • Per-session TokenStore isolates multiple clients

7. Troubleshooting

The MCP server does not start

MCP env validation failed:
  - NONAGON_PRIVATE_KEY: Base58 Solana private key format

→ Set the NONAGON_PRIVATE_KEY environment variable.

Unsupported MCP env keys: <legacy-key>. Use only live runtime env vars.

→ Legacy env vars are not supported. Use only the live runtime env vars in the table (including NONAGON_PAY_TO).

pay_and_call returns SSRF blocked

{ "success": false, "error": "Blocked destination: private/internal network", "paymentStatus": "not_paid", "paymentSignatureSent": false }

→ Private IPs / localhost cannot be called. Specify a public HTTPS URL.

pay_and_call ends with a client timeout

→ One pay_and_call can take several minutes. It waits up to 200 seconds for each upstream request (fetching the 402 and the paid request), up to 400 seconds in total, plus time to prepare the payment; the call as a whole has no upper limit. Give the client a tool timeout of about 7 minutes (420000 ms) or more (a guide, not a guarantee). Claude Code's default limit is about 28 hours, so only revisit MCP_TOOL_TIMEOUT or a timeout in .mcp.json if you have set one.

→ On a timeout or cancel, @nonagon-link/mcp 0.3.12 and later pay nothing if the payment header has not been sent yet. After it was sent, or with a client that does not send a cancel, the payment can still go through and the agent never sees the result.Do not retry automatically. A missing row in get_payment_history does not prove that nothing was paid (the earlier call may finish later). If you cannot confirm the outcome, do not retry.

get_active_tokens returns an empty array

→ There are no tokens yet because you have not called an API with pay_and_call. This is normal behavior.

The MCP server does not appear in Claude Code

  1. Check that the path in .claude/settings.json is correct
  2. Check that cwd points to the project root
  3. Run npx tsx apps/nonagon_link/src/mcp/server.ts directly and check for errors

HTTP stream mode returns 401

→ Check that the Authorization: Bearer <MCP_AUTH_TOKEN> header is correct.

当サイトでは、利用状況の把握と改善のためにアクセス解析 (Google アナリティクス) を使用します。「同意する」を選ぶと、閲覧ページ等の計測情報が Google LLC(米国)へ送信されます。詳細: プライバシーポリシー / 利用者情報の外部送信について