MCPcopy
hub / github.com/TanStack/ai / createCodeModeSystemPrompt

Function createCodeModeSystemPrompt

packages/ai-code-mode/src/create-system-prompt.ts:28–110  ·  view source on GitHub ↗
(config: CodeModeToolConfig)

Source from the content-addressed store, hash-verified

26 * ```
27 */
28export function createCodeModeSystemPrompt(config: CodeModeToolConfig): string {
29 const { tools } = config
30 const include = config.lazyToolsConfig?.includeDescription ?? 'none'
31
32 const eagerTools = tools.filter((t) => !t.lazy)
33 const lazyTools = tools.filter((t) => t.lazy)
34
35 // Only eager tools get full type stubs + doc lines.
36 const bindings = toolsToBindings(eagerTools, 'external_')
37 const typeStubs = generateTypeStubs(bindings)
38
39 const functionDocs = Object.entries(bindings)
40 .map(([name, binding]) => `- \`${name}(input)\`: ${binding.description}`)
41 .join('\n')
42
43 const discoverableSection =
44 lazyTools.length > 0
45 ? `
46
47### Discoverable APIs
48
49These additional functions are available but not yet documented. Before calling \`external_<name>\` for any of them inside \`execute_typescript\`, call the \`discover_tools\` tool with their names to get full TypeScript signatures:
50
51${lazyTools
52 .map(
53 (t) =>
54 `- ${renderLazyCatalogEntry(`external_${t.name}`, t.description, include)}`,
55 )
56 .join('\n')}`
57 : ''
58
59 return `## Code Execution Tool
60
61You have access to \`execute_typescript\` which runs TypeScript code in a sandboxed environment.
62
63### When to Use
64
65Use \`execute_typescript\` when you need to:
66- Process data with loops, conditionals, or complex logic
67- Make multiple API calls in parallel (Promise.all)
68- Transform, filter, or aggregate data
69- Perform calculations or data analysis
70
71For simple operations, prefer calling tools directly.
72
73### Available External APIs
74
75Inside your TypeScript code, you can call these async functions:
76
77${functionDocs}
78
79### Type Definitions
80
81\`\`\`typescript
82${typeStubs}
83\`\`\`${discoverableSection}
84
85### Example

Callers 4

createCodeModeFunction · 0.90
runStructuredOutputTestFunction · 0.90
codeModeWithSkillsFunction · 0.90

Calls 3

toolsToBindingsFunction · 0.90
generateTypeStubsFunction · 0.90
renderLazyCatalogEntryFunction · 0.90

Tested by

no test coverage detected