MCPcopy
hub / github.com/CodebuffAI/codebuff / getToolSet

Function getToolSet

packages/agent-runtime/src/tools/prompts.ts:349–411  ·  view source on GitHub ↗
(params: {
  toolNames: string[]
  additionalToolDefinitions: () => Promise<CustomToolDefinitions>
  agentTools: ToolSet
  skills: SkillsMap
})

Source from the content-addressed store, hash-verified

347}
348
349export async function getToolSet(params: {
350 toolNames: string[]
351 additionalToolDefinitions: () => Promise<CustomToolDefinitions>
352 agentTools: ToolSet
353 skills: SkillsMap
354}): Promise<ToolSet> {
355 const { toolNames, additionalToolDefinitions, agentTools, skills } = params
356
357 // Generate available skills XML for the skill tool description
358 const availableSkillsXml = formatAvailableSkillsXml(skills)
359 const toolSet: ToolSet = {}
360 for (const toolName of toolNames) {
361 if (toolName in toolParams) {
362 const toolDef = toolParams[toolName as ToolName]
363
364 // For the skill tool, replace the placeholder with actual available skills
365 if (toolName === 'skill' && availableSkillsXml) {
366 let description = toolDef.description ?? ''
367 description = description.replace(
368 AVAILABLE_SKILLS_PLACEHOLDER,
369 availableSkillsXml,
370 )
371 toolSet[toolName] = {
372 ...toolDef,
373 description,
374 }
375 } else if (toolName === 'skill') {
376 // Explicitly state no skills are available
377 let description = toolDef.description ?? ''
378 description = description.replace(
379 AVAILABLE_SKILLS_PLACEHOLDER,
380 'There are no skills available. Do not use this tool because there are no skills to load.',
381 )
382 toolSet[toolName] = {
383 ...toolDef,
384 description,
385 }
386 } else {
387 toolSet[toolName] = toolDef
388 }
389 }
390 }
391
392 const toolDefinitions = await additionalToolDefinitions()
393 for (const [toolName, toolDefinition] of Object.entries(toolDefinitions)) {
394 const clonedDef = cloneDeep(toolDefinition)
395 // Custom tool inputSchema may be JSON Schema (from SDK) or Zod (from MCP)
396 // Ensure it's a Zod schema for the AI SDK
397 const zodSchema = ensureZodSchema(clonedDef.inputSchema)
398 const safeSchema = ensureJsonSchemaCompatible(zodSchema)
399 toolSet[toolName] = {
400 ...clonedDef,
401 inputSchema: safeSchema,
402 } as (typeof toolSet)[string]
403 }
404
405 // Add agent tools (agents as direct tool calls)
406 for (const [toolName, toolDefinition] of Object.entries(agentTools)) {

Callers 2

loopAgentStepsFunction · 0.90

Calls 4

formatAvailableSkillsXmlFunction · 0.90
ensureZodSchemaFunction · 0.85

Tested by

no test coverage detected