creditclaudit-mcp-server
Version:
MCP server for tenant credit assessment using CreditClaudit methodology
91 lines (73 loc) • 2.04 kB
JavaScript
import { spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Parse command line arguments
const args = process.argv.slice(2);
if (args.includes('--help') || args.includes('-h')) {
console.log(`
CreditClaudit MCP Server
Usage:
creditclaudit-mcp Run the MCP server (for Claude Desktop)
creditclaudit-mcp --stdio Run in stdio mode (default)
creditclaudit-mcp --config Show configuration for Claude Desktop
creditclaudit-mcp --help Show this help message
Claude Desktop Configuration:
Add this to your Claude Desktop settings:
"creditclaudit": {
"command": "creditclaudit-mcp",
"args": ["--stdio"]
}
`);
process.exit(0);
}
if (args.includes('--config')) {
const npmBin = process.execPath.replace(/node(\.exe)?$/, '');
const globalPath = path.join(npmBin, 'creditclaudit-mcp');
console.log(`
Add this configuration to Claude Desktop settings:
{
"creditclaudit": {
"command": "creditclaudit-mcp",
"args": ["--stdio"]
}
}
Or if you prefer the full path:
{
"creditclaudit": {
"command": "${globalPath}",
"args": ["--stdio"]
}
}
`);
process.exit(0);
}
// Default behavior: run the server
const serverPath = path.join(__dirname, 'server.js');
// Check if server.js exists
if (!fs.existsSync(serverPath)) {
console.error('Error: server.js not found at', serverPath);
process.exit(1);
}
// Spawn the server process
const serverProcess = spawn(process.execPath, [serverPath], {
stdio: 'inherit',
env: process.env
});
serverProcess.on('error', (err) => {
console.error('Failed to start server:', err);
process.exit(1);
});
serverProcess.on('exit', (code) => {
process.exit(code || 0);
});
// Handle graceful shutdown
process.on('SIGINT', () => {
serverProcess.kill('SIGINT');
});
process.on('SIGTERM', () => {
serverProcess.kill('SIGTERM');
});