Skip to content

Commit 8062d22

Browse files
authored
Merge pull request #16 from damassi/fix/dont-reconnect-if-failed
fix: Dont attempt to reconnect to failed servers
2 parents 2779081 + 36aa2ca commit 8062d22

File tree

7 files changed

+36
-5
lines changed

7 files changed

+36
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
3434
.DS_Store
3535

3636
.claude/settings.local.json
37+
.npmrc

agent-chat-cli.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const config: AgentChatConfig = {
2525
},
2626
github: {
2727
description:
28-
"GitHub MCP tools to search code, PRs, issues; discover documentation in repo docs/; find deployment guides and code examples.",
28+
"GitHub MCP tools to search remote code, PRs, issues; discover documentation in remote repo docs/; find deployment guides and code examples.",
2929
prompt: getPrompt("github.md"),
3030
command: "bunx",
3131
args: [

src/prompts/chrome.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# System Prompt for Chrome Devtools MCP

src/prompts/github.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# System Prompt for Github MCP Server Agent
22

3-
You are a GitHub MCP server agent, optimized for performing operations on github repos.
3+
You are a GitHub MCP server agent, optimized for performing operations on remote github repos.
44

55
### Core Capabilities
66

src/prompts/system.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ You are a helpful Agent specifically designed to handle questions related to sys
77
- **CRITICAL**: Only tools prefixed with `mcp_` are to be invoked. Any other tool such as "Bash", etc are strictly forbidden.
88
- **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.
99
- **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.
10-
1110
- **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.
1211

1312
**DO NOT INVOKE ANY TOOLS AT THIS STEP, JUST OUTPUT A SUMMARY**

src/utils/mcpServerSelectionAgent.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
type SDKUserMessage,
66
} from "@anthropic-ai/claude-agent-sdk"
77
import type { AgentConfig } from "utils/createAgent"
8+
import type { McpServerStatus } from "store"
89
import { log } from "utils/logger"
910
import { z } from "zod"
1011
import { messageTypes } from "./runAgentLoop"
@@ -14,6 +15,7 @@ interface SelectMcpServersOptions {
1415
agents?: Record<string, AgentConfig>
1516
inferredServers?: Set<string>
1617
enabledMcpServers: Record<string, any> | undefined
18+
mcpServers?: McpServerStatus[]
1719
onServerConnection?: (status: string) => void
1820
sessionId?: string
1921
userMessage: string
@@ -24,6 +26,7 @@ export const inferMcpServers = async ({
2426
agents,
2527
inferredServers = new Set(),
2628
enabledMcpServers,
29+
mcpServers: mcpServerStatuses = [],
2730
onServerConnection,
2831
sessionId,
2932
userMessage,
@@ -158,7 +161,33 @@ Examples:
158161

159162
log("[mcpServerSelectionAgent] Selected MCP servers:", selectedServers)
160163

161-
const newServers = selectedServers.filter(
164+
const isRetryRequest = /retry|reconnect/i.test(userMessage)
165+
166+
const failedServers = new Set(
167+
mcpServerStatuses
168+
.filter((s) => s.status === "failed")
169+
.map((s) => s.name.toLowerCase())
170+
)
171+
172+
const serversAfterFailureFilter = isRetryRequest
173+
? selectedServers
174+
: selectedServers.filter(
175+
(server) => !failedServers.has(server.toLowerCase())
176+
)
177+
178+
if (!isRetryRequest && failedServers.size > 0) {
179+
const filteredOut = selectedServers.filter((server) =>
180+
failedServers.has(server.toLowerCase())
181+
)
182+
if (filteredOut.length > 0) {
183+
log(
184+
"[mcpServerSelectionAgent] Excluding failed servers (not a retry):",
185+
filteredOut.join(", ")
186+
)
187+
}
188+
}
189+
190+
const newServers = serversAfterFailureFilter.filter(
162191
(server) => !inferredServers.has(server.toLowerCase())
163192
)
164193

@@ -173,7 +202,7 @@ Examples:
173202

174203
const allServers = new Set([
175204
...Array.from(inferredServers),
176-
...selectedServers,
205+
...serversAfterFailureFilter,
177206
])
178207

179208
const mcpServers =

src/utils/runAgentLoop.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export async function* runAgentLoop({
6565
agents: config.agents,
6666
inferredServers,
6767
enabledMcpServers,
68+
mcpServers,
6869
onServerConnection,
6970
sessionId,
7071
userMessage,

0 commit comments

Comments
 (0)