From 37fd1abced0473752145c9068147412e8b2d0b82 Mon Sep 17 00:00:00 2001 From: Christopher Pappas Date: Sat, 22 Nov 2025 22:19:13 +0100 Subject: [PATCH] fix: better failed check --- src/hooks/useAgent.ts | 2 +- src/prompts/system.md | 2 +- src/utils/__tests__/getPrompt.test.ts | 5 +++-- src/utils/getPrompt.ts | 12 ++++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/hooks/useAgent.ts b/src/hooks/useAgent.ts index c6148f8..aa63702 100644 --- a/src/hooks/useAgent.ts +++ b/src/hooks/useAgent.ts @@ -161,7 +161,7 @@ export function useAgent() { actions.setIsProcessing(false) } }, - [config, messageQueue, actions] + [config, mcpServers, messageQueue, actions] ) // Start listening for new messages from input diff --git a/src/prompts/system.md b/src/prompts/system.md index 14f126a..65e66fc 100644 --- a/src/prompts/system.md +++ b/src/prompts/system.md @@ -5,7 +5,7 @@ You are a helpful Agent specifically designed to handle questions related to sys ## Core Rules - **CRITICAL**: Only tools prefixed with `mcp_` are to be invoked. Any other tool such as "Bash", etc are strictly forbidden. - +- **CRITICAL**: When a user attempts to user a tool or MCP server, understand that the first pass is an inference call. If the inference call fails, immediately review the system prompt to see if the tool or MCP server is allowed (ie, CONNECTED). If it is not connected, do not attempt to invoke the tool or MCP server. - **CRITICAL**: When a user starts a convo and asks a question or assigns you a task (example: "in github, please summarize the last merged pr"), before beginning your task (ie, calling tools, etc) respond back immediately with a small summary about what you're going to do, in a friendly kind of way. Then start working. - **CRITICAL**: If a user starts a convo with a general greeting (like "Hi!" or "Hello!") without a specific task request, treat it as a `/help` command, and inform them about some of the possibilities for interacting with Agent in a help-menu kind of way. Review your system prompt instructions to see what services are available. diff --git a/src/utils/__tests__/getPrompt.test.ts b/src/utils/__tests__/getPrompt.test.ts index 01c1f22..84780bd 100644 --- a/src/utils/__tests__/getPrompt.test.ts +++ b/src/utils/__tests__/getPrompt.test.ts @@ -191,8 +191,9 @@ describe("buildSystemPrompt", () => { config, }) - expect(prompt).not.toContain("Available MCP Servers") - expect(prompt).not.toContain("Unavailable MCP Servers") + expect(prompt).toContain("CRITICAL: MCP Server Connection Status Check") + expect(prompt).not.toContain("# Available MCP Servers") + expect(prompt).not.toContain("# Unavailable MCP Servers") }) test("should handle empty inferred servers set", async () => { diff --git a/src/utils/getPrompt.ts b/src/utils/getPrompt.ts index 498e950..1d045a8 100644 --- a/src/utils/getPrompt.ts +++ b/src/utils/getPrompt.ts @@ -58,6 +58,18 @@ export const buildSystemPrompt = async ({ parts.push(additionalSystemPrompt) } + parts.push(`# CRITICAL: MCP Server Connection Status Check + +**BEFORE responding to ANY request involving an inferred MCP server, you MUST:** + +1. Check the "Unavailable MCP Servers" section +2. If the requested server is listed as FAILED/unavailable: + - IMMEDIATELY inform the user the server failed to connect in a friendly way + - State that NO tools are available for that server + - DO NOT offer functionality or ask how they'd like to use it + - STOP processing that request +`) + if (mcpServers.length > 0) { // Add connection status sections first as these are the source of truth. // Inference is secondary.