haloapi-mcp-tools
Version:
Model Context Protocol (MCP) server for interacting with the HaloPSA API
100 lines (86 loc) • 3.63 kB
JavaScript
/**
* Integration Script
*
* This script helps integrate both CommonJS and TypeScript MCP server implementations
* with Claude Desktop by generating the appropriate configuration.
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const { execSync } = require('child_process');
// Get the package.json to read version info
const packageJsonPath = path.join(__dirname, '..', 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// Configuration for Claude Desktop
const claudeDesktopConfigDir = (() => {
switch (process.platform) {
case 'darwin': // macOS
return path.join(os.homedir(), 'Library', 'Application Support', 'Claude');
case 'win32': // Windows
return path.join(os.homedir(), 'AppData', 'Roaming', 'Claude');
case 'linux': // Linux
return path.join(os.homedir(), '.config', 'claude');
default:
throw new Error(`Unsupported platform: ${process.platform}`);
}
})();
const claudeDesktopConfigPath = path.join(claudeDesktopConfigDir, 'claude_desktop_config.json');
// Check if Claude Desktop config exists
if (!fs.existsSync(claudeDesktopConfigDir)) {
console.log(`Creating Claude Desktop config directory: ${claudeDesktopConfigDir}`);
fs.mkdirSync(claudeDesktopConfigDir, { recursive: true });
}
// Default config if no existing config found
let claudeDesktopConfig = {
mcpServers: {}
};
// Read existing config if it exists
if (fs.existsSync(claudeDesktopConfigPath)) {
try {
console.log(`Reading existing Claude Desktop config from: ${claudeDesktopConfigPath}`);
claudeDesktopConfig = JSON.parse(fs.readFileSync(claudeDesktopConfigPath, 'utf8'));
// Ensure mcpServers property exists
if (!claudeDesktopConfig.mcpServers) {
claudeDesktopConfig.mcpServers = {};
}
} catch (error) {
console.error(`Error reading Claude Desktop config: ${error.message}`);
console.log('Creating new config file...');
}
}
// Add CommonJS HaloAPI MCP server configuration
claudeDesktopConfig.mcpServers.halopsa = {
command: 'haloapi-desktop-mcp',
args: [],
env: {
HALO_API_URL: process.env.HALO_API_URL || '<ENTER_YOUR_HALO_API_URL>',
HALO_API_KEY: process.env.HALO_API_KEY || '<ENTER_YOUR_HALO_API_KEY>'
}
};
// Add TypeScript HaloAPI MCP server configuration
const scriptPath = path.join(__dirname, '..', 'bin', 'ts', 'haloapi-mcp');
claudeDesktopConfig.mcpServers['halopsa-ts'] = {
command: 'node',
args: [scriptPath],
env: {
HALO_API_URL: process.env.HALO_API_URL || '<ENTER_YOUR_HALO_API_URL>',
HALO_API_KEY: process.env.HALO_API_KEY || '<ENTER_YOUR_HALO_API_KEY>'
}
};
// Write the updated config back to disk
try {
console.log(`Writing updated Claude Desktop config to: ${claudeDesktopConfigPath}`);
fs.writeFileSync(claudeDesktopConfigPath, JSON.stringify(claudeDesktopConfig, null, 2), 'utf8');
console.log('Claude Desktop configuration updated successfully');
} catch (error) {
console.error(`Error writing Claude Desktop config: ${error.message}`);
process.exit(1);
}
console.log('\nIntegration completed successfully!');
console.log(`\nHaloAPI MCP Tools v${packageJson.version} has been integrated with Claude Desktop`);
console.log('\nThe following MCP servers are now available:');
console.log('1. halopsa - CommonJS implementation');
console.log('2. halopsa-ts - TypeScript implementation');
console.log('\nPlease check your Claude Desktop settings to ensure the MCP servers are enabled.');
console.log('You may need to restart Claude Desktop for the changes to take effect.');