first
This commit is contained in:
123
http-simple.js
Normal file
123
http-simple.js
Normal file
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Simple HTTP server with startup banner
|
||||
*/
|
||||
|
||||
import express from 'express';
|
||||
import cors from 'cors';
|
||||
|
||||
// Set environment variables if not set
|
||||
process.env.LARAVEL_API_BASE_URL = process.env.LARAVEL_API_BASE_URL || 'https://example.com';
|
||||
|
||||
console.log('🚀 Starting Laravel Healthcare MCP HTTP Server...');
|
||||
|
||||
try {
|
||||
const app = express();
|
||||
const port = process.env.MCP_SERVER_PORT || 3000;
|
||||
const host = process.env.MCP_SERVER_HOST || '0.0.0.0';
|
||||
|
||||
console.log('📋 Step 1: Setting up middleware...');
|
||||
|
||||
// Basic middleware
|
||||
app.use(cors());
|
||||
app.use(express.json());
|
||||
|
||||
console.log('📋 Step 2: Setting up routes...');
|
||||
|
||||
// Health endpoint
|
||||
app.get('/health', (req, res) => {
|
||||
res.json({
|
||||
status: 'healthy',
|
||||
timestamp: new Date().toISOString(),
|
||||
server: 'Laravel Healthcare MCP Server',
|
||||
port: port,
|
||||
host: host,
|
||||
apiUrl: process.env.LARAVEL_API_BASE_URL
|
||||
});
|
||||
});
|
||||
|
||||
// Tools endpoint
|
||||
app.get('/tools', (req, res) => {
|
||||
res.json({
|
||||
message: 'Laravel Healthcare MCP Server Tools',
|
||||
total: 26,
|
||||
publicTools: 21,
|
||||
providerTools: 5,
|
||||
note: 'Use POST /tools/{toolName}/execute to run tools'
|
||||
});
|
||||
});
|
||||
|
||||
// Stats endpoint
|
||||
app.get('/stats', (req, res) => {
|
||||
res.json({
|
||||
server: {
|
||||
name: 'Laravel Healthcare MCP Server',
|
||||
version: '1.0.0',
|
||||
uptime: process.uptime(),
|
||||
memory: process.memoryUsage()
|
||||
},
|
||||
tools: {
|
||||
total: 26,
|
||||
categories: {
|
||||
'public': 21,
|
||||
'provider': 5
|
||||
}
|
||||
},
|
||||
config: {
|
||||
port: port,
|
||||
host: host,
|
||||
apiUrl: process.env.LARAVEL_API_BASE_URL
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
console.log('📋 Step 3: Starting HTTP server...');
|
||||
|
||||
// Start server
|
||||
const server = app.listen(port, host, () => {
|
||||
const serverUrl = `http://${host === '0.0.0.0' ? 'localhost' : host}:${port}`;
|
||||
|
||||
// Startup banner
|
||||
console.log('\n' + '='.repeat(60));
|
||||
console.log('🚀 LARAVEL HEALTHCARE MCP SERVER - HTTP MODE');
|
||||
console.log('='.repeat(60));
|
||||
console.log(`📡 Server URL: ${serverUrl}`);
|
||||
console.log(`🌐 Host: ${host}`);
|
||||
console.log(`🔌 Port: ${port}`);
|
||||
console.log(`🔗 API URL: ${process.env.LARAVEL_API_BASE_URL}`);
|
||||
console.log('='.repeat(60));
|
||||
console.log('📋 Available Endpoints:');
|
||||
console.log(` • Health Check: ${serverUrl}/health`);
|
||||
console.log(` • Tools List: ${serverUrl}/tools`);
|
||||
console.log(` • Server Stats: ${serverUrl}/stats`);
|
||||
console.log('='.repeat(60));
|
||||
console.log('📊 Server Status: READY');
|
||||
console.log(`⏰ Started at: ${new Date().toLocaleString()}`);
|
||||
console.log('='.repeat(60));
|
||||
console.log('💡 Press Ctrl+C to stop the server');
|
||||
console.log('');
|
||||
console.log('🧪 Test the server:');
|
||||
console.log(` curl ${serverUrl}/health`);
|
||||
console.log(` curl ${serverUrl}/tools`);
|
||||
console.log(` curl ${serverUrl}/stats`);
|
||||
console.log('');
|
||||
});
|
||||
|
||||
// Graceful shutdown
|
||||
const shutdown = (signal) => {
|
||||
console.log(`\n🛑 Received ${signal}, shutting down HTTP server...`);
|
||||
server.close(() => {
|
||||
console.log('✅ HTTP server stopped');
|
||||
process.exit(0);
|
||||
});
|
||||
};
|
||||
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ HTTP Server startup failed:', error.message);
|
||||
console.error('Stack trace:', error.stack);
|
||||
process.exit(1);
|
||||
}
|
Reference in New Issue
Block a user