Skip to content

Commit 09a9b66

Browse files
committed
- Added a PreWarm Model feature to the MCP server. I am using this in a rather large NX monorepo, and tools like search_codebase were timing out, and the indexing was timing out. What this PreWarm feature does is, as the tool initializes the MCP server, we index the codebase so that it's ready when the agent needs to use the codebase context mcp server for it's tools.
1 parent 6cd5e58 commit 09a9b66

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,20 @@ async function main() {
11331133
logStartup('[DEBUG] Index found. Ready.');
11341134
indexState.status = 'ready';
11351135
indexState.lastIndexed = new Date();
1136+
1137+
// Pre-warm the embedding model in background to avoid timeout on first search
1138+
// This loads the ML model (can take 30-90s) before any search request comes in
1139+
if (process.env.CODEBASE_CONTEXT_PREWARM_MODEL !== 'false') {
1140+
logStartup('[DEBUG] Pre-warming embedding model...');
1141+
import('./embeddings/index.js')
1142+
.then(({ getEmbeddingProvider }) => getEmbeddingProvider())
1143+
.then(() => {
1144+
logStartup('[DEBUG] Embedding model ready');
1145+
})
1146+
.catch((err) => {
1147+
console.warn('[WARN] Failed to pre-warm embedding model:', err.message);
1148+
});
1149+
}
11361150
}
11371151

11381152
const transport = new StdioServerTransport();

0 commit comments

Comments
 (0)