x402-x402fix / tree / src/install-snippets.js ยท raw (this view has old GitHub links rewritten for the mirror; raw is byte-exact)
// Copy-paste install snippets for the remote MCP endpoint (Claude Code, Claude Desktop, Cursor). Used by landing.js.
// Cursor deeplink format (cursor.com/docs/mcp/install-links): cursor://anysphere.cursor-deeplink/mcp/install?name=&config=<base64 JSON of one server>.
const b64 = (s) => (typeof btoa === 'function' ? btoa(s) : Buffer.from(s, 'utf8').toString('base64'));

export function installSnippets(name, mcpUrl) {
  const server = { url: mcpUrl };
  return {
    claudeCode: `claude mcp add --transport http ${name} ${mcpUrl}`,
    claudeDesktop: JSON.stringify({ mcpServers: { [name]: { command: 'npx', args: ['-y', 'mcp-remote', mcpUrl] } } }, null, 2),
    cursorJson: JSON.stringify({ mcpServers: { [name]: server } }, null, 2),
    cursorDeeplink: `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(name)}&config=${encodeURIComponent(b64(JSON.stringify(server)))}`,
    genericJson: JSON.stringify({ mcpServers: { [name]: { type: 'http', url: mcpUrl } } }),
  };
}

/** HTML for the landing page (block = the page's copy-button code block helper, esc = its HTML escaper). */
export function installHtml(name, mcpUrl, { block, esc, freeLine }) {
  const s = installSnippets(name, mcpUrl);
  return `<p style="margin-top:6px"><a class="run" href="${esc(s.cursorDeeplink)}">Add to Cursor</a> <span class="muted">${esc(freeLine)}</span></p>
  <p class="muted" style="margin:14px 0 6px">Claude Code (one line):</p>
  ${block('mcp-claude-code', s.claudeCode)}
  <p class="muted" style="margin:14px 0 6px">Claude Desktop: Settings &gt; Connectors &gt; Add custom connector with the URL <code>${esc(mcpUrl)}</code>, or this <code>claude_desktop_config.json</code> entry:</p>
  ${block('mcp-claude-desktop', s.claudeDesktop)}
  <p class="muted" style="margin:14px 0 6px">Cursor <code>~/.cursor/mcp.json</code> (or the Add to Cursor button above):</p>
  ${block('mcp-cursor', s.cursorJson)}
  <p class="muted" style="margin:14px 0 6px">Any other MCP client (Streamable HTTP):</p>`;
}

agentgate-source: code mirror on Cloudflare Pages. All repos