Implementation of MCP for LLM Observability capture to PostHig
Some checks failed
CI - Semantic Release / Semantic Release (push) Failing after 7m48s
Some checks failed
CI - Semantic Release / Semantic Release (push) Failing after 7m48s
This commit is contained in:
68
src/index.ts
Normal file
68
src/index.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env node
|
||||
import { Logger } from './utils/logger.util.js';
|
||||
import { config } from './utils/config.util.js';
|
||||
import { runCli } from './cli/index.js';
|
||||
import { stdioTransport } from './server/stdio.js';
|
||||
import { streamableHttpTransport } from './server/streamableHttp.js';
|
||||
|
||||
const logger = Logger.forContext('index.ts');
|
||||
|
||||
/**
|
||||
* Start the MCP server with the specified transport mode
|
||||
*/
|
||||
export async function startServer(): Promise<void> {
|
||||
const mainLogger = Logger.forContext('index.ts', 'startServer');
|
||||
|
||||
// Define available transport modes and their handlers
|
||||
const transportModes = {
|
||||
stdio: { handler: stdioTransport, name: 'stdio' },
|
||||
http: { handler: streamableHttpTransport, name: 'http' },
|
||||
};
|
||||
|
||||
// Get requested transport mode (default to stdio)
|
||||
const requestedMode = (process.env.TRANSPORT_MODE || 'stdio').toLowerCase();
|
||||
const transport =
|
||||
transportModes[requestedMode as keyof typeof transportModes] ||
|
||||
transportModes.stdio;
|
||||
|
||||
// Warn if requested mode is invalid
|
||||
if (!transportModes[requestedMode as keyof typeof transportModes]) {
|
||||
mainLogger.warn(
|
||||
`Unknown TRANSPORT_MODE "${requestedMode}", defaulting to stdio`,
|
||||
);
|
||||
}
|
||||
|
||||
// Start the selected transport
|
||||
mainLogger.info(
|
||||
`Starting server with ${transport.name.toUpperCase()} transport`,
|
||||
);
|
||||
transport.handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point
|
||||
*/
|
||||
async function main() {
|
||||
const mainLogger = Logger.forContext('index.ts', 'main');
|
||||
|
||||
// Load configuration
|
||||
config.load();
|
||||
|
||||
// CLI mode - if any arguments are provided
|
||||
if (process.argv.length > 2) {
|
||||
mainLogger.info('CLI mode detected');
|
||||
await runCli(process.argv.slice(2));
|
||||
return;
|
||||
}
|
||||
|
||||
// Server mode - determine transport and start server
|
||||
await startServer();
|
||||
}
|
||||
|
||||
// Run main if executed directly
|
||||
if (require.main === module) {
|
||||
main().catch((err) => {
|
||||
logger.error('Unhandled error in main process', err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user