Implement remote MCP server deployment capabilities
- Add HTTP/JSON-RPC server for remote MCP access - Configure domain and authentication via environment variables - Create comprehensive remote deployment documentation - Support both local (stdio) and remote (HTTP) deployment modes - Add PM2 and Nginx configuration examples - Update README with remote server instructions The server can now be deployed on a VM (e.g., Hetzner) and accessed from Claude Desktop over HTTPS using the configured domain. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
93
src/index-http.ts
Normal file
93
src/index-http.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
#!/usr/bin/env node
|
||||
import dotenv from 'dotenv';
|
||||
import { N8NDocumentationRemoteServer } from './mcp/remote-server';
|
||||
import { logger } from './utils/logger';
|
||||
import * as path from 'path';
|
||||
|
||||
// Load environment variables
|
||||
dotenv.config();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// Get configuration from environment
|
||||
const config = {
|
||||
port: parseInt(process.env.MCP_PORT || '3000', 10),
|
||||
host: process.env.MCP_HOST || '0.0.0.0',
|
||||
domain: process.env.MCP_DOMAIN || 'localhost',
|
||||
authToken: process.env.MCP_AUTH_TOKEN,
|
||||
cors: process.env.MCP_CORS === 'true',
|
||||
tlsCert: process.env.MCP_TLS_CERT,
|
||||
tlsKey: process.env.MCP_TLS_KEY,
|
||||
};
|
||||
|
||||
// Validate required configuration
|
||||
if (!config.domain || config.domain === 'localhost') {
|
||||
logger.warn('MCP_DOMAIN not set or set to localhost. Using default: localhost');
|
||||
logger.warn('For production, set MCP_DOMAIN to your actual domain (e.g., n8ndocumentation.aiservices.pl)');
|
||||
}
|
||||
|
||||
if (!config.authToken) {
|
||||
logger.warn('MCP_AUTH_TOKEN not set. Server will run without authentication.');
|
||||
logger.warn('For production, set MCP_AUTH_TOKEN to a secure value.');
|
||||
}
|
||||
|
||||
// Set database path if not already set
|
||||
if (!process.env.NODE_DB_PATH) {
|
||||
process.env.NODE_DB_PATH = path.join(__dirname, '../data/nodes-v2.db');
|
||||
}
|
||||
|
||||
logger.info('Starting n8n Documentation MCP Remote Server');
|
||||
logger.info('Configuration:', {
|
||||
port: config.port,
|
||||
host: config.host,
|
||||
domain: config.domain,
|
||||
cors: config.cors,
|
||||
authEnabled: !!config.authToken,
|
||||
tlsEnabled: !!(config.tlsCert && config.tlsKey),
|
||||
databasePath: process.env.NODE_DB_PATH,
|
||||
});
|
||||
|
||||
const server = new N8NDocumentationRemoteServer(config);
|
||||
|
||||
// Start the server
|
||||
await server.start();
|
||||
|
||||
// Handle graceful shutdown
|
||||
const shutdown = async () => {
|
||||
logger.info('Received shutdown signal');
|
||||
await server.stop();
|
||||
process.exit(0);
|
||||
};
|
||||
|
||||
process.on('SIGINT', shutdown);
|
||||
process.on('SIGTERM', shutdown);
|
||||
|
||||
logger.info('Server is ready to accept connections');
|
||||
logger.info(`Claude Desktop configuration:`);
|
||||
logger.info(JSON.stringify({
|
||||
"mcpServers": {
|
||||
"n8n-nodes-remote": {
|
||||
"command": "curl",
|
||||
"args": [
|
||||
"-X", "POST",
|
||||
"-H", "Content-Type: application/json",
|
||||
"-H", `Authorization: Bearer ${config.authToken || 'YOUR_AUTH_TOKEN'}`,
|
||||
"-d", "@-",
|
||||
`https://${config.domain}/mcp`
|
||||
],
|
||||
"env": {}
|
||||
}
|
||||
}
|
||||
}, null, 2));
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Run the server
|
||||
main().catch((error) => {
|
||||
logger.error('Unhandled error:', error);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user