Repository navigation
Fix/embedding initialization and single instance - #134
Merged
thomaszang merged 7 commits intoOct 21, 2026
Merged
Conversation
Remove --port flag from start script to use pure stdio mode instead of HTTP mode. HTTP mode with --port spawns a new instance per request, causing the multiple instance problem. Direct stdio mode maintains a single persistent instance. Before: npx -y supergateway --port 9881 --stdio "node ./build/start.js" After: node ./build/start.js This ensures only one MCP server instance runs at a time.
Complete fix for initialization order and async handling: 1. Move ALL initialization BEFORE server.connect(): - Get server configuration - Generate/load embeddings (with await) - Load documentation files - Setup telemetry - THEN connect to transport 2. Add missing await keywords: - await retrieveAndStore() - line 1898 - await retrieveAndStoreRule() - line 1910 3. Use correct embeddings path: - ./embeddings/ instead of ./build/embeddings/ This ensures: - Server only signals ready when fully initialized - Embeddings complete before accepting requests - No race conditions with stdio mode - Single instance handles all requests correctly
…ition Changes: - Make retrieveAndStoreRule() async and return Promise<void> - Add await before createEmbeddings() call - Fix embeddings.d.ts to declare createEmbeddings returns Promise<void> This ensures rule embeddings fully complete before server.connect() is called. Previously, retrieveAndStoreRule fired createEmbeddings without await, causing embeddings to generate in the background after the server reported ready.
The path should go up two levels from build/lib/ to reach project root: - Before: path.join(__dirname, "..", "embeddings") → build/embeddings/ - After: path.join(__dirname, "..", "..", "embeddings") → ./embeddings/ This fixes the issue where embeddings were written to build/embeddings/ but the code was checking ./embeddings/, causing regeneration on every start.
Keep embeddings in build/embeddings/ as requested: - Revert embeddings.js path back to ../embeddings (from build/lib) - Update index.ts to check build/embeddings - Remove /embeddings/ from gitignore (not needed) Embeddings survive rebuilds because tsc doesn't clear the build directory, it only replaces .js files. The build/embeddings folder persists.
yaosheng79
approved these changes
Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.