#!/usr/bin/env node
/**
* AgentBTC MCP Setup Helper
* Interactive setup for connecting to Lightning node and Claude Desktop
*/
import { readFileSync, writeFileSync, existsSync } from 'fs';
import { join } from 'path';
import { homedir } from 'os';
import { createInterface } from 'readline';
const rl = createInterface({
input: process.stdin,
output: process.stdout
});
function ask(question) {
return new Promise((resolve) => {
rl.question(question, (answer) => {
resolve(answer.trim());
});
});
}
// Detect Claude Desktop config location
function getClaudeConfigPath() {
const platform = process.platform;
if (platform === 'darwin') {
return join(homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
} else if (platform === 'win32') {
return join(homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json');
} else {
return join(homedir(), '.config', 'claude', 'claude_desktop_config.json');
}
}
// Generate MCP config for Claude Desktop
function generateClaudeConfig(lndHost, lndMacaroon, apiKey = '') {
return {
"agentbtc": {
"command": "agentbtc-mcp",
"args": ["start"],
"env": {
"AGENTBTC_LND_HOST": lndHost,
"AGENTBTC_LND_MACAROON": lndMacaroon,
...(apiKey && { "AGENTBTC_API_KEY": apiKey })
}
}
};
}
// Main setup flow
async function main() {
console.log('π AgentBTC MCP Setup');
console.log('');
console.log('This will help you connect AgentBTC to your Lightning node and Claude Desktop.');
console.log('');
// Check for existing Claude config
const claudeConfigPath = getClaudeConfigPath();
console.log(`Claude Desktop config: ${claudeConfigPath}`);
if (!existsSync(claudeConfigPath)) {
console.log('β οΈ Claude Desktop config not found. Make sure Claude Desktop is installed.');
console.log('');
}
// Lightning node setup
console.log('β‘ Lightning Node Configuration:');
console.log('');
const lndHost = await ask('LND Host (e.g., localhost:10009): ');
if (!lndHost) {
console.log('β LND host is required');
process.exit(1);
}
const lndMacaroon = await ask('LND Macaroon path (e.g., ~/.lnd/data/chain/bitcoin/mainnet/readonly.macaroon): ');
if (!lndMacaroon) {
console.log('β LND macaroon path is required');
process.exit(1);
}
// Expand tilde in path
const expandedMacaroonPath = lndMacaroon.startsWith('~')
? join(homedir(), lndMacaroon.slice(1))
: lndMacaroon;
if (!existsSync(expandedMacaroonPath)) {
console.log(`β οΈ Macaroon file not found at: ${expandedMacaroonPath}`);
console.log(' Please verify the path is correct.');
}
console.log('');
const apiKey = await ask('AgentBTC API Key (optional, press Enter to skip): ');
// Generate config
const mcpConfig = generateClaudeConfig(lndHost, expandedMacaroonPath, apiKey);
console.log('');
console.log('β
Configuration generated:');
console.log('');
console.log(JSON.stringify(mcpConfig, null, 2));
console.log('');
// Offer to update Claude config
if (existsSync(claudeConfigPath)) {
const updateConfig = await ask('Update Claude Desktop config automatically? (y/n): ');
if (updateConfig.toLowerCase() === 'y') {
try {
let claudeConfig = {};
// Read existing config
if (existsSync(claudeConfigPath)) {
const configText = readFileSync(claudeConfigPath, 'utf8');
claudeConfig = JSON.parse(configText);
}
// Ensure mcpServers section exists
if (!claudeConfig.mcpServers) {
claudeConfig.mcpServers = {};
}
// Add/update AgentBTC config
claudeConfig.mcpServers.agentbtc = mcpConfig.agentbtc;
// Write back
writeFileSync(claudeConfigPath, JSON.stringify(claudeConfig, null, 2));
console.log('β
Claude Desktop config updated!');
console.log('');
console.log('π Please restart Claude Desktop for changes to take effect.');
} catch (e) {
console.log(`β Failed to update Claude config: ${e.message}`);
console.log('');
console.log('Please manually add the configuration above to:');
console.log(claudeConfigPath);
}
}
} else {
console.log('π To complete setup, add the configuration above to your Claude Desktop config:');
console.log(claudeConfigPath);
}
console.log('');
console.log('π Setup complete! You can now use Bitcoin payments in Claude Desktop.');
console.log('');
console.log('Next steps:');
console.log('1. Restart Claude Desktop');
console.log('2. Test the connection: agentbtc-mcp test');
console.log('3. Try making a payment in Claude: "Pay 100 sats for some data"');
rl.close();
}
main().catch(console.error);