debank-mcp-proxy
Version:
Secure proxy client for DeBank MCP Server - connects Claude Desktop to remote DeBank MCP server
156 lines โข 6.52 kB
JavaScript
import { Command } from 'commander';
import chalk from 'chalk';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
import { generateApiKey } from './auth.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const program = new Command();
program
.name('debank-mcp')
.description('CLI for DeBank MCP Proxy - Connect Claude Desktop to remote DeBank MCP server')
.version('1.0.0');
program
.command('setup')
.description('Setup DeBank MCP proxy for Claude Desktop')
.option('-k, --key <apiKey>', 'API key for authentication')
.action(async (options) => {
console.log(chalk.blue('๐ Setting up DeBank MCP Proxy...'));
if (!options.key) {
console.error(chalk.red('โ API key is required. Please provide with --key option'));
console.log(chalk.yellow('๐ Get your API key from: https://debank-mcp-server.fly.dev/get-key'));
process.exit(1);
}
const claudeConfigPath = path.join(process.env.APPDATA || process.env.HOME || '.', 'Claude', 'claude_desktop_config.json');
try {
let config = {};
try {
const existing = await fs.readFile(claudeConfigPath, 'utf-8');
config = JSON.parse(existing);
}
catch {
console.log(chalk.yellow('๐ Creating new Claude Desktop config...'));
}
if (!config.mcpServers) {
config.mcpServers = {};
}
const proxyPath = process.platform === 'win32'
? path.join(__dirname, '..', 'dist', 'index.js')
: path.join(__dirname, 'index.js');
config.mcpServers['debank-mcp'] = {
command: 'node',
args: [proxyPath],
env: {
DEBANK_API_KEY: options.key,
DEBANK_SERVER_URL: process.env.DEBANK_SERVER_URL || 'https://debank-mcp-server.fly.dev'
}
};
await fs.mkdir(path.dirname(claudeConfigPath), { recursive: true });
await fs.writeFile(claudeConfigPath, JSON.stringify(config, null, 2));
console.log(chalk.green('โ
DeBank MCP Proxy configured successfully!'));
console.log(chalk.cyan('๐ Config saved to:'), claudeConfigPath);
console.log(chalk.cyan('๐ Restart Claude Desktop to use the proxy'));
}
catch (error) {
console.error(chalk.red('โ Failed to setup:'), error);
process.exit(1);
}
});
program
.command('generate-key')
.description('Generate a new API key (for server admins only)')
.action(() => {
const key = generateApiKey();
console.log(chalk.green('๐ Generated API Key:'));
console.log(chalk.yellow(key));
console.log(chalk.cyan('๐ Add this key to your server\'s authorized keys'));
});
program
.command('test')
.description('Test connection to remote MCP server')
.option('-k, --key <apiKey>', 'API key for authentication')
.action(async (options) => {
if (!options.key) {
console.error(chalk.red('โ API key is required. Please provide with --key option'));
process.exit(1);
}
console.log(chalk.blue('๐งช Testing connection to DeBank MCP server...'));
const serverUrl = process.env.DEBANK_SERVER_URL || 'https://debank-mcp-server.fly.dev';
try {
const response = await fetch(`${serverUrl}/healthz`, {
headers: {
'X-API-Key': options.key
}
});
if (response.ok) {
const text = await response.text();
console.log(chalk.green('โ
Connection successful!'));
console.log(chalk.cyan('๐ Server status:'), text);
console.log(chalk.blue('\n๐ง Testing MCP protocol...'));
const mcpResponse = await fetch(`${serverUrl}/mcp`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json, text/event-stream',
'X-API-Key': options.key
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'initialize',
params: { protocolVersion: '2024-11-01' },
id: 1
})
});
if (mcpResponse.ok) {
// Handle SSE response
const contentType = mcpResponse.headers.get('content-type');
let mcpData;
if (contentType?.includes('text/event-stream')) {
const text = await mcpResponse.text();
const lines = text.split('\n');
for (const line of lines) {
if (line.startsWith('data: ')) {
const jsonStr = line.substring(6);
if (jsonStr.trim()) {
mcpData = JSON.parse(jsonStr);
break;
}
}
}
}
else {
mcpData = await mcpResponse.json();
}
console.log(chalk.green('โ
MCP protocol working!'));
console.log(chalk.cyan('๐ฆ Available capabilities:'), mcpData?.result?.capabilities);
}
}
else {
console.error(chalk.red('โ Connection failed:'), response.status, response.statusText);
}
}
catch (error) {
console.error(chalk.red('โ Connection error:'), error);
}
});
program
.command('info')
.description('Show information about the proxy and server')
.action(() => {
console.log(chalk.blue('๐ฆ DeBank MCP Proxy'));
console.log(chalk.cyan('Version:'), '1.0.0');
console.log(chalk.cyan('Server:'), 'https://debank-mcp-server.fly.dev');
console.log(chalk.cyan('\n๐ง Available Tools:'));
console.log(' - getPortfolio: Get complete portfolio data');
console.log(' - getTokenBalances: Get token balances');
console.log(' - getTransactions: Get transaction history');
console.log(' - getAllowances: Check token allowances');
console.log(' - getNFTs: Get NFT holdings');
console.log(' - getProtocolPositions: Get DeFi positions');
console.log(chalk.cyan('\n๐ Documentation:'));
console.log(' https://github.com/debank/mcp-proxy');
});
program.parse();
//# sourceMappingURL=cli.js.map