diff --git a/app/api/v1/paid/[product]/route.ts b/app/api/v1/paid/[product]/route.ts index 65076eb..79ab076 100644 --- a/app/api/v1/paid/[product]/route.ts +++ b/app/api/v1/paid/[product]/route.ts @@ -24,6 +24,133 @@ function paymentRequired(req: NextRequest, product: NonNullable) { + const requestedSegment = normalizeToken(query.segment) || 'mcp'; + const limit = Math.max(1, Math.min(Number(query.limit) || 3, 5)); + + const leads = VENDOR_LEAD_PROFILES + .map((profile) => ({ + segment: profile.segment, + target: profile.target, + fit_score: scoreLead(profile, requestedSegment), + priority: scoreLead(profile, requestedSegment) >= 90 ? 'high' : 'medium', + discovery_queries: profile.discovery_queries, + qualifying_signals: profile.signals, + pitch: profile.pitch, + suggested_product: { + product_id_hint: `${profile.segment}-paid-tool`, + category: profile.catalog_category, + price_range_usdc: '$0.05-$0.25 per call', + affiliate_bps: 2500, + }, + next_step: 'Confirm the vendor has a callable tool/API, then ask for one paid endpoint to list with x402 and Pyrimid metadata.', + })) + .sort((a, b) => b.fit_score - a.fit_score) + .slice(0, limit); + + return { + segment: requestedSegment, + scoring_model: { + max_score: 100, + factors: ['x402 fit', 'agent discoverability', 'per-call value', 'Pyrimid affiliate-distribution upside'], + }, + leads, + clean_json_output: true, + }; +} + +function classifyMcpUrl(url: string) { + const text = normalizeToken(url); + if (/github|gitlab|repo/.test(text)) return 'code-hosted MCP server'; + if (/search|crawl|browser|web/.test(text)) return 'web/search MCP server'; + if (/data|market|price|signal|analytics/.test(text)) return 'data API MCP server'; + if (/tool|api|mcp/.test(text)) return 'developer-tool MCP server'; + return 'generic MCP server'; +} + +function buildMcpServerAudit(query: Record) { + const url = query.url || 'https://example.com/mcp'; + const serverType = classifyMcpUrl(url); + const requestedPrice = query.price || '$0.05'; + const paidToolCandidates = [ + { name: 'search', price: requestedPrice, reason: 'Search-style tools have repeatable per-call value and clear buyer-agent intent.' }, + { name: 'enrich', price: '$0.10', reason: 'Enrichment often combines external data and compute, making per-call pricing natural.' }, + { name: 'export', price: '$0.05', reason: 'Export is easy to gate while leaving browse/list tools free for discovery.' }, + { name: 'analyze', price: '$0.25', reason: 'Analysis tools can justify higher prices when they consume model or data-provider budget.' }, + ]; + + return { + audit: { + url, + server_type: serverType, + monetization_readiness_score: serverType === 'generic MCP server' ? 72 : 86, + recommended_paid_tools: paidToolCandidates, + route_shape: { + unpaid_request: 'Return HTTP 402 with x402 accepts[] metadata when X-PAYMENT is missing.', + paid_retry: 'Verify X-PAYMENT or X-PAYMENT-TX on Base, then execute the paid MCP tool.', + free_discovery: 'Keep server info, tool list, and lightweight previews free so buyer agents can evaluate the product.', + }, + catalog_metadata: { + tags: ['mcp', 'paid-tools', 'x402', 'base-usdc'], + output_schema_required: true, + agents_txt_hint: 'Advertise paid tool endpoints and pricing so buyer agents can preflight before payment.', + }, + risk_notes: [ + 'Do not gate the MCP initialize/list_tools flow; gate only high-value tool calls.', + 'Publish max price and output schema to reduce failed buyer-agent purchases.', + 'Log payment tx hashes separately from user prompts or private tool inputs.', + ], + launch_checklist: [ + 'Choose one paid tool with obvious per-call value', + 'Add a 402/x402 challenge response for unpaid calls', + 'Publish Pyrimid catalog metadata with price, endpoint, and output schema', + 'Add an agents.txt or server card note describing the paid tool', + 'Run one unpaid preflight and one paid retry demo', + ], + }, + }; +} + function payload(productId: string, req: NextRequest, proof: string) { const query = Object.fromEntries(req.nextUrl.searchParams.entries()); @@ -52,31 +179,10 @@ function payload(productId: string, req: NextRequest, proof: string) { }; } case 'vendor-lead-discovery': { - const segment = query.segment || 'mcp'; - return { - segment, - leads: [ - { segment: 'mcp', target: 'MCP servers with paid/data-heavy tools', pitch: 'Add optional x402 payment gate + Pyrimid catalog listing.' }, - { segment: 'agent-frameworks', target: 'Agent frameworks with marketplace/plugin systems', pitch: 'Let builders sell tools to agents with Base USDC settlement.' }, - { segment: 'api-tools', target: 'AI API services with per-call cost', pitch: 'Turn API calls into agent-purchasable products.' }, - ], - }; + return buildVendorLeadDiscovery(query); } case 'mcp-server-audit': { - const url = query.url || 'https://example.com/mcp'; - return { - audit: { - url, - recommended_paid_tools: ['search', 'enrich', 'export', 'analyze'], - pricing: '$0.01-$0.25 per call depending on compute/data cost', - integration_steps: [ - 'Add 402 response with x402 accepts[] metadata', - 'Register vendor/product in Pyrimid catalog', - 'Expose tool schema in MCP server card', - 'Add affiliateBps for distribution agents', - ], - }, - }; + return buildMcpServerAudit(query); } case 'x402-integration-plan': { const service = query.service || 'agent-api';