Skip to content

Commit 3958043

Browse files
committed
perf(plugin): remove blocking wait from system prompt generation
System prompt now uses server names from config (instant) instead of waiting for MCP servers to connect (400-1500ms). Tools are still discoverable via toolbox_search_* once servers connect in background. Signed-off-by: assagman <ahmetsercansagman@gmail.com>
1 parent 35bfa7d commit 3958043

File tree

1 file changed

+8
-30
lines changed

1 file changed

+8
-30
lines changed

src/plugin.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -250,32 +250,18 @@ You have access to an extended toolbox with additional capabilities (web search,
250250
2. Execute: toolbox_execute({ name: "tool_name", arguments: '{"key": "value"}' })`;
251251

252252
/**
253-
* Generate system prompt with registered MCP servers and their tools
254-
* Uses JSON schema format with full tool names (serverName_toolName)
253+
* Generate system prompt with configured MCP server names
254+
* Server names come from config (instant) - no need to wait for connections
255255
*/
256-
function generateSystemPrompt(mcpManager: MCPManager): string {
257-
const servers = mcpManager.getAllServers();
258-
259-
if (servers.length === 0) {
260-
return SYSTEM_PROMPT_BASE;
261-
}
262-
263-
const toolboxSchema: Record<string, string[]> = {};
264-
265-
for (const server of servers) {
266-
if (server.status === "connected" && server.tools.length > 0) {
267-
toolboxSchema[server.name] = server.tools.map((t) => t.idString);
268-
}
269-
}
270-
271-
if (Object.keys(toolboxSchema).length === 0) {
256+
function generateSystemPrompt(configuredServers: string[]): string {
257+
if (configuredServers.length === 0) {
272258
return SYSTEM_PROMPT_BASE;
273259
}
274260

275261
return `${SYSTEM_PROMPT_BASE}
276262
277263
## Registered MCP Servers
278-
${Object.entries(toolboxSchema).map(([server, tools]) => `- ${server}: ${tools.map(t => t.split('_').slice(1).join('_')).join(', ')}`).join('\n')}`;
264+
- ${configuredServers.join(", ")}`;
279265
}
280266

281267
/**
@@ -920,18 +906,10 @@ export const ToolboxPlugin: Plugin = async (ctx: PluginInput) => {
920906
},
921907

922908
// Inject system prompt with tool search instructions
909+
// NOTE: We use serverNames from config (instant) - no waiting for connections.
910+
// Tools are discoverable via toolbox_search_* once servers connect.
923911
"experimental.chat.system.transform": async (_input, output) => {
924-
// Wait for partial readiness before generating system prompt
925-
// This is non-blocking if already ready
926-
if (!mcpManager.isReady() && initMode === "eager") {
927-
try {
928-
await mcpManager.waitForPartial();
929-
} catch {
930-
// Continue with base prompt if waiting fails
931-
}
932-
}
933-
934-
output.system.push(generateSystemPrompt(mcpManager));
912+
output.system.push(generateSystemPrompt(serverNames));
935913
},
936914
};
937915
};

0 commit comments

Comments
 (0)