feat: add HTTP server mode for remote deployment with token auth
This commit is contained in:
@@ -18,13 +18,21 @@ process.on('unhandledRejection', (reason, promise) => {
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
console.error('Starting n8n Documentation MCP Server...');
|
||||
const mode = process.env.MCP_MODE || 'stdio';
|
||||
|
||||
console.error(`Starting n8n Documentation MCP Server in ${mode} mode...`);
|
||||
console.error('Current directory:', process.cwd());
|
||||
console.error('Script directory:', __dirname);
|
||||
console.error('Node version:', process.version);
|
||||
|
||||
const server = new N8NDocumentationMCPServer();
|
||||
await server.run();
|
||||
if (mode === 'http') {
|
||||
// HTTP mode - for remote deployment
|
||||
const { startHTTPServer } = await import('../http-server');
|
||||
await startHTTPServer();
|
||||
} else {
|
||||
// Stdio mode - for local Claude Desktop
|
||||
const server = new N8NDocumentationMCPServer();
|
||||
await server.run();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to start MCP server:', error);
|
||||
logger.error('Failed to start MCP server', error);
|
||||
|
||||
@@ -150,7 +150,9 @@ export class N8NDocumentationMCPServer {
|
||||
}
|
||||
}
|
||||
|
||||
private listNodes(filters: any = {}): any {
|
||||
private async listNodes(filters: any = {}): Promise<any> {
|
||||
await this.ensureInitialized();
|
||||
|
||||
let query = 'SELECT * FROM nodes WHERE 1=1';
|
||||
const params: any[] = [];
|
||||
|
||||
@@ -199,7 +201,8 @@ export class N8NDocumentationMCPServer {
|
||||
};
|
||||
}
|
||||
|
||||
private getNodeInfo(nodeType: string): any {
|
||||
private async getNodeInfo(nodeType: string): Promise<any> {
|
||||
await this.ensureInitialized();
|
||||
if (!this.repository) throw new Error('Repository not initialized');
|
||||
let node = this.repository.getNode(nodeType);
|
||||
|
||||
@@ -228,7 +231,8 @@ export class N8NDocumentationMCPServer {
|
||||
return node;
|
||||
}
|
||||
|
||||
private searchNodes(query: string, limit: number = 20): any {
|
||||
private async searchNodes(query: string, limit: number = 20): Promise<any> {
|
||||
await this.ensureInitialized();
|
||||
if (!this.db) throw new Error('Database not initialized');
|
||||
// Simple search across multiple fields
|
||||
const searchQuery = `%${query}%`;
|
||||
@@ -273,7 +277,8 @@ export class N8NDocumentationMCPServer {
|
||||
return 'low';
|
||||
}
|
||||
|
||||
private listAITools(): any {
|
||||
private async listAITools(): Promise<any> {
|
||||
await this.ensureInitialized();
|
||||
if (!this.repository) throw new Error('Repository not initialized');
|
||||
const tools = this.repository.getAITools();
|
||||
|
||||
@@ -287,7 +292,8 @@ export class N8NDocumentationMCPServer {
|
||||
};
|
||||
}
|
||||
|
||||
private getNodeDocumentation(nodeType: string): any {
|
||||
private async getNodeDocumentation(nodeType: string): Promise<any> {
|
||||
await this.ensureInitialized();
|
||||
if (!this.db) throw new Error('Database not initialized');
|
||||
const node = this.db!.prepare(`
|
||||
SELECT node_type, display_name, documentation
|
||||
@@ -307,7 +313,8 @@ export class N8NDocumentationMCPServer {
|
||||
};
|
||||
}
|
||||
|
||||
private getDatabaseStatistics(): any {
|
||||
private async getDatabaseStatistics(): Promise<any> {
|
||||
await this.ensureInitialized();
|
||||
if (!this.db) throw new Error('Database not initialized');
|
||||
const stats = this.db!.prepare(`
|
||||
SELECT
|
||||
@@ -345,6 +352,15 @@ export class N8NDocumentationMCPServer {
|
||||
};
|
||||
}
|
||||
|
||||
// Add connect method to accept any transport
|
||||
async connect(transport: any): Promise<void> {
|
||||
await this.ensureInitialized();
|
||||
await this.server.connect(transport);
|
||||
logger.info('MCP Server connected', {
|
||||
transportType: transport.constructor.name
|
||||
});
|
||||
}
|
||||
|
||||
async run(): Promise<void> {
|
||||
// Ensure database is initialized before starting server
|
||||
await this.ensureInitialized();
|
||||
|
||||
Reference in New Issue
Block a user