MCPcopy
hub / github.com/thesysdev/openui / renderToolsSection

Function renderToolsSection

packages/lang-core/src/parser/prompt.ts:473–519  ·  view source on GitHub ↗
(tools: (string | ToolSpec)[])

Source from the content-addressed store, hash-verified

471}
472
473function renderToolsSection(tools: (string | ToolSpec)[]): string {
474 const lines: string[] = [];
475
476 const stringTools: string[] = [];
477 const specTools: ToolSpec[] = [];
478
479 for (const tool of tools) {
480 if (typeof tool === "string") {
481 stringTools.push(tool);
482 } else {
483 specTools.push(tool);
484 }
485 }
486
487 lines.push("## Available Tools");
488 lines.push("");
489 lines.push(
490 "Use these with Query() for read operations or Mutation() for write operations. The LLM decides which is appropriate based on the tool's purpose.",
491 );
492 lines.push("");
493 for (const t of stringTools) {
494 lines.push(`- ${t}`);
495 }
496 for (const t of specTools) {
497 lines.push(renderToolSignature(t));
498 }
499
500 // Default values hint for ToolSpec tools with outputSchema
501 const toolsWithOutput = specTools.filter((t) => t.outputSchema);
502 if (toolsWithOutput.length > 0) {
503 lines.push("");
504 lines.push("### Default values for Query results");
505 lines.push("");
506 lines.push("Use these shapes as minimal Query defaults:");
507 for (const t of toolsWithOutput) {
508 const defaults = defaultForSchema(t.outputSchema as Record<string, unknown>);
509 lines.push(`- ${t.name}: \`${JSON.stringify(defaults)}\``);
510 }
511 }
512
513 lines.push("");
514 lines.push(
515 "CRITICAL: Use ONLY the tools listed above in Query() and Mutation() calls. Do NOT invent or guess tool names. If the user asks for functionality that doesn't match any available tool, use realistic mock data instead of fabricating a tool call.",
516 );
517
518 return lines.join("\n");
519}
520
521// ─── Component signatures ───────────────────────────────────────────────────
522

Callers 1

generatePromptFunction · 0.85

Calls 3

renderToolSignatureFunction · 0.85
defaultForSchemaFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected