feat(mcps): unify SSE/Stdio transport and fix handshake timeouts

This commit is contained in:
2026-03-05 12:04:19 +01:00
parent 29423123b3
commit daa2750f89
5 changed files with 141 additions and 75 deletions

View File

@@ -12,14 +12,6 @@ async function main() {
const qdrantService = new QdrantMemoryService(process.env.QDRANT_URL || 'http://localhost:6333');
// Initialize embedding model and Qdrant connection
try {
await qdrantService.initialize();
} catch (e) {
console.error('Failed to initialize local dependencies. Exiting.');
process.exit(1);
}
server.tool(
'store_memory',
'Store a new piece of knowledge/memory into the vector database. Use this to remember architectural decisions, preferences, aliases, etc.',
@@ -71,10 +63,18 @@ async function main() {
const isStdio = process.argv.includes('--stdio');
if (isStdio) {
// Connect Stdio FIRST to avoid handshake timeouts while loading model
const { StdioServerTransport } = await import('@modelcontextprotocol/sdk/server/stdio.js');
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('Memory MCP server is running on stdio');
// Initialize dependency after connection
try {
await qdrantService.initialize();
} catch (e) {
console.error('Failed to initialize local dependencies:', e);
}
} else {
const app = express();
let transport: SSEServerTransport | null = null;
@@ -94,13 +94,19 @@ async function main() {
});
const PORT = process.env.MEMORY_MCP_PORT || 3002;
app.listen(PORT, () => {
console.error(`Memory MCP server is running on http://localhost:${PORT}/sse`);
app.listen(PORT, async () => {
console.error(`Memory MCP server running on http://localhost:${PORT}/sse`);
// Initialize dependencies in SSE mode on startup
try {
await qdrantService.initialize();
} catch (e) {
console.error('Failed to initialize local dependencies:', e);
}
});
}
}
main().catch((error) => {
console.error('Fatal error in main():', error);
console.error('Fatal error:', error);
process.exit(1);
});