npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nuwa-ai/x402

v0.6.0

Published

Small helpers to add x402 payments to: - MCP servers: mark tools as paid and verify/settle before running (tracks the original x402 MCP specification) - HTTP/LLM proxies: gate endpoints with x402 and settle automatically (currently via a naive flat-price

Readme

@nuwa-ai/x402

Small helpers to add x402 payments to:

  • MCP servers: mark tools as paid and verify/settle before running (tracks the original x402 MCP specification)
  • HTTP/LLM proxies: gate endpoints with x402 and settle automatically (currently via a naive flat-price flow while v2 upto schema support is in progress)

Status

  • mcp – aligned with the original x402 MCP spec used by x402-compatible clients today.
  • llm – implements flat-price payments only; full v2 upto schema-based payments are under active development.

Exports

  • mcpcreatePaidMcpHandler(serverInit, serverOptions, { recipient, network, facilitator }) for Nextjs, referred to vercel's x402-mcp.
  • llmX402LlmPayments and helpers (createPaymentPlugin, logPaymentResponseHeader, decodePaymentResponseHeader)
  • Common types re-exported from x402/types

Install

  • In this monorepo it is consumed via workspace. For external projects: pnpm add @nuwa-ai/x402 x402 @modelcontextprotocol/sdk viem zod mcp-handler.

MCP: Paid Tools

import { privateKeyToAccount } from "viem/accounts";
import z from "zod";
import { createPaidMcpHandler, type FacilitatorConfig } from "@nuwa-ai/x402/mcp";
import { facilitator } from "@coinbase/x402"; // FacilitatorConfig implementation

const seller = privateKeyToAccount(process.env.SERVICE_PRIVATE_KEY as `0x${string}`);
const network = (process.env.NETWORK as "base" | "base-sepolia") ?? "base-sepolia";

export const handler = createPaidMcpHandler(
  (server) => {
    // Paid tool – requires a valid _meta["x402/payment"] from the client
    server.paidTool(
      "add",
      "Add two numbers",
      { price: 0.001 }, // USD
      { a: z.number().int(), b: z.number().int() },
      {},
      async (args) => ({ content: [{ type: "text", text: String(args.a + args.b) }] }),
    );

    // Free tool – works like a normal MCP tool
    server.tool(
      "hello",
      "Say hello",
      { name: z.string() },
      async (args) => ({ content: [{ type: "text", text: `Hello ${args.name}` }] }),
    );
  },
  { serverInfo: { name: "example-mcp", version: "0.0.1" } },
  { recipient: seller.address, facilitator: facilitator as unknown as FacilitatorConfig, network },
);

Behavior

  • If the client does not supply _meta["x402/payment"], the server returns an error with an accepts array describing acceptable payment requirements.
  • On success, the tool callback runs. Settlement is attempted afterward; if successful, _meta["x402/payment-response"] is attached to the result.
  • On the client side (xNUWA), the MCP client will automatically handle the payment and extract payment info.

HTTP/LLM: Payment-Gated Endpoints

import type { NextRequest } from "next/server";
import { X402LlmPayments, type EnsurePaymentConfig } from "@nuwa-ai/x402/llm";
import { privateKeyToAccount } from "viem/accounts";

const seller = privateKeyToAccount(process.env.SERVICE_PRIVATE_KEY as `0x${string}`);
const payments = new X402LlmPayments(); // or pass a FacilitatorConfig

export async function POST(request: NextRequest) {
  const config: EnsurePaymentConfig = {
    payTo: seller.address,
    price: 0.01,          // USD
    network: "base-sepolia",
    config: { description: "My paid API", mimeType: "application/json" },
  };

  return payments.gateWithX402Payment(request, config, async () => {
    // Your upstream work here (call model provider, etc.)
    return new Response(JSON.stringify({ ok: true }), { status: 200, headers: { "Content-Type": "application/json" } });
  });
}

Behavior

  • Without an X-PAYMENT header the handler returns 402 and a JSON body describing accepts (requirements).
  • With a valid payment: verifies first, runs your handler, then settles before returning. On success, adds X-PAYMENT-RESPONSE header with settlement details.
  • Pricing today is fixed per endpoint invocation; v2 upto schema-driven pricing is forthcoming.

Facilitator

  • The library uses x402/verify under the hood. You can pass a FacilitatorConfig to both MCP and LLM helpers.
  • With Coinbase’s facilitator, provide CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET, or import facilitator from @coinbase/x402 and pass it through.

Configuration Notes

  • price is in USD. The helpers compute the on-chain amount automatically for the selected network and USDC asset.
  • Supported networks: base-sepolia (default) and base.
  • For HTTP endpoints you can customize error messages, input/output schemas, and timeouts via config (PaymentMiddlewareConfig).

Utilities

  • logPaymentResponseHeader(response) – logs decoded X-PAYMENT-RESPONSE.
  • decodePaymentResponseHeader(responseOrHeaders) – parse the header programmatically.

See Also

  • End-to-end usage in examples/nextjs (OpenRouter proxy and paid MCP server). You can exercise a hosted build at https://xnuwa.app.