UnifyAPI

UnifyAPI

One API key and one billing rail for hundreds of API tools across many providers — exposed to AI agents through a single MCP endpoint and billed per call with x402 crypto payments.

Category
访问服务器

README

UnifyAPI

One API key and one billing rail for hundreds of API tools across many providers — exposed to AI agents through a single MCP endpoint and billed per call with x402 crypto payments.

UnifyAPI is a full-stack demo platform (inspired by the MCP + x402 ecosystem) built with Next.js 16, PostgreSQL + Prisma 7, and x402. Agents connect once and call any tool; humans manage keys, balance, and usage from a dashboard.


Features

  • Tool catalog — 24 seeded tools across 12 categories and 13 providers.
  • Three access surfaces
    • REST: POST /api/call/{slug}
    • MCP (JSON-RPC): POST /api/mcpinitialize, tools/list, tools/call
    • OpenAPI 3.1 spec: GET /api/openapi
    • Machine-readable agent card: GET /api/agent-card
  • Privy authentication — email / Google / wallet login with embedded wallets; falls back to a demo email login when Privy isn't configured.
  • API-key auth — hashed keys, Bearer tokens, revocation.
  • Per-call billing — every call validates input, checks balance, executes, charges, and records usage atomically.
  • x402 crypto payments — top up balance with USDC; real verify/settle through a facilitator, with an automatic simulation mode when not configured.
  • Live + mock tools — weather (Open-Meteo) and crypto price (CoinGecko) hit real key-less APIs; the rest return realistic mock data.
  • Dashboard — balance, top-up, key management, usage history.
  • Tool playground — run real calls from the tool detail page.

Tech stack

Layer Choice
Framework Next.js 16 (App Router, Turbopack) + React 19 + TypeScript
Styling Tailwind CSS v4
Database PostgreSQL via Prisma 7 (prisma-client generator + @prisma/adapter-pg)
Payments x402 (USDC on Base / Base-Sepolia)

Getting started

1. Install

npm install

2. Start a database

For local development, run a zero-install Postgres with Prisma:

npm run db:dev      # starts a local Prisma Postgres server (keep this running)

This prints connection URLs. The default .env is already pointed at the local server (postgres://postgres:postgres@localhost:51214/template1).

Production: set DATABASE_URL in .env to your own PostgreSQL connection string instead.

3. Create the schema & seed data

In a second terminal:

npm run db:push     # create tables
npm run db:seed     # load categories, providers, and tools

4. Run the app

npm run dev

Open http://localhost:3000.


Using the API

Create an account and key:

  1. Go to /login, enter any email (passwordless demo auth).
  2. On /dashboard, click Top up (credits instantly in simulation mode) and Create new key.

Call a tool over REST:

curl -X POST http://localhost:3000/api/call/crypto.price \
  -H "Authorization: Bearer uak_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "coin": "bitcoin", "vs": "usd" }'

Call a tool over MCP:

curl -X POST http://localhost:3000/api/mcp \
  -H "Authorization: Bearer uak_live_..." \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
       "params":{"name":"weather__current","arguments":{"latitude":-6.2,"longitude":106.8}}}'

MCP tool names replace dots with double underscores: weather.currentweather__current.


Enabling real x402 payments

By default the server runs in simulation mode: top-ups credit instantly and no on-chain settlement happens. To enable real crypto payments, fill these in .env:

X402_PAY_TO="0xYourReceivingWalletAddress"
X402_NETWORK="base-sepolia"                  # or "base" for mainnet
X402_FACILITATOR_URL="https://x402.org/facilitator"
# Mainnet via Coinbase CDP facilitator also needs:
# CDP_API_KEY_ID="..."
# CDP_API_KEY_SECRET="..."

With X402_PAY_TO set, POST /api/payments/topup returns HTTP 402 with payment requirements. An x402-capable client/wallet completes the payment and retries with an X-PAYMENT header, which the server verifies and settles through the facilitator before crediting the balance.

The wallet, network, and facilitator credentials must be supplied by you — they are the only pieces that can't be bundled into the demo.


Project structure

prisma/
  schema.prisma         # data model
  seed.ts               # catalog seed
src/
  app/
    page.tsx            # landing
    tools/              # catalog + tool detail (+ playground)
    docs/               # documentation
    login/  dashboard/  # account UI
    api/
      tools/            # public catalog
      call/[slug]/      # authenticated tool execution + billing
      mcp/              # MCP JSON-RPC endpoint
      openapi/          # OpenAPI 3.1 spec
      agent-card/       # agent discovery card
      keys/  me/  auth/ # account management
      payments/topup/   # x402 top-up
  lib/
    prisma.ts  apiKeys.ts  auth.ts
    catalog.ts validate.ts execute.ts  billing.ts  x402.ts
  components/           # client UI (CodeTabs, Playground, CatalogSearch)

Authentication (Privy)

Set NEXT_PUBLIC_PRIVY_APP_ID and PRIVY_APP_SECRET (from dashboard.privy.io) to enable real auth: email, Google, and crypto-wallet login, each with an embedded wallet. The client signs in with Privy, and the server verifies the Privy access token and bridges it into a session (src/app/api/auth/privy/route.ts). With those vars empty, the app uses a passwordless demo login so you can run it immediately.

Deployment

See DEPLOY.md for step-by-step Vercel and Docker instructions, plus the full environment-variable checklist. In short:

  • Vercel: import the repo (uses vercel.json), set env vars, point DATABASE_URL at managed Postgres.
  • Docker: docker compose up --build brings up the app + Postgres together.

Live vs mock tools

11 tools call real, key-less upstreams (weather, crypto price/market, FX, geocode, timezone, dictionary, translation, news). The rest return realistic mock data — wire them to real providers in src/lib/execute.ts.

Notes & caveats (it's a demo)

  • Rate limiting, caching, and retries are described in the UI but not fully implemented.
  • The x402 mainnet path needs a Coinbase CDP facilitator; testnet works with the public facilitator.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选