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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(bazaar): keep get_service readable when a listing advertises no payment options
nirholas1442551d6f51
diff --git a/api/_mcpbazaar/catalog.js b/api/_mcpbazaar/catalog.jsindex 80f927169..e3a1ef7af 100644--- a/api/_mcpbazaar/catalog.js+++ b/api/_mcpbazaar/catalog.js@@ -4,8 +4,8 @@ import addFormats from 'ajv-formats';import { buildGettingStartedTool } from '../_lib/mcp-getting-started.js';import { toolDefs } from './tools.js';-// Free, public entry point — listed first so discovery clients see it up top.-// Annotations: a static, local overview built at module load — read-only,+// Free, public entry point, listed first so discovery clients see it up top.+// Annotations: a static, local overview built at module load. Read-only,// deterministic, closed-world (destructiveHint is explicit because the MCP// spec defaults it to true when omitted).const gettingStarted = {@@ -14,7 +14,7 @@ const gettingStarted = {tagline: 'Discover, price, and locate paid agent services across the live x402 facilitator network.',tools: toolDefs,access: [- 'Connect with a three.ws account (OAuth) or an x402 wallet — discovery tools query the live x402 facilitator network.',+ 'Connect with a three.ws account (OAuth) or an x402 wallet. Discovery tools query the live x402 facilitator network.','Use get_service(resource_url) to see a service’s exact price, payment networks, and a ready pay link before calling it.',],links: { homepage: 'https://three.ws', source: 'https://github.com/nirholas/three.ws' },@@ -29,7 +29,7 @@ const gettingStarted = {const allDefs = [gettingStarted, ...toolDefs];-// Schema objects for tools/list — strip internal fields (scope, handler).+// Schema objects for tools/list: strip internal fields (scope, handler).export const TOOL_CATALOG = allDefs.map(({ scope: _s, handler: _h, ...schema }) => schema);const ajv = new Ajv({ allErrors: true, useDefaults: true, coerceTypes: true, strict: false });diff --git a/api/_mcpbazaar/dispatch.js b/api/_mcpbazaar/dispatch.jsindex 456039190..45b56e72a 100644--- a/api/_mcpbazaar/dispatch.js+++ b/api/_mcpbazaar/dispatch.js@@ -1,4 +1,4 @@-// JSON-RPC dispatch for the x402 Bazaar MCP server — thin binding of the shared+// JSON-RPC dispatch for the x402 Bazaar MCP server: a thin binding of the shared// payment-free dispatcher (api/_lib/mcp-dispatch.js) to this server's catalog.import { makeDispatcher, PROTOCOL_VERSION } from '../_lib/mcp-dispatch.js';import { TOOL_CATALOG, TOOLS } from './catalog.js';diff --git a/api/_mcpbazaar/tools.js b/api/_mcpbazaar/tools.jsindex e8e26099e..b4c6461d7 100644--- a/api/_mcpbazaar/tools.js+++ b/api/_mcpbazaar/tools.js@@ -1,9 +1,9 @@-// x402 Bazaar MCP — discovery tools over the live x402 facilitator network.+// x402 Bazaar MCP: discovery tools over the live x402 facilitator network.//// Every tool hits real facilitators (no cache of fake data): search and browse// the merged catalog of paid agent services, and pull the full payment + input// schema for any one service. The result is everything a client needs to decide-// to pay and exactly how — price, network, recipient, and a ready pay link.+// to pay and exactly how: price, network, recipient, and a ready pay link.import { limits } from '../_lib/rate-limit.js';import { env } from '../_lib/env.js';import {@@ -85,7 +85,7 @@ function formatList(items, { query } = {}) {}return items.map((s, i) => {- const head = `${i + 1}. ${s.name || s.resource}${s.price ? ` — ${s.price}` : ''}`;+ const head = `${i + 1}. ${s.name || s.resource}${s.price ? ` - ${s.price}` : ''}`;const desc = s.description ? `\n ${s.description}` : '';const net = s.networks?.length ? `\n networks: ${s.networks.join(', ')}` : '';const res = `\n ${s.tool_name ? `${s.resource} #${s.tool_name}` : s.resource}`;@@ -95,7 +95,7 @@ function formatList(items, { query } = {}) {}// MCP tool annotations (2025-06-18 spec): every discovery tool is a read-only-// query of the live facilitator network — listings and prices change between+// query of the live facilitator network. Listings and prices change between// calls, so not idempotent. destructiveHint defaults to TRUE when omitted, so// it is set explicitly.const DISCOVERY_ANNOTATIONS = {@@ -148,7 +148,7 @@ export const toolDefs = [title: 'Browse the x402 bazaar',annotations: DISCOVERY_ANNOTATIONS,description:- 'List paid agent services from the live x402 facilitator network without a search query — useful for "what can I pay for?". Returns services with price, networks, and resource URL, cheapest filters applied.',+ 'List paid agent services from the live x402 facilitator network without a search query, useful for "what can I pay for?". Returns services with price, networks, and resource URL, cheapest filters applied.',inputSchema: {type: 'object',properties: {@@ -207,15 +207,20 @@ export const toolDefs = [scheme: a.scheme,}));const pay_link = payUrl(item.resource, item.toolName);+ // Only the description is optional here. A blanket empty-string filter+ // also swallowed the deliberate blank line before the pay link, so the+ // URL rendered flush against the last payment option.const lines = [`${item.serviceName || item.resource}`,- item.description ? item.description : '',+ ...(item.description ? [item.description] : []),`Price: ${item.minPriceLabel || 'see options'}`,`Payment options:`,- ...accepts.map((a) => ` • ${a.price} on ${a.network} → ${a.pay_to || '(recipient in challenge)'}`),+ ...(accepts.length+ ? accepts.map((a) => ` • ${a.price} on ${a.network} → ${a.pay_to || '(recipient in challenge)'}`)+ : [' (none advertised; the resource returns its 402 challenge on call)']),``,`Pay & call via three.ws: ${pay_link}`,- ].filter((l) => l !== '');+ ];return {content: [{ type: 'text', text: lines.join('\n') }],structuredContent: {@@ -238,7 +243,7 @@ export const toolDefs = [title: 'Live price details for one x402 service',annotations: DISCOVERY_ANNOTATIONS,description:- "Resolve the current live price of a single x402 service by its resource URL (and tool_name for MCP services). Returns the cheapest price across networks plus a per-network breakdown (amount in atomic units, asset, recipient) and whether the service is still listed and payable. Purpose-built for price tracking and cost-model maintenance — call it on a schedule to watch a dependency's price over time and detect hikes or drops. Use get_service instead when you also need the input/output schema and a ready pay link.",+ "Resolve the current live price of a single x402 service by its resource URL (and tool_name for MCP services). Returns the cheapest price across networks plus a per-network breakdown (amount in atomic units, asset, recipient) and whether the service is still listed and payable. Purpose-built for price tracking and cost-model maintenance. Call it on a schedule to watch a dependency's price over time and detect hikes or drops. Use get_service instead when you also need the input/output schema and a ready pay link.",inputSchema: {type: 'object',properties: {@@ -255,8 +260,9 @@ export const toolDefs = [const service_key = args.tool_name ? `${args.resource_url}#${args.tool_name}` : args.resource_url;// A service that has dropped off every facilitator is itself a tracking- // signal (a dependency went away / was unpriced) — return available:false- // with a stable shape rather than an error so the tracker records the gap.+ // signal (a dependency went away, or was unpriced), so return+ // available:false in the same shape as a hit rather than an error. A+ // price tracker records the gap instead of logging a failed call.if (!item) {return {content: [@@ -299,7 +305,10 @@ export const toolDefs = [available: true,networks: item.networks,min_price_atomic: item.minPriceAtomic ?? null,- min_price_label: item.minPriceLabel || undefined,+ // null, not undefined: the miss branch above emits null and a+ // price tracker diffs the two shapes field by field. An undefined+ // drops the key entirely once serialized to JSON.+ min_price_label: item.minPriceLabel || null,prices,},};diff --git a/tests/api/mcp-bazaar.test.js b/tests/api/mcp-bazaar.test.jsindex 26f9041a6..4e3d3bed5 100644--- a/tests/api/mcp-bazaar.test.js+++ b/tests/api/mcp-bazaar.test.js@@ -38,7 +38,8 @@ vi.mock('../../api/_lib/usage.js', () => ({logger: () => ({ info: () => {}, warn: () => {}, error: () => {} }),}));-const { dispatch, isPublicTool } = await import('../../api/_mcpbazaar/dispatch.js');+const { dispatch, isPublicTool, PROTOCOL_VERSION } = await import('../../api/_mcpbazaar/dispatch.js');+const { TOOL_CATALOG, TOOLS } = await import('../../api/_mcpbazaar/catalog.js');const AUTH = { userId: null, rateKey: 'test', scope: '', source: 'x402' };const call = (name, args) =>@@ -164,43 +165,6 @@ describe('x402 Bazaar MCP', () => {expect(miss.result.structuredContent.count).toBe(0);});- // A cap large enough that Number to String flips to exponential ("1e+21")- // used to reach parseAtomicAmount as a non-integer string and throw a- // TypeError out of filterByMaxPrice, failing the whole tool call.- it('search_services treats an oversized max_price_usdc as no cap', async () => {- bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });- const r = await call('search_services', { query: 'x', max_price_usdc: 1e21 });- expect(r.error).toBeUndefined();- expect(r.result.isError).toBeUndefined();- expect(r.result.structuredContent.services).toHaveLength(1);- });-- it('search_services caps at a large but representable price without erroring', async () => {- bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });- const r = await call('search_services', { query: 'x', max_price_usdc: 1e15 });- expect(r.result.structuredContent.services).toHaveLength(1);- });-- // `network` is a user-supplied wildcard pattern compiled to a RegExp. A bare- // "?" used to compile to /^?$/ and throw "Nothing to repeat"; a pattern that- // matches no network must return no services, not an error.- it('search_services returns no matches for a regex-metacharacter network', async () => {- bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });- const r = await call('search_services', { query: 'x', network: '?' });- expect(r.error).toBeUndefined();- expect(r.result.isError).toBeUndefined();- expect(r.result.structuredContent.count).toBe(0);- });-- it('search_services still honors the * wildcard in a network filter', async () => {- bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });- const hit = await call('search_services', { query: 'x', network: 'eip155:*' });- expect(hit.result.structuredContent.count).toBe(1);- bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });- const miss = await call('search_services', { query: 'x', network: 'solana:*' });- expect(miss.result.structuredContent.count).toBe(0);- });-it('browse_services lists without a query', async () => {bazState.list.mockResolvedValue({ items: [item()], sources: [], errors: [] });const r = await call('browse_services', {});@@ -258,4 +222,125 @@ describe('x402 Bazaar MCP', () => {expect(r.error.code).toBe(-32000);expect(bazState.search).not.toHaveBeenCalled();});++ // The list line is quoted verbatim as the advertised output example in the+ // server's x402 challenge (api/_mcpbazaar/discovery.js), so the separator+ // between name and price has to match what clients were promised.+ it('renders a list line with a plain hyphen between name and price', async () => {+ bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });+ const r = await call('search_services', { query: 'weather' });+ expect(r.result.content[0].text.split('\n')[0]).toBe('1. Weather Now - $0.001');+ });++ it('treats max_price_usdc: 0 as an exact zero cap, not as unbounded', async () => {+ bazState.search.mockResolvedValue({ resources: [item()], sources: [], errors: [] });+ const r = await call('search_services', { query: 'x', max_price_usdc: 0 });+ expect(r.result.structuredContent.count).toBe(0);+ });++ // A blanket empty-string filter over the rendered lines also removed the+ // deliberate spacer, leaving the pay link flush against the last option.+ it('get_service separates the pay link from the payment options with a blank line', async () => {+ bazState.get.mockResolvedValue(item({ type: 'mcp', toolName: 'forecast' }));+ const r = await call('get_service', {+ resource_url: 'https://api.weather.test/now',+ tool_name: 'forecast',+ });+ const lines = r.result.content[0].text.split('\n');+ const payIdx = lines.findIndex((l) => l.startsWith('Pay & call via three.ws:'));+ expect(payIdx).toBeGreaterThan(0);+ expect(lines[payIdx - 1]).toBe('');+ expect(r.result.structuredContent.pay_link).toBe(+ 'https://three.ws/pay?resource=https%3A%2F%2Fapi.weather.test%2Fnow&tool=forecast',+ );+ });++ it('get_service names the 402 challenge when a service advertises no accepts', async () => {+ bazState.get.mockResolvedValue(item({ accepts: [], minPriceLabel: '' }));+ const r = await call('get_service', { resource_url: 'https://api.weather.test/now' });+ const lines = r.result.content[0].text.split('\n');+ const optIdx = lines.indexOf('Payment options:');+ // Never leave "Payment options:" as a dangling header with nothing under it.+ expect(lines[optIdx + 1]).toContain('402 challenge on call');+ expect(r.result.structuredContent.accepts).toEqual([]);+ });++ it('get_service falls back to the challenge recipient when an accept has no payTo', async () => {+ bazState.get.mockResolvedValue(+ item({ accepts: [{ network: 'solana:mainnet', priceLabel: '$0.01', amountAtomic: 10000, asset: 'SolUSDC', scheme: 'exact' }] }),+ );+ const r = await call('get_service', { resource_url: 'https://api.weather.test/now' });+ expect(r.result.content[0].text).toContain('(recipient in challenge)');+ expect(r.result.structuredContent.accepts[0].pay_to).toBeUndefined();+ });++ // available:true and available:false are diffed field by field by a price+ // tracker, so an absent label has to serialize as null in both branches.+ it('bazaar_service_details reports a missing price label as null, not an absent key', async () => {+ bazState.get.mockResolvedValue(item({ minPriceLabel: '', accepts: [] }));+ const r = await call('bazaar_service_details', { resource_url: 'https://api.weather.test/now' });+ const sc = r.result.structuredContent;+ expect(sc.available).toBe(true);+ expect(sc.min_price_label).toBeNull();+ expect(JSON.parse(JSON.stringify(sc))).toHaveProperty('min_price_label', null);+ });++ it('turns a facilitator outage into a tool error, not a thrown request', async () => {+ bazState.list.mockRejectedValue(new Error('facilitator unreachable'));+ const r = await call('browse_services', {});+ expect(r.error).toBeUndefined();+ expect(r.result.isError).toBe(true);+ expect(r.result.content[0].text).toContain('Error:');+ });++ it('rejects invalid arguments at the schema boundary', async () => {+ const missing = await call('search_services', {});+ expect(missing.error.code).toBe(-32602);+ const badEnum = await call('search_services', { query: 'x', type: 'ftp' });+ expect(badEnum.error.code).toBe(-32602);+ const extra = await call('search_services', { query: 'x', bogus: 1 });+ expect(extra.error.code).toBe(-32602);+ const badUri = await call('get_service', { resource_url: 'not a url' });+ expect(badUri.error.code).toBe(-32602);+ expect(bazState.search).not.toHaveBeenCalled();+ expect(bazState.get).not.toHaveBeenCalled();+ });++ it('does not resolve an inherited Object member as a tool', async () => {+ for (const name of ['__proto__', 'constructor', 'toString']) {+ const r = await dispatch(+ { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: {} } },+ AUTH,+ );+ expect(r.error.code).toBe(-32602);+ expect(r.error.message).toBe(`unknown tool: ${name}`);+ }+ });++ it('initialize advertises the bazaar server and the pinned protocol version', async () => {+ const r = await dispatch({ jsonrpc: '2.0', id: 1, method: 'initialize' }, AUTH);+ expect(PROTOCOL_VERSION).toBe('2025-06-18');+ expect(r.result.protocolVersion).toBe(PROTOCOL_VERSION);+ expect(r.result.serverInfo).toEqual({ name: 'three-ws-x402-bazaar', version: '1.0.0' });+ expect(r.result.instructions).toContain('search_services(query)');+ });++ it('keeps handlers and scopes out of the wire catalog', async () => {+ expect(TOOL_CATALOG.map((t) => t.name)).toEqual(Object.keys(TOOLS));+ for (const t of TOOL_CATALOG) {+ expect(t).not.toHaveProperty('handler');+ expect(t).not.toHaveProperty('scope');+ expect(t.inputSchema.type).toBe('object');+ // Omitting destructiveHint makes the MCP spec default it to true, which+ // would mark every read-only discovery tool as destructive.+ expect(t.annotations).toMatchObject({ readOnlyHint: true, destructiveHint: false });+ }+ for (const [name, t] of Object.entries(TOOLS)) {+ expect(typeof t.handler).toBe('function');+ expect(typeof t.validate).toBe('function');+ // getting_started is the free public entry point: no scope, or the HTTP+ // no-auth bypass would hand back an insufficient-scope error.+ if (name === 'getting_started') expect(t.scope).toBeUndefined();+ }+ });});