Skip to content

Commit 2fd3b9f

Browse files
committed
Fix mcp for subagents!
1 parent 1ce6109 commit 2fd3b9f

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

.agents/types/util-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ export type MCPConfig =
141141
command: string
142142
args?: string[]
143143
env?: Record<string, string>
144-
headers?: Record<string, string>
145144
}
146145
| {
147146
type?: 'http' | 'sse'
148147
url: string
149148
params?: Record<string, string>
149+
headers?: Record<string, string>
150150
}
151151

152152
// ============================================================================

agents/types/util-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ export type MCPConfig =
141141
command: string
142142
args?: string[]
143143
env?: Record<string, string>
144-
headers?: Record<string, string>
145144
}
146145
| {
147146
type?: 'http' | 'sse'
148147
url: string
149148
params?: Record<string, string>
149+
headers?: Record<string, string>
150150
}
151151

152152
// ============================================================================

common/src/templates/initial-agents-dir/types/util-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ export type MCPConfig =
134134
command: string
135135
args?: string[]
136136
env?: Record<string, string>
137-
headers?: Record<string, string>
138137
}
139138
| {
140139
type?: 'http' | 'sse'
141140
url: string
142141
params?: Record<string, string>
142+
headers?: Record<string, string>
143143
}
144144

145145
// ============================================================================

sdk/src/run.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
getCancelledAdditionalMessages,
77
} from '@codebuff/agent-runtime/util/messages'
88
import { MAX_AGENT_STEPS_DEFAULT } from '@codebuff/common/constants/agents'
9-
import { getMCPClient, listMCPTools } from '@codebuff/common/mcp/client'
9+
import { getMCPClient, listMCPTools, callMCPTool } from '@codebuff/common/mcp/client'
1010
import { toOptionalFile } from '@codebuff/common/old-constants'
1111
import { toolNames } from '@codebuff/common/tools/constants'
1212
import { clientToolCallSchema } from '@codebuff/common/tools/list'
@@ -552,6 +552,30 @@ async function handleToolCall({
552552
const toolName = action.toolName
553553
const input = action.input
554554

555+
// Handle MCP tool calls when mcpConfig is present
556+
if (action.mcpConfig) {
557+
try {
558+
const mcpClientId = await getMCPClient(action.mcpConfig)
559+
const result = await callMCPTool(mcpClientId, {
560+
name: toolName,
561+
arguments: input,
562+
})
563+
return { output: result }
564+
} catch (error) {
565+
return {
566+
output: [
567+
{
568+
type: 'json',
569+
value: {
570+
errorMessage:
571+
error instanceof Error ? error.message : String(error),
572+
},
573+
},
574+
],
575+
}
576+
}
577+
}
578+
555579
let result: ToolResultOutput[]
556580
if (toolNames.includes(toolName as ToolName)) {
557581
clientToolCallSchema.parse(action)

0 commit comments

Comments
 (0)