0xgasless-mcp
Version:
MCP server for 0xGasless smart accounts with gasless blockchain operations. Directly connects to Claude Desktop
231 lines (221 loc) ⢠8.27 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
const main_js_1 = require("./main.js");
const version_js_1 = require("./version.js");
const fs = __importStar(require("fs"));
const os = __importStar(require("os"));
const path = __importStar(require("path"));
const readline = __importStar(require("readline"));
// Handle command line arguments
const args = process.argv.slice(2);
if (args.includes('--version') || args.includes('-v')) {
console.log(version_js_1.version);
process.exit(0);
}
if (args.includes('--help') || args.includes('-h')) {
console.log(`
0xGasless MCP Server v${version_js_1.version}
Usage: 0xgasless-mcp [options]
Options:
-h, --help Show this help message
-v, --version Show version number
configure Interactive Claude Desktop configuration
Environment Variables Required:
PRIVATE_KEY Your wallet private key (0x...)
RPC_URL RPC endpoint URL
API_KEY 0xGasless API key
CHAIN_ID Chain ID (56=BSC, 8453=Base, etc.)
OPENROUTER_API_KEY OpenRouter API key (optional)
Example:
PRIVATE_KEY=0x... RPC_URL=https://... API_KEY=... CHAIN_ID=56 0xgasless-mcp
For more information, visit:
https://github.com/yourusername/0xgasless-mcp-server
`);
process.exit(0);
}
// Interactive configuration
if (args.includes('configure')) {
(async () => {
await configureClaude();
process.exit(0);
})();
}
else {
// Start the MCP server
(0, main_js_1.main)().catch((error) => {
console.error('ā Fatal error:', error);
process.exit(1);
});
}
async function configureClaude() {
console.log(`
š§ 0xGasless MCP Server Configuration
====================================
This will help you configure Claude Desktop to use 0xGasless MCP Server.
`);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const question = (prompt) => new Promise(resolve => rl.question(prompt, resolve));
try {
// Detect Claude Desktop config path
const homeDir = os.homedir();
let claudeConfigPath;
if (process.platform === 'darwin') {
claudeConfigPath = path.join(homeDir, 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json');
}
else if (process.platform === 'win32') {
claudeConfigPath = path.join(homeDir, 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json');
}
else {
claudeConfigPath = path.join(homeDir, '.config', 'Claude', 'claude_desktop_config.json');
}
console.log(`š Claude config location: ${claudeConfigPath}`);
// Get configuration values
console.log(`\nš Please provide your configuration values:`);
const privateKey = await question('Private Key (0x...): ');
if (!privateKey.startsWith('0x')) {
console.log('ā Private key should start with 0x');
process.exit(1);
}
const rpcUrl = await question('RPC URL (https://...): ');
if (!rpcUrl.startsWith('http')) {
console.log('ā RPC URL should start with http:// or https://');
process.exit(1);
}
const apiKey = await question('0xGasless API Key: ');
if (!apiKey) {
console.log('ā API Key is required');
process.exit(1);
}
const chainIdInput = await question('Chain ID (56 for BSC, 8453 for Base, etc.): ');
const chainId = chainIdInput || '56';
const openRouterKey = await question('OpenRouter API Key (optional, press Enter to skip): ');
// Prepare the configuration
const mcpConfig = {
command: "npx",
args: ["0xgasless-mcp"],
env: {
PRIVATE_KEY: privateKey,
RPC_URL: rpcUrl,
API_KEY: apiKey,
CHAIN_ID: chainId,
...(openRouterKey && { OPENROUTER_API_KEY: openRouterKey })
}
};
// Read existing config or create new one
let config = {};
if (fs.existsSync(claudeConfigPath)) {
try {
const existingConfig = fs.readFileSync(claudeConfigPath, 'utf8');
config = JSON.parse(existingConfig);
console.log('š Found existing Claude config');
}
catch (error) {
console.log('ā ļø Could not parse existing config, creating new one');
}
}
else {
console.log('š Creating new Claude config');
// Create directory if it doesn't exist
const configDir = path.dirname(claudeConfigPath);
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir, { recursive: true });
}
}
// Ensure mcpServers exists
if (!config.mcpServers) {
config.mcpServers = {};
}
// Check if 0xgasless config already exists
if (config.mcpServers['0xgasless']) {
const overwrite = await question('ā ļø 0xgasless MCP server is already configured. Overwrite? (y/N): ');
if (overwrite.toLowerCase() !== 'y' && overwrite.toLowerCase() !== 'yes') {
console.log('ā Configuration cancelled');
rl.close();
return;
}
}
// Add the 0xgasless configuration
config.mcpServers['0xgasless'] = mcpConfig;
// Write the configuration
fs.writeFileSync(claudeConfigPath, JSON.stringify(config, null, 2));
console.log(`
ā
Configuration saved successfully!
š Configuration added to Claude Desktop:
${claudeConfigPath}
š Next steps:
1. Restart Claude Desktop
2. Start a new conversation
3. Try: "What's my wallet address?" or "Check my balance"
š Your configuration:
Chain: ${getChainName(chainId)} (${chainId})
OpenRouter: ${openRouterKey ? 'Configured' : 'Not configured'}
š You're ready to use 0xGasless with Claude!
`);
}
catch (error) {
console.error('ā Configuration failed:', error);
}
finally {
rl.close();
}
}
function getChainName(chainId) {
const chains = {
'1': 'Ethereum',
'56': 'BSC (Binance Smart Chain)',
'137': 'Polygon',
'8453': 'Base',
'43114': 'Avalanche',
'250': 'Fantom',
'1284': 'Moonbeam',
'1088': 'Metis'
};
return chains[chainId] || `Chain ${chainId}`;
}
// Error handling
process.on('uncaughtException', (error) => {
console.error('ā Uncaught exception:', error.message);
process.exit(1);
});
process.on('unhandledRejection', (error) => {
console.error('ā Unhandled rejection:', error);
process.exit(1);
});
//# sourceMappingURL=index.js.map