Skip to main content
Glama

Token4u MCP Server

透過 x402 微支付讓 AI agent 調用 LLM API + 查詢 x402 消費明細。

純 external x402 模式:MCP server 本地管理 wallet 私鑰(~/.token4u-mcp/wallet.json,0o600),所有支付走 x402 鏈上 USDC(Base network),無需 token4u 帳號。

Installation

claude mcp add token4u-mcp -- npx -y token4u-mcp

Local build

npm install
npm run build

Related MCP server: cardzero-mcp

Environment Variables

Variable

Default

Description

TOKEN4U_API_URL

https://token4u.ai

token4u API base URL

TOKEN4U_WALLET_KEY

(optional)

Local wallet private key (takes priority over file)

TOKEN4U_BUDGET_LIMIT

(optional)

Max USD budget for LLM calls

TOKEN4U_DATA_DIR

~/.token4u-mcp

Directory for wallet key and session storage

Tools

1. token4u_wallet — Manage Local Wallet

Create and manage a local signing wallet for x402 payments.

Status(default)— check wallet state:

token4u_wallet action=status

Create — generate a new local wallet keypair or load an existing one:

token4u_wallet action=create

The private key is stored at ~/.token4u-mcp/wallet.json with 0o600 permissions and never leaves this MCP server.

Setup — get step-by-step funding guidance:

token4u_wallet action=setup

Shows your wallet address and instructions for depositing USDC on Base network.

2. token4u_chat — Paid LLM Chat

Call AI models via token4u, paid with USDC on Base via x402.

token4u_chat model=deepseek-v3 messages=[{"role":"user","content":"Hello!"}]

3. token4u_consumption — View Consumption Records

Query x402 consumption records for a given EVM wallet address (public API — no login required).

token4u_consumption address=0xYourWalletAddress page=1

Funding Your Wallet

This MCP server runs in pure external x402 mode — your local wallet must be funded with USDC on Base before making paid LLM calls.

