@phqb/mcp-server
Version:
PHQB MCP Payment Server - AI-powered payment processing for Claude and other AI assistants
204 lines (194 loc) • 7.29 kB
JavaScript
;
// PHQB MCP 服务器 CLI 工具
Object.defineProperty(exports, "__esModule", { value: true });
const server_1 = require("./server");
function showHelp() {
console.log(`
🤖 PHQB MCP Server - AI-powered payment processing
USAGE:
phqb-mcp [command] [options]
COMMANDS:
start Start the MCP server (default)
test Test API Key connection
tools List available tools
help Show this help message
OPTIONS:
--api-key <key> PHQB API Key (or set PHQB_API_KEY env var)
--base-url <url> PHQB API base URL (default: https://www.phqb.com)
--verbose Enable verbose logging
ENVIRONMENT VARIABLES:
PHQB_API_KEY Your PHQB API Key (required)
PHQB_API_URL PHQB API base URL (optional)
EXAMPLES:
# Start MCP server with environment variable
export PHQB_API_KEY="your-api-key"
phqb-mcp start
# Start with command line option
phqb-mcp start --api-key "your-api-key"
# Test API Key connection
phqb-mcp test --api-key "your-api-key"
# List available tools
phqb-mcp tools --api-key "your-api-key"
GET YOUR API KEY:
Visit https://www.phqb.com/dashboard?tab=apikey to create an API Key
DOCUMENTATION:
https://www.phqb.com/docs/mcp
`);
}
async function testConnection(apiKey, baseURL) {
try {
console.log('🧪 Testing API Key connection...');
console.log(`📡 API URL: ${baseURL}`);
console.log(`🔑 API Key: ${apiKey.substring(0, 8)}...`);
console.log('');
const server = new server_1.PHQBMCPServer(apiKey, baseURL);
await server.initialize();
const userInfo = server['authManager'].getUserInfo();
console.log('✅ Connection successful!');
console.log(`👤 User ID: ${userInfo?.user_id}`);
console.log(`📋 Plan: ${userInfo?.plan}`);
console.log(`🔧 Permissions: ${userInfo?.permissions?.length || 0} permissions`);
console.log(`⚡ Rate Limit: ${userInfo?.rate_limit?.calls_per_hour || 'unlimited'} calls/hour`);
}
catch (error) {
console.error('❌ Connection failed:', error instanceof Error ? error.message : error);
process.exit(1);
}
}
async function listTools(apiKey, baseURL) {
try {
console.log('🔧 Loading available tools...');
console.log('');
const server = new server_1.PHQBMCPServer(apiKey, baseURL);
await server.initialize();
const availableTools = server['authManager'].getAvailableTools();
const userInfo = server['authManager'].getUserInfo();
console.log(`📋 Available Tools (${availableTools.length} tools)`);
console.log(`👤 Plan: ${userInfo?.plan}`);
console.log('');
if (availableTools.length === 0) {
console.log('❌ No tools available with current API Key permissions');
console.log('💡 Please check your API Key permissions or upgrade your plan');
return;
}
// 按类别分组显示工具
const toolCategories = {
'💳 支付创建': availableTools.filter(t => t.startsWith('create_')),
'📋 订单管理': availableTools.filter(t => ['get_order_details', 'search_orders', 'get_recent_orders', 'cancel_order'].includes(t)),
'💰 退款管理': availableTools.filter(t => t.includes('refund')),
'📊 统计分析': availableTools.filter(t => ['get_payment_stats', 'get_revenue_summary', 'get_top_products'].includes(t)),
'👥 客户管理': availableTools.filter(t => t.includes('customer'))
};
for (const [category, tools] of Object.entries(toolCategories)) {
if (tools.length > 0) {
console.log(`${category}:`);
tools.forEach(tool => {
console.log(` ✓ ${tool}`);
});
console.log('');
}
}
console.log('💡 Use these tools in Claude Desktop or other MCP-compatible AI assistants');
}
catch (error) {
console.error('❌ Failed to load tools:', error instanceof Error ? error.message : error);
process.exit(1);
}
}
async function startServer(apiKey, baseURL, verbose) {
try {
if (verbose) {
console.log('🚀 Starting PHQB MCP Server in verbose mode...');
}
const server = new server_1.PHQBMCPServer(apiKey, baseURL);
await server.initialize();
await server.run();
}
catch (error) {
console.error('❌ Failed to start server:', error instanceof Error ? error.message : error);
process.exit(1);
}
}
async function main() {
const args = process.argv.slice(2);
// 解析命令行参数
let command = 'start';
let apiKey = process.env.PHQB_API_KEY || '';
let baseURL = process.env.PHQB_API_URL || 'https://www.phqb.com';
let verbose = false;
for (let i = 0; i < args.length; i++) {
const arg = args[i];
if (arg === 'help' || arg === '--help' || arg === '-h') {
showHelp();
return;
}
if (arg === 'test' || arg === 'tools' || arg === 'start') {
command = arg;
continue;
}
if (arg === '--api-key' && i + 1 < args.length) {
apiKey = args[i + 1];
i++;
continue;
}
if (arg === '--base-url' && i + 1 < args.length) {
baseURL = args[i + 1];
i++;
continue;
}
if (arg === '--verbose') {
verbose = true;
continue;
}
}
// 验证 API Key
if (!apiKey) {
console.error('❌ Error: PHQB API Key is required');
console.error('');
console.error('Set your API Key using one of these methods:');
console.error(' 1. Environment variable: export PHQB_API_KEY="your-api-key"');
console.error(' 2. Command line option: --api-key "your-api-key"');
console.error('');
console.error('Get your API Key from: https://www.phqb.com/dashboard?tab=apikey');
console.error('');
console.error('Run "phqb-mcp help" for more information');
process.exit(1);
}
// 执行命令
switch (command) {
case 'test':
await testConnection(apiKey, baseURL);
break;
case 'tools':
await listTools(apiKey, baseURL);
break;
case 'start':
default:
await startServer(apiKey, baseURL, verbose);
break;
}
}
// 错误处理
process.on('uncaughtException', (error) => {
console.error('❌ Uncaught Exception:', error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('❌ Unhandled Rejection at:', promise, 'reason:', reason);
process.exit(1);
});
// 优雅关闭
process.on('SIGINT', () => {
console.log('\n👋 PHQB MCP Server shutting down...');
process.exit(0);
});
process.on('SIGTERM', () => {
console.log('\n👋 PHQB MCP Server shutting down...');
process.exit(0);
});
main().catch((error) => {
console.error('❌ Fatal error:', error);
process.exit(1);
});
//# sourceMappingURL=cli.js.map