Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
.DS_Store

.claude/settings.local.json
.npmrc
2 changes: 1 addition & 1 deletion agent-chat-cli.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const config: AgentChatConfig = {
},
github: {
description:
"GitHub MCP tools to search code, PRs, issues; discover documentation in repo docs/; find deployment guides and code examples.",
"GitHub MCP tools to search remote code, PRs, issues; discover documentation in remote repo docs/; find deployment guides and code examples.",
prompt: getPrompt("github.md"),
command: "bunx",
args: [
Expand Down
1 change: 1 addition & 0 deletions src/prompts/chrome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# System Prompt for Chrome Devtools MCP
2 changes: 1 addition & 1 deletion src/prompts/github.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# System Prompt for Github MCP Server Agent

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

### Core Capabilities

Expand Down
1 change: 0 additions & 1 deletion src/prompts/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ You are a helpful Agent specifically designed to handle questions related to sys
- **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.

**DO NOT INVOKE ANY TOOLS AT THIS STEP, JUST OUTPUT A SUMMARY**
Expand Down
33 changes: 31 additions & 2 deletions src/utils/mcpServerSelectionAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
type SDKUserMessage,
} from "@anthropic-ai/claude-agent-sdk"
import type { AgentConfig } from "utils/createAgent"
import type { McpServerStatus } from "store"
import { log } from "utils/logger"
import { z } from "zod"
import { messageTypes } from "./runAgentLoop"
Expand All @@ -14,6 +15,7 @@ interface SelectMcpServersOptions {
agents?: Record<string, AgentConfig>
inferredServers?: Set<string>
enabledMcpServers: Record<string, any> | undefined
mcpServers?: McpServerStatus[]
onServerConnection?: (status: string) => void
sessionId?: string
userMessage: string
Expand All @@ -24,6 +26,7 @@ export const inferMcpServers = async ({
agents,
inferredServers = new Set(),
enabledMcpServers,
mcpServers: mcpServerStatuses = [],
onServerConnection,
sessionId,
userMessage,
Expand Down Expand Up @@ -158,7 +161,33 @@ Examples:

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

const newServers = selectedServers.filter(
const isRetryRequest = /retry|reconnect/i.test(userMessage)

const failedServers = new Set(
mcpServerStatuses
.filter((s) => s.status === "failed")
.map((s) => s.name.toLowerCase())
)

const serversAfterFailureFilter = isRetryRequest
? selectedServers
: selectedServers.filter(
(server) => !failedServers.has(server.toLowerCase())
)

if (!isRetryRequest && failedServers.size > 0) {
const filteredOut = selectedServers.filter((server) =>
failedServers.has(server.toLowerCase())
)
if (filteredOut.length > 0) {
log(
"[mcpServerSelectionAgent] Excluding failed servers (not a retry):",
filteredOut.join(", ")
)
}
}

const newServers = serversAfterFailureFilter.filter(
(server) => !inferredServers.has(server.toLowerCase())
)

Expand All @@ -173,7 +202,7 @@ Examples:

const allServers = new Set([
...Array.from(inferredServers),
...selectedServers,
...serversAfterFailureFilter,
])

const mcpServers =
Expand Down
1 change: 1 addition & 0 deletions src/utils/runAgentLoop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function* runAgentLoop({
agents: config.agents,
inferredServers,
enabledMcpServers,
mcpServers,
onServerConnection,
sessionId,
userMessage,
Expand Down