Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(x402): upgrade to spec v2 with CAIP-2 networks and Bazaar discovery

nirholas93ea675ac666
diff --git a/api/_lib/x402-spec.js b/api/_lib/x402-spec.js
index 6ef6cf875..7f359abc9 100644
--- a/api/_lib/x402-spec.js
+++ b/api/_lib/x402-spec.js
@@ -1,11 +1,25 @@
// x402 protocol — facilitator-mediated micropayments.
// Spec: https://x402.org / https://github.com/coinbase/x402
//
-// This module implements the *standard* x402 wire flow used by x402scan and
-// agentcash. (api/_lib/x402.js is the unrelated Pump.fun agent-skill flow.)
+// This module implements the *standard* x402 wire flow used by agentic.market,
+// x402scan, and Coinbase's Bazaar. v2 wire format (April 2026 spec):
+//
+// {
+// "x402Version": 2,
+// "error": "X-PAYMENT header is required",
+// "resource": { "url": "...", "description": "...", "mimeType": "application/json" },
+// "accepts": [
+// { "scheme": "exact", "network": "eip155:8453", "amount": "1000",
+// "asset": "0x...", "payTo": "0x...", "maxTimeoutSeconds": 60, "extra": {...} }
+// ],
+// "extensions": { "bazaar": { input, inputSchema, output:{example,schema}, bodyType, method } }
+// }
+//
+// Networks use CAIP-2 IDs in v2: `eip155:<chainId>` for EVM, `solana:<genesis-prefix>`
+// for Solana. The legacy `api/_lib/x402.js` is the unrelated Pump.fun agent-skill flow.
//
// Server flow on a paid resource:
-// 1. No X-PAYMENT header → 402 with { x402Version, accepts:[paymentRequirements] }
+// 1. No X-PAYMENT header → 402 with the body shape above.
// 2. Client retries with X-PAYMENT (base64-encoded PaymentPayload).
// 3. Server POSTs facilitator /verify with { x402Version, paymentPayload, paymentRequirements }
// → { isValid, invalidReason?, payer? }
@@ -15,7 +29,14 @@
import { env } from './env.js';
-export const X402_VERSION = 1;
+export const X402_VERSION = 2;
+
+// CAIP-2 network IDs as advertised by Coinbase x402 facilitators (PayAI, CDP).
+// Solana mainnet's CAIP-2 namespace uses the truncated genesis-block hash.
+export const NETWORK_BASE_MAINNET = 'eip155:8453';
+export const NETWORK_BASE_SEPOLIA = 'eip155:84532';
+export const NETWORK_SOLANA_MAINNET = 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp';
+export const NETWORK_SOLANA_DEVNET = 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1';
export class X402Error extends Error {
constructor(code, message, status = 402) {
@@ -25,22 +46,32 @@ export class X402Error extends Error {
}
}
-// One PaymentRequirements entry per supported network.
-export function paymentRequirements({ resource, description = '' } = {}) {
+// One v2 PaymentRequirements entry per supported network. Base mainnet first
+// — agentic.market's validator inspects the first entry for its supported-network
+// check, and Base is the most broadly recognized option in the Bazaar.
+//
+// In v2, `resource` / `description` / `mimeType` are top-level on the 402 body
+// (not per-accepts), and the price field is `amount` (not `maxAmountRequired`).
+export function paymentRequirements() {
const common = {
scheme: 'exact',
- maxAmountRequired: env.X402_MAX_AMOUNT_REQUIRED,
- resource,
- description,
- mimeType: 'application/json',
+ amount: env.X402_MAX_AMOUNT_REQUIRED,
maxTimeoutSeconds: 60,
- extra: { name: 'USDC', decimals: 6 },
};
const out = [];
+ if (env.X402_PAY_TO_BASE) {
+ out.push({
+ ...common,
+ network: NETWORK_BASE_MAINNET,
+ payTo: env.X402_PAY_TO_BASE,
+ asset: env.X402_ASSET_ADDRESS_BASE,
+ extra: { name: 'USDC', version: '2', decimals: 6 },
+ });
+ }
if (env.X402_PAY_TO_SOLANA) {
out.push({
...common,
- network: 'solana',
+ network: NETWORK_SOLANA_MAINNET,
payTo: env.X402_PAY_TO_SOLANA,
asset: env.X402_ASSET_MINT_SOLANA,
// PayAI's Solana facilitator requires clients to build the SPL transfer
@@ -49,22 +80,13 @@ export function paymentRequirements({ resource, description = '' } = {}) {
extra: { name: 'USDC', decimals: 6, feePayer: env.X402_FEE_PAYER_SOLANA },
});
}
- if (env.X402_PAY_TO_BASE) {
- out.push({
- ...common,
- network: 'base',
- payTo: env.X402_PAY_TO_BASE,
- asset: env.X402_ASSET_ADDRESS_BASE,
- extra: { name: 'USDC', version: '2', decimals: 6 },
- });
- }
return out;
}
function facilitatorFor(network) {
- if (network === 'solana')
+ if (network === NETWORK_SOLANA_MAINNET || network === NETWORK_SOLANA_DEVNET || network === 'solana')
return { url: env.X402_FACILITATOR_URL_SOLANA, token: env.X402_FACILITATOR_TOKEN_SOLANA };
- if (network === 'base')
+ if (network === NETWORK_BASE_MAINNET || network === NETWORK_BASE_SEPOLIA || network === 'base')
return { url: env.X402_FACILITATOR_URL_BASE, token: env.X402_FACILITATOR_TOKEN_BASE };
throw new X402Error('unsupported_network', `unsupported network: ${network}`, 400);
}
@@ -149,8 +171,8 @@ async function callFacilitator(network, path, body) {
// /api/x402-status to surface misconfigurations before a paying client hits them.
export async function probeFacilitators() {
const targets = [
- { network: 'solana', ...facilitatorFor('solana') },
- { network: 'base', ...facilitatorFor('base') },
+ { network: NETWORK_BASE_MAINNET, ...facilitatorFor(NETWORK_BASE_MAINNET) },
+ { network: NETWORK_SOLANA_MAINNET, ...facilitatorFor(NETWORK_SOLANA_MAINNET) },
];
const seen = new Map();
const results = [];
@@ -266,18 +288,113 @@ export function encodePaymentResponseHeader(settleResult) {
return Buffer.from(JSON.stringify(body), 'utf8').toString('base64');
}
-export function send402(res, requirements, error = 'X-PAYMENT header is required') {
- const accepts = Array.isArray(requirements) ? requirements : [requirements];
+// Long-form description used for the top-level `resource.description` and
+// (lightly trimmed) for the bazaar extension. Stays in one place so the 402
+// challenge, the /.well-known/x402.json discovery file, and any operator
+// dashboards stay in sync.
+export const RESOURCE_DESCRIPTION =
+ 'three.ws MCP — Streamable HTTP transport (MCP 2025-06-18) exposing 3D avatar viewer, glTF/GLB model validation/inspection/optimization, and Solana agent data as JSON-RPC 2.0 tool calls. Pay-per-call in USDC on Base mainnet (eip155:8453) or Solana mainnet. ≤256 tools/call output, ≤32-message JSON-RPC batches. Operated by three.ws.';
+
+// Bazaar discovery extension — agentic.market reads this to render input/output
+// hints in its catalog and to power its endpoint validator. Shape matches
+// declareDiscoveryExtension({ input, inputSchema, output:{example,schema}, bodyType }).
+export function bazaarExtension() {
+ return {
+ method: 'POST',
+ bodyType: 'json',
+ discoverable: true,
+ input: {
+ jsonrpc: '2.0',
+ id: 1,
+ method: 'tools/call',
+ params: {
+ name: 'validate_model',
+ arguments: { url: 'https://example.com/model.glb' },
+ },
+ },
+ inputSchema: {
+ type: 'object',
+ required: ['jsonrpc', 'method'],
+ properties: {
+ jsonrpc: { type: 'string', const: '2.0' },
+ id: { type: ['string', 'number'] },
+ method: {
+ type: 'string',
+ enum: ['initialize', 'tools/list', 'tools/call', 'ping'],
+ description: 'MCP JSON-RPC method.',
+ },
+ params: {
+ type: 'object',
+ description:
+ 'For tools/call: { name, arguments }. Tool names include validate_model, inspect_model, optimize_model, search_public_avatars, solana_register, solana_reputation, and others — see tools/list.',
+ },
+ },
+ },
+ output: {
+ example: {
+ jsonrpc: '2.0',
+ id: 1,
+ result: {
+ content: [{ type: 'text', text: '{"ok":true,"warnings":[],"meta":{"vertices":12345}}' }],
+ },
+ },
+ schema: {
+ type: 'object',
+ properties: {
+ jsonrpc: { type: 'string', const: '2.0' },
+ id: { type: ['string', 'number'] },
+ result: {
+ type: 'object',
+ properties: {
+ content: {
+ type: 'array',
+ items: {
+ type: 'object',
+ required: ['type', 'text'],
+ properties: {
+ type: { type: 'string', enum: ['text'] },
+ text: { type: 'string' },
+ },
+ },
+ },
+ },
+ },
+ error: {
+ type: 'object',
+ properties: {
+ code: { type: 'number' },
+ message: { type: 'string' },
+ },
+ },
+ },
+ },
+ },
+ };
+}
+
+// Build the v2 PaymentRequired body. Top-level `resource` carries url/description/
+// mimeType (per v2 spec); per-accept entries no longer repeat them.
+export function build402Body({ resourceUrl, accepts, error = 'X-PAYMENT header is required' }) {
+ return {
+ x402Version: X402_VERSION,
+ error,
+ resource: {
+ url: resourceUrl,
+ description: RESOURCE_DESCRIPTION,
+ mimeType: 'application/json',
+ },
+ accepts: Array.isArray(accepts) ? accepts : [accepts],
+ extensions: {
+ bazaar: bazaarExtension(),
+ },
+ };
+}
+
+export function send402(res, { resourceUrl, accepts, error } = {}) {
res.statusCode = 402;
res.setHeader('content-type', 'application/json; charset=utf-8');
res.setHeader('cache-control', 'no-store');
- res.end(
- JSON.stringify({
- x402Version: X402_VERSION,
- error,
- accepts,
- }),
- );
+ res.end(JSON.stringify(build402Body({ resourceUrl, accepts, error })));
}
// Resolve the canonical resource URL the client hit, so the facilitator can
diff --git a/api/_mcp/auth.js b/api/_mcp/auth.js
index d65249311..ec5d65301 100644
--- a/api/_mcp/auth.js
+++ b/api/_mcp/auth.js
@@ -43,15 +43,14 @@ export async function authenticateRequest(req, res) {
return { auth, x402Ctx: null };
}
- const requirements = paymentRequirements({
- resource: resolveResourceUrl(req, '/api/mcp'),
- description: 'MCP tool call',
- });
+ const resourceUrl = resolveResourceUrl(req, '/api/mcp');
+ const requirements = paymentRequirements();
if (paymentHeader) {
try {
const verified = await verifyPayment({ paymentHeader, requirements });
const x402Ctx = {
+ resourceUrl,
requirements,
requirement: verified.requirement,
paymentPayload: verified.paymentPayload,
@@ -74,12 +73,12 @@ export async function authenticateRequest(req, res) {
x402Ctx,
};
} catch (err) {
- sendX402Error(res, requirements, err);
+ sendX402Error(res, { resourceUrl, accepts: requirements }, err);
return null;
}
}
- send402(res, requirements);
+ send402(res, { resourceUrl, accepts: requirements });
return null;
}
@@ -90,13 +89,10 @@ export async function handleSse(req, res) {
// so x402scan / x402 clients can discover the price. Invalid bearers still
// get 401 with WWW-Authenticate so OAuth clients can re-auth correctly.
if (!bearer && !req.headers['x-payment']) {
- return send402(
- res,
- paymentRequirements({
- resource: resolveResourceUrl(req, '/api/mcp'),
- description: 'MCP tool call',
- }),
- );
+ return send402(res, {
+ resourceUrl: resolveResourceUrl(req, '/api/mcp'),
+ accepts: paymentRequirements(),
+ });
}
const auth = await authenticateBearer(bearer, { audience: env.MCP_RESOURCE });
if (!auth) return send401(res, 'missing or invalid access token');
diff --git a/api/_mcp/payments.js b/api/_mcp/payments.js
index 1de43f20e..81a93d93b 100644
--- a/api/_mcp/payments.js
+++ b/api/_mcp/payments.js
@@ -3,9 +3,9 @@ import { X402Error, send402 } from '../_lib/x402-spec.js';
const log = logger('mcp');
-export function sendX402Error(res, requirements, err) {
+export function sendX402Error(res, { resourceUrl, accepts }, err) {
if (err instanceof X402Error) {
- if (err.status === 402) return send402(res, requirements, err.message);
+ if (err.status === 402) return send402(res, { resourceUrl, accepts, error: err.message });
res.statusCode = err.status;
res.setHeader('content-type', 'application/json; charset=utf-8');
res.end(JSON.stringify({ error: err.code, error_description: err.message }));
diff --git a/api/mcp.js b/api/mcp.js
index e3ffb5b72..7200a2761 100644
--- a/api/mcp.js
+++ b/api/mcp.js
@@ -53,7 +53,11 @@ export default wrap(async (req, res) => {
});
res.setHeader('x-payment-response', encodePaymentResponseHeader(settled));
} catch (err) {
- return sendX402Error(res, x402Ctx.requirements, err);
+ return sendX402Error(
+ res,
+ { resourceUrl: x402Ctx.resourceUrl, accepts: x402Ctx.requirements },
+ err,
+ );
}
}
diff --git a/api/wk.js b/api/wk.js
index 3f19e9c51..685487614 100644
--- a/api/wk.js
+++ b/api/wk.js
@@ -3,7 +3,13 @@
import { cors, json, method, wrap, error } from './_lib/http.js';
import { env } from './_lib/env.js';
-import { paymentRequirements, X402_VERSION } from './_lib/x402-spec.js';
+import {
+ paymentRequirements,
+ bazaarExtension,
+ build402Body,
+ NETWORK_BASE_MAINNET,
+ NETWORK_SOLANA_MAINNET,
+} from './_lib/x402-spec.js';
// ── agent-attestation-schemas ─────────────────────────────────────────────────
@@ -69,12 +75,20 @@ function handleOauthProtectedResource(req, res) {
function handleX402(req, res) {
const mcpResource = `${env.APP_ORIGIN}/api/mcp`;
- const accepts = paymentRequirements({ resource: mcpResource, description: 'MCP tool call' });
- return json(res, 200, {
- x402Version: X402_VERSION,
- accepts,
- pump_agent_payments: { prep: '/api/pump/accept-payment-prep', confirm: '/api/pump/accept-payment-confirm', balances: '/api/pump/balances' },
- }, { 'cache-control': 'public, max-age=300' });
+ const body = build402Body({ resourceUrl: mcpResource, accepts: paymentRequirements() });
+ return json(
+ res,
+ 200,
+ {
+ ...body,
+ pump_agent_payments: {
+ prep: '/api/pump/accept-payment-prep',
+ confirm: '/api/pump/accept-payment-confirm',
+ balances: '/api/pump/balances',
+ },
+ },
+ { 'cache-control': 'public, max-age=300' },
+ );
}
// ── x402 Bazaar discovery (/.well-known/x402.json) ───────────────────────────
@@ -95,28 +109,32 @@ function handleX402Discovery(req, res) {
const price = RAW_AMOUNT_TO_USDC(env.X402_MAX_AMOUNT_REQUIRED);
const accepts = [];
- if (env.X402_PAY_TO_SOLANA) {
+ if (env.X402_PAY_TO_BASE) {
accepts.push({
scheme: 'exact',
- network: 'solana',
- network_label: 'solana-mainnet',
+ network: NETWORK_BASE_MAINNET,
+ network_label: 'base-mainnet',
+ amount: env.X402_MAX_AMOUNT_REQUIRED,
price,
- payTo: env.X402_PAY_TO_SOLANA,
- asset: env.X402_ASSET_MINT_SOLANA,
+ payTo: env.X402_PAY_TO_BASE,
+ asset: env.X402_ASSET_ADDRESS_BASE,
asset_symbol: 'USDC',
- extra: { name: 'USDC', decimals: 6, feePayer: env.X402_FEE_PAYER_SOLANA },
+ maxTimeoutSeconds: 60,
+ extra: { name: 'USDC', version: '2', decimals: 6 },
});
}
- if (env.X402_PAY_TO_BASE) {
+ if (env.X402_PAY_TO_SOLANA) {
accepts.push({
scheme: 'exact',
- network: 'base',
- network_label: 'base-mainnet',
+ network: NETWORK_SOLANA_MAINNET,
+ network_label: 'solana-mainnet',
+ amount: env.X402_MAX_AMOUNT_REQUIRED,
price,
- payTo: env.X402_PAY_TO_BASE,
- asset: env.X402_ASSET_ADDRESS_BASE,
+ payTo: env.X402_PAY_TO_SOLANA,
+ asset: env.X402_ASSET_MINT_SOLANA,
asset_symbol: 'USDC',
- extra: { name: 'USDC', version: '2', decimals: 6 },
+ maxTimeoutSeconds: 60,
+ extra: { name: 'USDC', decimals: 6, feePayer: env.X402_FEE_PAYER_SOLANA },
});
}
@@ -142,9 +160,11 @@ function handleX402Discovery(req, res) {
path: '/api/mcp',
url: mcpUrl,
method: 'POST',
- description: 'MCP 2025-06-18 Streamable HTTP transport — 3D avatar viewer, glTF model validation/inspection/optimization, and Solana agent data exposed as MCP tools. JSON-RPC 2.0 batch-aware. Currency: USDC.',
+ description:
+ 'MCP 2025-06-18 Streamable HTTP transport — 3D avatar viewer, glTF model validation/inspection/optimization, and Solana agent data exposed as MCP tools. JSON-RPC 2.0 batch-aware. Currency: USDC.',
mimeType: 'application/json',
accepts,
+ extensions: { bazaar: bazaarExtension() },
links: {
openapi: `${origin}/openapi.json`,
docs: `${origin}/docs/mcp`,
diff --git a/api/x402-status.js b/api/x402-status.js
index 1a4a43bb2..67490b921 100644
--- a/api/x402-status.js
+++ b/api/x402-status.js
@@ -14,10 +14,7 @@ export default wrap(async (req, res) => {
if (cors(req, res, { methods: 'GET,OPTIONS' })) return;
if (!method(req, res, ['GET'])) return;
- const accepts = paymentRequirements({
- resource: `${env.APP_ORIGIN}/api/mcp`,
- description: 'MCP tool call',
- });
+ const accepts = paymentRequirements();
const facilitators = await probeFacilitators();
const ok = facilitators.every((f) => f.ok);
diff --git a/public/studio/studio.css b/public/studio/studio.css
index d3cc093f3..084f2561c 100644
--- a/public/studio/studio.css
+++ b/public/studio/studio.css
@@ -1,166 +1,856 @@
+/* Widget Studio — three-column layout. */
+
:root {
- --accent: #6a5cff;
- --border: #2a2a36;
- --bg: #0a0a0f;
- --panel: #14141c;
- --muted: #888;
- --header-h: 64px;
+ --accent: #8b5cf6;
+ --accent-strong: #a78bfa;
+ --border: #2a2a36;
+ --border-soft: rgba(255, 255, 255, 0.08);
+ --bg: #0a0a0f;
+ --panel: #14141c;
+ --panel-soft: #1b1b25;
+ --muted: #888;
+ --text: #eee;
+ --danger: #f87171;
+ --header-h: 60px;
+ --radius-sm: 6px;
+ --radius-md: 10px;
+ --radius-lg: 14px;
}
+
+* {
+ box-sizing: border-box;
+}
+
+html,
body {
- background-color: var(--bg);
- color: #eee;
- font-family: 'Inter', sans-serif;
- padding-top: var(--header-h);
- display: flex;
- flex-direction: column;
- min-height: 100vh;
- margin: 0;
- overflow-x: hidden;
- }
- .main-content {
- flex: 1;
- display: flex;
- padding: 2rem;
- gap: 2rem;
- max-width: 1400px;
- margin: 0 auto;
- width: 100%;
- }
- .config-panel {
- width: 380px;
- flex-shrink: 0;
- background-color: var(--panel);
- padding: 1.5rem;
- border-radius: 12px;
- border: 1px solid var(--border);
- height: fit-content;
- }
- .preview-area {
- flex: 1;
- display: flex;
- flex-direction: column;
- gap: 1.5rem;
- }
- .preview-box {
- flex: 1;
- min-height: 400px;
- border: 1px dashed var(--border);
- border-radius: 12px;
- display: flex;
- align-items: center;
- justify-content: center;
- background-image:
- linear-gradient(45deg, #1a1a24 25%, transparent 25%),
- linear-gradient(-45deg, #1a1a24 25%, transparent 25%),
- linear-gradient(45deg, transparent 75%, #1a1a24 75%),
- linear-gradient(-45deg, transparent 75%, #1a1a24 75%);
- background-size: 20px 20px;
- background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
- padding: 2rem;
- transition: background-color 0.3s ease;
- }
- .preview-box.light {
- background-color: #f0f0f0;
- }
- .preview-box.dark {
- background-color: #111;
- }
- .code-box {
- background-color: var(--panel);
- border: 1px solid var(--border);
- border-radius: 12px;
- padding: 1rem;
- }
- h1, h2, h3 {
- font-family: 'Space Grotesk', sans-serif;
- font-weight: 600;
- margin-top: 0;
- }
- .form-group {
- margin-bottom: 1.5rem;
- }
- label {
- display: block;
- font-size: 0.9rem;
- font-weight: 500;
- margin-bottom: 0.5rem;
- color: #ccc;
- }
- input[type="text"],
- select {
- width: 100%;
- box-sizing: border-box;
- background-color: #0a0a0f;
- border: 1px solid var(--border);
- color: #eee;
- padding: 0.6rem 0.8rem;
- border-radius: 6px;
- font-size: 1rem;
- }
- input[type="text"]:focus,
- select:focus {
- outline: none;
- border-color: var(--accent);
- box-shadow: 0 0 0 2px rgba(106, 92, 255, 0.3);
- }
- .toggle-group {
- display: flex;
- gap: 0.5rem;
- }
- .toggle-group button {
- flex: 1;
- padding: 0.6rem;
- background-color: transparent;
- border: 1px solid var(--border);
- color: var(--muted);
- cursor: pointer;
- border-radius: 6px;
- font-size: 0.9rem;
- transition: all 0.2s ease;
- }
- .toggle-group button:hover {
- border-color: #4a4a58;
- color: #fff;
- }
- .toggle-group button.active {
- background-color: var(--accent);
- color: white;
- border-color: var(--accent);
- }
- textarea {
- width: 100%;
- box-sizing: border-box;
- height: 150px;
- background-color: #0a0a0f;
- border: 1px solid var(--border);
- color: #eee;
- padding: 0.8rem;
- border-radius: 6px;
- font-family: monospace;
- font-size: 0.9rem;
- resize: none;
- }
- .copy-btn {
- position: absolute;
- top: 0.5rem;
- right: 0.5rem;
- background-color: #2a2a36;
- color: #ccc;
- border: none;
- padding: 0.3rem 0.6rem;
- border-radius: 4px;
- cursor: pointer;
- font-size: 0.8rem;
- }
- .copy-btn:hover {
- background-color: #3a3a4a;
- }
- .code-wrapper {
- position: relative;
- }
- #widget-preview-container {
- transition: all 0.2s ease-in-out;
- border-radius: 8px;
- overflow: hidden;
- box-shadow: 0 10px 30px rgba(0,0,0,0.3);
- }
+ margin: 0;
+ padding: 0;
+}
+
+body.studio-body {
+ background: var(--bg);
+ color: var(--text);
+ font-family: 'Inter', system-ui, -apple-system, sans-serif;
+ font-size: 14px;
+ line-height: 1.45;
+ min-height: 100vh;
+ overflow-x: hidden;
+}
+
+a {
+ color: var(--accent-strong);
+ text-decoration: none;
+}
+a:hover {
+ text-decoration: underline;
+}
+
+/* ── header ────────────────────────────────────────────────────────────────── */
+.studio-header {
+ position: sticky;
+ top: 0;
+ z-index: 50;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 1rem;
+ height: var(--header-h);
+ padding: 0 1.25rem;
+ background: rgba(10, 10, 15, 0.85);
+ backdrop-filter: blur(12px);
+ border-bottom: 1px solid var(--border-soft);
+}
+
+.studio-header h1 {
+ display: flex;
+ align-items: center;
+ gap: 0.55rem;
+ margin: 0;
+ font-family: 'Space Grotesk', sans-serif;
+ font-size: 1rem;
+ font-weight: 600;
+ letter-spacing: -0.01em;
+}
+
+.studio-header h1 a {
+ display: inline-flex;
+ align-items: center;
+ color: var(--text);
+}
+
+.studio-header .wordmark-logo {
+ width: 26px;
+ height: 26px;
+ display: block;
+}
+
+.studio-tag {
+ color: var(--muted);
+ font-weight: 500;
+ font-size: 0.85rem;
+ letter-spacing: 0.02em;
+}
+
+.studio-header nav {
+ display: flex;
+ align-items: center;
+ gap: 0.25rem;
+ flex-wrap: wrap;
+}
+
+.studio-header nav a,
+.studio-header nav button {
+ display: inline-flex;
+ align-items: center;
+ padding: 0.4rem 0.7rem;
+ font-size: 0.85rem;
+ font-weight: 500;
+ color: rgba(255, 255, 255, 0.65);
+ border-radius: var(--radius-sm);
+ transition: color 0.15s ease, background 0.15s ease;
+}
+
+.studio-header nav a:hover,
+.studio-header nav button:hover {
+ color: #fff;
+ background: rgba(255, 255, 255, 0.05);
+ text-decoration: none;
+}
+
+.studio-header nav a[aria-current='page'] {
+ color: #fff;
+ background: rgba(139, 92, 246, 0.16);
+}
+
+/* ── layout ────────────────────────────────────────────────────────────────── */
+.studio-layout {
+ display: grid;
+ grid-template-columns: 320px minmax(0, 1fr) 380px;
+ gap: 1rem;
+ padding: 1rem;
+ max-width: 1600px;
+ margin: 0 auto;
+ align-items: start;
+}
+
+.studio-col-left,
+.studio-col-mid,
+.studio-col-right {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+ min-width: 0;
+}
+
+.studio-col-mid {
+ position: sticky;
+ top: calc(var(--header-h) + 1rem);
+}
+
+@media (max-width: 1280px) {
+ .studio-layout {
+ grid-template-columns: 280px minmax(0, 1fr) 340px;
+ }
+}
+
+@media (max-width: 1100px) {
+ .studio-layout {
+ grid-template-columns: 1fr;
+ }
+ .studio-col-mid {
+ position: static;
+ order: -1;
+ }
+}
+
+/* ── panels ────────────────────────────────────────────────────────────────── */
+.panel {
+ background: var(--panel);
+ border: 1px solid var(--border);
+ border-radius: var(--radius-lg);
+ padding: 1.1rem 1.1rem 1.2rem;
+}
+
+.panel h2 {
+ font-family: 'Space Grotesk', sans-serif;
+ font-size: 0.95rem;
+ font-weight: 600;
+ margin: 0 0 0.8rem;
+ letter-spacing: -0.005em;
+ color: #fff;
+}
+
+.panel .note,
+.note {
+ font-size: 0.8rem;
+ color: var(--muted);
+ margin: -0.4rem 0 0.8rem;
+}
+
+.muted {
+ color: var(--muted);
+}
+
+/* ── avatar list ───────────────────────────────────────────────────────────── */
+.avatar-list {
+ display: grid;
+ grid-template-columns: repeat(2, minmax(0, 1fr));
+ gap: 0.55rem;
+}
+
+.avatar-list[aria-busy='true']::before {
+ content: 'Loading avatars…';
+ grid-column: 1 / -1;
+ font-size: 0.8rem;
+ color: var(--muted);
+ padding: 0.6rem;
+}
+
+.avatar-card {
+ position: relative;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 0.4rem;
+ padding: 0.55rem 0.5rem 0.65rem;
+ background: var(--panel-soft);
+ border: 1px solid var(--border);
+ border-radius: var(--radius-md);
+ color: var(--text);
+ cursor: pointer;
+ transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease;
+ text-align: center;
+ font: inherit;
+}
+
+.avatar-card:hover {
+ border-color: rgba(139, 92, 246, 0.45);
+ background: #1f1f2a;
+}
+
+.avatar-card.selected {
+ border-color: var(--accent);
+ background: rgba(139, 92, 246, 0.1);
+ box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25) inset;
+}
+
+.avatar-card .thumb {
+ width: 100%;
+ aspect-ratio: 1 / 1;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border-radius: var(--radius-sm);
+ background: #0d0d14;
+ overflow: hidden;
+ font-size: 1.6rem;
+ color: rgba(255, 255, 255, 0.4);
+}
+
+.avatar-card .thumb img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ display: block;
+}
+
+.avatar-card .name {
+ font-size: 0.75rem;
+ font-weight: 500;
+ color: #ddd;
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ max-width: 100%;
+}
+
+.badge-demo {
+ font-size: 0.62rem;
+ letter-spacing: 0.06em;
+ text-transform: uppercase;
+ color: var(--accent-strong);
+ background: rgba(139, 92, 246, 0.15);
+ border: 1px solid rgba(139, 92, 246, 0.4);
+ padding: 0.1rem 0.35rem;
+ border-radius: 999px;
+}
+
+.empty {
+ grid-column: 1 / -1;
+ font-size: 0.8rem;
+ color: var(--muted);
+ padding: 0.5rem 0.2rem;
+}
+
+/* ── type grid ─────────────────────────────────────────────────────────────── */
+.type-grid {
+ display: grid;
+ grid-template-columns: 1fr;
+ gap: 0.5rem;
+}
+
+.type-card {
+ position: relative;
+ display: grid;
+ grid-template-columns: auto 1fr;
+ column-gap: 0.65rem;
+ row-gap: 0.15rem;
+ align-items: start;
+ padding: 0.65rem 0.7rem;
+ background: var(--panel-soft);
+ border: 1px solid var(--border);
+ border-radius: var(--radius-md);
+ color: var(--text);
+ cursor: pointer;
+ text-align: left;
+ transition: border-color 0.15s ease, background 0.15s ease;
+ font: inherit;
+}
+
+.type-card:hover {
+ border-color: rgba(139, 92, 246, 0.45);
+ background: #1f1f2a;
+}
+
+.type-card.selected {
+ border-color: var(--accent);
+ background: rgba(139, 92, 246, 0.1);
+}
+
+.type-card .icon {
+ grid-row: 1 / span 2;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ border-radius: 6px;
+ background: rgba(139, 92, 246, 0.12);
+ color: var(--accent-strong);
+ font-size: 0.95rem;
+}
+
+.type-card .label {
+ font-size: 0.85rem;
+ font-weight: 600;
+ color: #fff;
+}
+
+.type-card .desc {
+ font-size: 0.72rem;
+ color: var(--muted);
+ line-height: 1.35;
+}
+
+.type-card .pending {
+ grid-column: 2;
+ margin-top: 0.2rem;
+ font-size: 0.65rem;
+ letter-spacing: 0.06em;
+ text-transform: uppercase;
+ color: #f59e0b;
+}
+
+.pending-banner {
+ background: rgba(245, 158, 11, 0.08);
+ border: 1px solid rgba(245, 158, 11, 0.3);
+ color: #fbbf24;
+ padding: 0.6rem 0.7rem;
+ border-radius: var(--radius-sm);
+ font-size: 0.78rem;
+ margin-top: 0.6rem;
+}
+
+/* ── preview (mid column) ──────────────────────────────────────────────────── */
+.preview-shell {
+ background: var(--panel);
+ border: 1px solid var(--border);
+ border-radius: var(--radius-lg);
+ padding: 0.8rem;
+ display: flex;
+ flex-direction: column;
+ gap: 0.7rem;
+}
+
+.preview-frame {
+ position: relative;
+ width: 100%;
+ aspect-ratio: 1 / 1;
+ max-height: calc(100vh - var(--header-h) - 8rem);
+ background: #050507;
+ border-radius: var(--radius-md);
+ overflow: hidden;
+ background-image:
+ linear-gradient(45deg, #15151c 25%, transparent 25%),
+ linear-gradient(-45deg, #15151c 25%, transparent 25%),
+ linear-gradient(45deg, transparent 75%, #15151c 75%),
+ linear-gradient(-45deg, transparent 75%, #15151c 75%);
+ background-size: 24px 24px;
+ background-position: 0 0, 0 12px, 12px -12px, -12px 0;
+}
+
+.preview-frame iframe {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ border: 0;
+ display: block;
+}
+
+.preview-meta {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 0.6rem;
+ font-size: 0.78rem;
+}
+
+/* ── right column: tabs + form ─────────────────────────────────────────────── */
+.studio-right-tabs {
+ display: flex;
+ gap: 0.25rem;
+ margin: -0.4rem -0.4rem 0.9rem;
+ padding: 0.3rem;
+ background: #0d0d14;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-md);
+}
+
+.studio-right-tab {
+ flex: 1;
+ padding: 0.45rem 0.6rem;
+ background: transparent;
+ border: 0;
+ border-radius: 6px;
+ color: var(--muted);
+ font: inherit;
+ font-size: 0.82rem;
+ font-weight: 500;
+ cursor: pointer;
+ transition: background 0.15s ease, color 0.15s ease;
+}
+
+.studio-right-tab:hover {
+ color: #fff;
+}
+
+.studio-right-tab[aria-selected='true'] {
+ background: var(--accent);
+ color: #fff;
+}
+
+.config-form {
+ display: flex;
+ flex-direction: column;
+ gap: 0.7rem;
+}
+
+.field {
+ display: flex;
+ flex-direction: column;
+ gap: 0.3rem;
+ font-size: 0.8rem;
+ color: #ccc;
+}
+
+.field > span:first-child {
+ font-weight: 500;
+ color: #ccc;
+}
+
+.field.row {
+ flex-direction: row;
+ align-items: center;
+ gap: 0.5rem;
+}
+
+.field.row > span {
+ font-weight: 400;
+ color: #ddd;
+}
+
+.field input[type='text'],
+.field input[type='number'],
+.field input[type='url'],
+.field input[type='email'],
+.field input[type='password'],
+.field select,
+.field textarea {
+ width: 100%;
+ padding: 0.5rem 0.65rem;
+ background: #0d0d14;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-sm);
+ color: var(--text);
+ font: inherit;
+ font-size: 0.85rem;
+}
+
+.field input:focus,
+.field select:focus,
+.field textarea:focus {
+ outline: none;
+ border-color: var(--accent);
+ box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.25);
+}
+
+.field input[type='color'] {
+ width: 60px;
+ height: 30px;
+ padding: 2px;
+ background: #0d0d14;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-sm);
+ cursor: pointer;
+}
+
+.field input[type='checkbox'] {
+ width: 14px;
+ height: 14px;
+ accent-color: var(--accent);
+ cursor: pointer;
+}
+
+.field textarea {
+ resize: vertical;
+ min-height: 4rem;
+ font-family: inherit;
+}
+
+.type-fields {
+ display: flex;
+ flex-direction: column;
+ gap: 0.7rem;
+ padding-top: 0.7rem;
+ margin-top: 0.3rem;
+ border-top: 1px dashed var(--border);
+}
+
+.type-fields:empty {
+ display: none;
+}
+
+/* ── buttons ───────────────────────────────────────────────────────────────── */
+.btn-primary,
+.btn-ghost {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.4rem;
+ padding: 0.55rem 0.95rem;
+ border-radius: var(--radius-sm);
+ font: inherit;
+ font-weight: 500;
+ font-size: 0.85rem;
+ cursor: pointer;
+ transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
+ border: 1px solid transparent;
+}
+
+.btn-primary {
+ background: var(--accent);
+ color: #fff;
+ border-color: var(--accent);
+}
+
+.btn-primary:hover {
+ background: #7c3aed;
+ border-color: #7c3aed;
+}
+
+.btn-primary:disabled {
+ background: #4c3a78;
+ border-color: #4c3a78;
+ cursor: not-allowed;
+ opacity: 0.7;
+}
+
+.btn-ghost {
+ background: transparent;
+ color: #ddd;
+ border-color: var(--border);
+}
+
+.btn-ghost:hover {
+ background: rgba(255, 255, 255, 0.04);
+ border-color: #3a3a48;
+ color: #fff;
+}
+
+.btn-ghost:disabled {
+ cursor: not-allowed;
+ opacity: 0.5;
+}
+
+.btn-sm {
+ padding: 0.35rem 0.6rem;
+ font-size: 0.75rem;
+}
+
+.action-row {
+ display: flex;
+ gap: 0.6rem;
+ justify-content: flex-end;
+ flex-wrap: wrap;
+}
+
+.action-row .btn-primary {
+ flex: 1;
+ min-width: 140px;
+}
+
+.form-error {
+ margin: 0.4rem 0 0;
+ color: var(--danger);
+ font-size: 0.8rem;
+ background: rgba(248, 113, 113, 0.08);
+ border: 1px solid rgba(248, 113, 113, 0.3);
+ border-radius: var(--radius-sm);
+ padding: 0.5rem 0.6rem;
+}
+
+/* ── modal ─────────────────────────────────────────────────────────────────── */
+.modal-overlay {
+ position: fixed;
+ inset: 0;
+ background: rgba(5, 5, 9, 0.75);
+ backdrop-filter: blur(6px);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ z-index: 100;
+ padding: 1rem;
+ overflow-y: auto;
+}
+
+.modal-overlay[hidden] {
+ display: none;
+}
+
+.modal {
+ position: relative;
+ width: min(560px, 100%);
+ max-height: calc(100vh - 2rem);
+ overflow-y: auto;
+ background: var(--panel);
+ border: 1px solid var(--border);
+ border-radius: var(--radius-lg);
+ padding: 1.4rem 1.4rem 1.5rem;
+ box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
+}
+
+.modal h2 {
+ font-family: 'Space Grotesk', sans-serif;
+ margin: 0 0 0.4rem;
+ font-size: 1.15rem;
+ font-weight: 600;
+}
+
+.modal-close {
+ position: absolute;
+ top: 0.5rem;
+ right: 0.5rem;
+ width: 32px;
+ height: 32px;
+ border: 0;
+ background: transparent;
+ color: #aaa;
+ font-size: 1.4rem;
+ line-height: 1;
+ border-radius: var(--radius-sm);
+ cursor: pointer;
+}
+
+.modal-close:hover {
+ background: rgba(255, 255, 255, 0.06);
+ color: #fff;
+}
+
+.modal .field {
+ margin-top: 0.85rem;
+}
+
+.embed-preview {
+ width: 100%;
+ aspect-ratio: 1 / 1;
+ max-height: 340px;
+ margin: 0.85rem 0;
+ border-radius: var(--radius-md);
+ border: 1px solid var(--border);
+ background: #050507;
+ overflow: hidden;
+}
+
+.embed-preview iframe {
+ width: 100%;
+ height: 100%;
+ border: 0;
+ display: block;
+}
+
+.copy-row {
+ display: flex;
+ gap: 0.4rem;
+ align-items: stretch;
+}
+
+.copy-row input,
+.copy-row textarea {
+ flex: 1;
+ font-family: ui-monospace, 'SF Mono', Menlo, monospace;
+ font-size: 0.78rem;
+ background: #0d0d14;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-sm);
+ color: var(--text);
+ padding: 0.5rem 0.6rem;
+ resize: none;
+}
+
+.copy-row textarea {
+ min-height: 3.6rem;
+}
+
+.modal details {
+ margin-top: 0.85rem;
+}
+
+.modal details summary {
+ cursor: pointer;
+ font-size: 0.8rem;
+ color: #ccc;
+ padding: 0.3rem 0;
+}
+
+.modal details[open] summary {
+ margin-bottom: 0.4rem;
+}
+
+/* ── toast ─────────────────────────────────────────────────────────────────── */
+.toast {
+ position: fixed;
+ bottom: 1.2rem;
+ left: 50%;
+ transform: translateX(-50%);
+ background: #1f1f2a;
+ color: #fff;
+ padding: 0.6rem 1rem;
+ border-radius: 999px;
+ border: 1px solid var(--border);
+ font-size: 0.82rem;
+ box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
+ z-index: 200;
+}
+
+.toast[hidden] {
+ display: none;
+}
+
+/* ── tooltip (data-tooltip on any element) ────────────────────────────────── */
+[data-tooltip] {
+ position: relative;
+}
+
+[data-tooltip]::after {
+ content: attr(data-tooltip);
+ position: absolute;
+ bottom: calc(100% + 6px);
+ left: 50%;
+ transform: translateX(-50%) translateY(2px);
+ background: #1f1f2a;
+ color: #eee;
+ font-size: 0.72rem;
+ font-weight: 400;
+ line-height: 1.4;
+ padding: 0.45rem 0.6rem;
+ border-radius: var(--radius-sm);
+ border: 1px solid var(--border);
+ white-space: normal;
+ width: max-content;
+ max-width: 240px;
+ pointer-events: none;
+ opacity: 0;
+ transition: opacity 0.15s ease, transform 0.15s ease;
+ z-index: 30;
+ box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
+}
+
+[data-tooltip]:hover::after,
+[data-tooltip]:focus-visible::after {
+ opacity: 1;
+ transform: translateX(-50%) translateY(0);
+}
+
+/* ── launch panel (mounted by launch-panel.js) ────────────────────────────── */
+.launch-panel {
+ display: flex;
+ flex-direction: column;
+ gap: 0.7rem;
+}
+
+.launch-panel-desc {
+ font-size: 0.78rem;
+ line-height: 1.45;
+ margin: 0 0 0.3rem;
+}
+
+.launch-req {
+ color: var(--accent-strong);
+}
+
+.launch-field-err {
+ color: var(--danger);
+ font-size: 0.72rem;
+}
+
+.launch-file-input {
+ font-size: 0.8rem;
+ color: #ccc;
+}
+
+.bonding-curve-preview {
+ background: #0d0d14;
+ border: 1px solid var(--border);
+ border-radius: var(--radius-md);
+ padding: 0.7rem 0.8rem;
+ display: flex;
+ flex-direction: column;
+ gap: 0.45rem;
+}
+
+.bonding-curve-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+}
+
+.bonding-curve-pct {
+ font-family: 'Space Grotesk', sans-serif;
+ font-weight: 600;
+ color: var(--accent-strong);
+ font-size: 0.85rem;
+}
+
+.bonding-curve-track {
+ height: 6px;
+ background: #1f1f2a;
+ border-radius: 999px;
+ overflow: hidden;
+}
+
+.bonding-curve-fill {
+ height: 100%;
+ background: linear-gradient(90deg, var(--accent), var(--accent-strong));
+ transition: width 0.25s ease;
+ border-radius: 999px;
+}
+
+.bonding-curve-labels {
+ display: flex;
+ justify-content: space-between;
+ font-size: 0.68rem;
+ color: var(--muted);
+ letter-spacing: 0.04em;
+ text-transform: uppercase;
+}
diff --git a/scripts/dev-wk-server.mjs b/scripts/dev-wk-server.mjs
index cffa31fbf..7e908f132 100644
--- a/scripts/dev-wk-server.mjs
+++ b/scripts/dev-wk-server.mjs
@@ -7,6 +7,7 @@ import { createServer } from 'node:http';
import { config as dotenv } from 'dotenv';
dotenv({ path: new URL('../.env', import.meta.url) });
const { default: wkHandler } = await import('../api/wk.js');
+const { send402, paymentRequirements } = await import('../api/_lib/x402-spec.js');
const PORT = Number(process.env.PORT || 3030);
@@ -21,11 +22,31 @@ const ROUTES = {
const server = createServer(async (req, res) => {
const url = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
+
+ // Preview the live /api/mcp 402 challenge (skips auth/db so we just see the
+ // challenge body the agentic.market validator will hit on production).
+ if (url.pathname === '/api/mcp') {
+ res.setHeader('access-control-allow-origin', '*');
+ res.setHeader('access-control-allow-methods', 'GET,POST,OPTIONS');
+ res.setHeader('access-control-allow-headers', 'authorization, content-type, x-payment');
+ if (req.method === 'OPTIONS') {
+ res.statusCode = 204;
+ res.end();
+ return;
+ }
+ const proto = (req.headers['x-forwarded-proto'] || 'https').toString().split(',')[0].trim();
+ const host = (req.headers['x-forwarded-host'] || req.headers.host || 'three.ws').toString();
+ // Always quote the production URL — the validator pins on a stable resource string.
+ const resourceUrl = `${proto}://three.ws/api/mcp`;
+ send402(res, { resourceUrl, accepts: paymentRequirements() });
+ return;
+ }
+
const name = ROUTES[url.pathname];
if (!name) {
res.statusCode = 404;
res.setHeader('content-type', 'application/json');
- res.end(JSON.stringify({ error: 'not_found', path: url.pathname, known: Object.keys(ROUTES) }));
+ res.end(JSON.stringify({ error: 'not_found', path: url.pathname, known: [...Object.keys(ROUTES), '/api/mcp'] }));
return;
}
req.query = { name };
@@ -35,4 +56,5 @@ const server = createServer(async (req, res) => {
server.listen(PORT, () => {
console.log(`[dev-wk-server] listening on http://localhost:${PORT}`);
for (const path of Object.keys(ROUTES)) console.log(` → http://localhost:${PORT}${path}`);
+ console.log(` → http://localhost:${PORT}/api/mcp (v2 402 challenge preview)`);
});
diff --git a/tests/api/mcp.test.js b/tests/api/mcp.test.js
index 1cdac195f..66d76e463 100644
--- a/tests/api/mcp.test.js
+++ b/tests/api/mcp.test.js
@@ -64,9 +64,11 @@ const x402State = { verifyOk: false, verifyResult: null };
vi.mock('../../api/_lib/x402-spec.js', () => ({
X402Error: MockX402Error,
+ X402_VERSION: 2,
paymentRequirements: vi.fn(() => [
- { network: 'base', payTo: '0xrecipient', resource: 'https://app.test/api/mcp' },
+ { scheme: 'exact', network: 'eip155:8453', payTo: '0xrecipient', amount: '1000', asset: '0xusdc', maxTimeoutSeconds: 60 },
]),
+ bazaarExtension: vi.fn(() => ({ method: 'POST', bodyType: 'json', input: {}, inputSchema: {}, output: { example: {} } })),
verifyPayment: vi.fn(async () => {
if (!x402State.verifyOk)
throw new MockX402Error('invalid_payment', 'payment rejected', 402);
@@ -75,15 +77,23 @@ vi.mock('../../api/_lib/x402-spec.js', () => ({
settlePayment: vi.fn(async () => ({
success: true,
transaction: 'tx123',
- network: 'base',
+ network: 'eip155:8453',
payer: '0xpayer',
})),
encodePaymentResponseHeader: vi.fn(() => 'settlement-b64'),
- send402: vi.fn((res, requirements) => {
+ send402: vi.fn((res, { resourceUrl, accepts, error } = {}) => {
res.statusCode = 402;
res.setHeader('content-type', 'application/json; charset=utf-8');
- const accepts = Array.isArray(requirements) ? requirements : [requirements];
- res.end(JSON.stringify({ x402Version: 1, accepts }));
+ const list = Array.isArray(accepts) ? accepts : [accepts];
+ res.end(
+ JSON.stringify({
+ x402Version: 2,
+ error: error || 'X-PAYMENT header is required',
+ resource: { url: resourceUrl, description: 'MCP', mimeType: 'application/json' },
+ accepts: list,
+ extensions: { bazaar: { method: 'POST', bodyType: 'json' } },
+ }),
+ );
}),
resolveResourceUrl: vi.fn((req, path) => `https://app.test${path}`),
}));
@@ -347,7 +357,7 @@ describe('Protocol layer', () => {
const { status, body } = await invoke({ method: 'GET' });
expect(status).toBe(402);
- expect(body.x402Version).toBe(1);
+ expect(body.x402Version).toBe(2);
expect(Array.isArray(body.accepts)).toBe(true);
});
@@ -375,7 +385,7 @@ describe('Authentication', () => {
});
expect(status).toBe(402);
- expect(body.x402Version).toBe(1);
+ expect(body.x402Version).toBe(2);
});
it('POST with a bearer that fails authentication returns 401', async () => {
@@ -522,8 +532,12 @@ describe('x402 payment flow', () => {
});
expect(status).toBe(402);
- expect(body.x402Version).toBe(1);
- expect(body.accepts[0].network).toBe('base');
+ expect(body.x402Version).toBe(2);
+ expect(body.resource.url).toMatch(/\/api\/mcp$/);
+ expect(body.resource.mimeType).toBe('application/json');
+ expect(body.accepts[0].network).toBe('eip155:8453');
+ expect(body.accepts[0].amount).toBe('1000');
+ expect(body.extensions.bazaar).toBeDefined();
});
it('valid X-PAYMENT header passes payment verification and executes the tool', async () => {