MCP server and SDK
MCP
A streamable HTTP MCP server at /api/mcp. Tools: prepare_ask, confirm_ask, get_answer, list_questions, swarm_stats. It never signs: prepare_askreturns the transaction for the caller's wallet.
{
"mcpServers": {
"swarm": { "type": "http", "url": "https://swarmconsensus.xyz/api/mcp" }
}
}JS SDK
An ES module served from this site, no install. It works in the browser and in Node 18 and later.
const sdk = await import("https://swarmconsensus.xyz/sdk/swarm.js"); // browser, Deno, bundlers with URL imports
// Node: curl -O https://swarmconsensus.xyz/sdk/swarm.js, then import("./swarm.js")
const tx = await sdk.prepareAsk({ text: "Is 7919 prime?", options: ["YES", "NO"], bountyEth: "0.0005" });
const hash = await wallet.sendTransaction(tx); // viem, ethers, any EIP-1193 wallet
const { id } = await sdk.confirmAsk(hash);
const answer = await sdk.waitForAnswer(id); // polls until settled