// Runnable example: does what an MCP client does with each config in this folder. For claude-desktop.json, cursor.json, // cline.json and windsurf.json it takes the server URL from the file, connects (streamable HTTP), lists the tools, and // then makes one free trial call and one unpaid call. No wallet and no account needed; nothing is paid. // node example.mjs // Env: LORDEVO_BASE_URL (default the live shop; replaces the origin in the configs), LORDEVO_EXAMPLE_SITE. import fs from 'node:fs'; import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'; const TOOLS = ['page_markdown', 'can_fetch', 'tech_stack', 'dns_lookup', 'email_validate']; const base = process.env.LORDEVO_BASE_URL; const site = process.env.LORDEVO_EXAMPLE_SITE || 'https://example.com'; const CONFIGS = ['claude-desktop.json', 'cursor.json', 'cline.json', 'windsurf.json']; // The server URL in each client's config format (Claude Desktop reaches it through the mcp-remote bridge). const urlOf = s => s.url || s.serverUrl || (s.args || []).find(a => /^https?:\/\//.test(a)); const connect = async url => { const client = new Client({ name: 'lordevo-integration-example', version: '0.0.1' }); await client.connect(new StreamableHTTPClientTransport(new URL(url))); return client; }; const configs = {}; let mcpUrl = null; for (const f of CONFIGS) { const url = urlOf(JSON.parse(fs.readFileSync(new URL(f, import.meta.url), 'utf8')).mcpServers.lordevo); const target = base && url ? new URL(new URL(url).pathname, base).href : url; // a test copy of the shop let ok = false; if (url?.endsWith('/mcp')) { const c = await connect(target); ok = (await c.listTools()).tools.some(t => t.name === 'page_markdown'); await c.close(); } configs[f] = ok; console.log(f, url, ok ? 'connects, tools listed' : 'FAILED'); mcpUrl ??= target; } const client = await connect(mcpUrl); const { tools } = await client.listTools(); const listed = Object.fromEntries(TOOLS.map(n => [n, tools.find(t => t.name === n)?.title?.match(/\(\$([\d.]+)\/call\)/)?.[1] || null])); console.log('prices per call', listed); // Free trial call: the agent adds "trial": true (3 free calls per IP per UTC day on tools up to $0.005). const tr = await client.callTool({ name: 'page_markdown', arguments: { url: site, trial: true } }); const trial_call = { ok: !tr.isError, free_trial: !!tr._meta?.['lordevo/trial']?.free, free_calls_left_today: tr._meta?.['lordevo/trial']?.free_calls_left_today ?? null }; console.log('trial call', trial_call); // Unpaid call: the x402 PaymentRequired comes back as the tool result. Chat clients cannot sign it; see README. const up = await client.callTool({ name: 'can_fetch', arguments: { url: `${site}/blog/post` } }); const a = up.structuredContent?.accepts?.[0] || {}; // The shop adds the next step for the model (free trial hint or how to pay) as a second text block. const next_step = (up.content || []).filter(c => c.type === 'text').slice(1).map(c => c.text).join(' ') || null; const unpaid_call = { payment_required: !!up.isError && !!a.amount, amount: a.amount ?? null, asset: a.asset ?? null, network: a.network ?? null, scheme: a.scheme ?? null, next_step }; console.log('unpaid call', unpaid_call); await client.close(); console.log('RESULT ' + JSON.stringify({ framework: 'mcp-clients', configs, listed, trial_call, unpaid_call }));