Quick Start

  1. Create a wallet(if you haven't already):

    token4u_wallet action=create
  2. Get funding instructions:

    token4u_wallet action=setup
  3. Send USDC on Base to the wallet address shown. You can use:

    • MetaMask (or any EVM wallet) connected to Base network

    • Coinbase / exchange withdrawal to Base

    • Any Base bridge to on-ramp USDC

  4. Verify the balance is visible on-chain (e.g., basescan.org) — the x402 protocol reads your USDC balance directly from the chain.

Self-Custody

Your private key is at ~/.token4u-mcp/wallet.json (permissions: 0o600). You can import it into MetaMask or any EVM wallet for self-management:

  • MetaMask: Settings → Import Account → paste the private key

  • Rabby / Frame: similar "Import Private Key" flow

⚠️ Anyone with this private key can spend your USDC. Never share it.

x402 Flow

Each paid LLM call follows the x402 micropayment protocol:

  1. 402 Quote — POST without payment → server responds with HTTP 402 + payment details (price, recipient, network)

  2. Authorization Signature — Sign a typed data message authorizing the USDC transfer:

    • Permit2 (upto scheme with assetTransferMethod=permit2) — sign a PermitWitnessTransferFrom authorising a ceiling amount; the server settles only the actual cost post-execution (≤ ceiling)

    • EIP-3009 (exact scheme or legacy upto) — sign a TransferWithAuthorization for the exact amount

  3. PAYMENT-SIGNATURE — Re-send the request with a base64-encoded PAYMENT-SIGNATURE header containing the signed authorization

  4. SSE Stream — Server verifies the signature and streams the LLM response via Server-Sent Events

Security

  • Private keys are stored at ~/.token4u-mcp/wallet.json with 0o600 permissions

  • Private keys never leave this machine — all EIP-3009 and Permit2 signing happens locally

  • No token4u account required — the MCP server manages its own local wallet

  • All payments are on-chain USDC transfers on Base network

Development

# Install dependencies
npm install

# Type check
npm run typecheck

# Run tests
npm test

# Build
npm run build

# Run locally
node dist/index.js

License

MIT

Available Tools

3 tools
token4u_chatA

Chat with AI models via token4u using x402 micropayments (USDC on Base). Each call is priced per-model and paid via an EIP-3009 authorization from your local wallet. Requires a wallet — run token4u_wallet action=create first.

ParametersJSON Schema
NameRequiredDescriptionDefault
modelYestoken4u model name (e.g. deepseek-v3)
messagesYes
max_tokensNoMaximum tokens in the response
temperatureNoSampling temperature (0-2)

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the burden of behavioral disclosure. It reveals that each call is paid per-model via an EIP-3009 authorization from the local wallet, and that a wallet must exist. This is critical operational context. It doesn't mention return format or errors, but the payment trait is well covered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences, each earning its place: purpose and payment mechanism, per-model pricing, and prerequisite. No fluff or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema or annotations, the description covers the key aspects: what the tool does, how payment works, and what is required before calling. It doesn't explicitly state the response format, but 'chat' implies a model reply. Overall sufficient for a paid chat tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema already provides descriptions for model, max_tokens, and temperature (75% coverage). The description adds an example model name and clarifies per-model pricing, but does not add significant meaning for the messages parameter or further parameter syntax. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Chat'), specifies the resource ('AI models via token4u'), and adds the payment mechanism (x402 micropayments). This clearly differentiates it from sibling tools like token4u_wallet (wallet management) and token4u_consumption (usage tracking).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides a clear prerequisite: run token4u_wallet action=create first. It implies this tool is for chat actions requiring payment, but does not explicitly mention when to prefer this over token4u_consumption. Still, the wallet requirement is practical guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

token4u_consumptionA

Query x402 consumption records for a given EVM wallet address. Public API — no login required. Returns per-call records with model, token usage, credits, amount paid in USD, transaction hash, and timestamp.

ParametersJSON Schema
NameRequiredDescriptionDefault
pageNoPage number, default 1
addressYesEVM wallet address (0x...) to query x402 consumption records for
page_sizeNoPage size, default 10

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It states the API is public and requires no login, and it lists the exact return fields (model, token usage, credits, amount paid in USD, transaction hash, timestamp). It does not mention rate limits or error handling, but for a read-only query this is reasonably transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loaded with the purpose, and includes only essential details (public API, return fields). Every sentence earns its place without waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers purpose, public access, and return fields, which is important because no output schema exists. For a simple query tool with three parameters, it is fairly complete. It lacks details on pagination behavior or error conditions, but the schema covers page/page_size and default values, so the description meets the core needs.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, and the description does not add significant new parameter semantics beyond what the schema already provides. The description mentions 'given EVM wallet address' which aligns with the address parameter but adds no additional detail about page or page_size beyond the schema's defaults.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool queries x402 consumption records for a given EVM wallet address, using the specific verb 'Query' and identifying the resource and scope. This distinguishes it from sibling tools like token4u_wallet and token4u_chat, which likely handle wallet and chat functions respectively.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for usage: it is a public API requiring no login, intended for querying per-call consumption records for a wallet address. It does not explicitly mention alternatives or when not to use it, but the context is sufficient for basic selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

token4u_walletA

Manage local x402 wallet — create keypair, check status, and get funding guidance.

This is a pure external x402 mode: the MCP server manages a local wallet (~/.token4u-mcp/wallet.json, 0o600). All payments go through on-chain x402 USDC transactions on Base network. No token4u account or internal wallet required.

Actions:

  • status (default): Show local wallet address and whether it is newly created.

  • create: Generate a new local wallet keypair or load an existing one. The private key is stored at ~/.token4u-mcp/wallet.json with 0o600 permissions and never leaves this machine.

  • setup: Show step-by-step funding instructions — how to send USDC on Base to your local wallet address, and how to export the private key for self-custody.

ParametersJSON Schema
NameRequiredDescriptionDefault
actionNoWhich wallet operation to performstatus

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does so thoroughly. It discloses the wallet file location and permissions (~/.token4u-mcp/wallet.json, 0o600), that the private key never leaves the machine, how create loads or generates a keypair, and the underlying network (Base USDC). This far exceeds the minimum required.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the main purpose, followed by a concise context paragraph and an action list. Every sentence contributes useful information without fluff, making it scannable and appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given it has only one parameter, no annotations, and no output schema, the description is exceptionally complete. It explains the tool's purpose, all three actions with their effects, underlying network details, security properties, and prerequisite context (no token4u account needed), leaving no critical gaps for an agent to select and invoke it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Although the schema covers the single parameter 'action' with an enum and description, the description adds substantial meaning by explaining what each enum value does: status shows address/newly-created flag, create generates/loads a keypair with security details, and setup provides funding/export steps. This goes well beyond the schema's minimal 'Which wallet operation to perform.'

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb and resource: 'Manage local x402 wallet — create keypair, check status, and get funding guidance.' It clearly distinguishes from sibling tools (token4u_chat, token4u_consumption) by focusing solely on wallet operations and explicitly noting this is for external x402 mode without a token4u account.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear usage context: it is for 'pure external x402 mode' and notes 'No token4u account or internal wallet required,' which implies when to use this tool over alternatives that might require an account. However, it does not explicitly state when not to use it or name alternative tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 3 tool updatesv0.3.0
    • First observedtoken4u_chat
    • First observedtoken4u_consumption
    • First observedtoken4u_wallet

TDQS

A4.4/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: wallet management, chat with micropayments, and consumption record querying. There is no overlap or ambiguity between them; even the actions within token4u_wallet are well-separated.

Naming Consistency5/5

All tool names follow the consistent pattern 'token4u_<noun>' using snake_case. This makes the toolset predictable and easy to navigate for agents.

Tool Count5/5

With only 3 tools, the server is tightly scoped to its purpose of handling x402 micropayments via a local wallet. Each tool provides a distinct and necessary function, and none feel redundant or superfluous.

Completeness4/5

The set covers the full workflow: wallet creation/funding guidance, chat with micropayments, and transaction consumption queries. A minor gap is the lack of a direct balance-check tool, but the core functionality is complete for the stated purpose.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers