builder/template_utils library

Constants

maxCodeModeLength → const int
Maximum allowed length for code mode scripts to prevent abuse.
maxPromptArgumentLength → const int
Maximum allowed length for prompt arguments to prevent abuse.
maxSearchQueryLength → const int
Maximum allowed length for search queries to prevent DoS.
primitives → const Set<String>
Set of Dart primitive type names.

Functions

baseType(String type) String
Strips a nullable ? suffix from a type string.
callArgsWithConversion(List<Map<String, dynamic>> params) String
Generates call arguments for a tool invocation, using Converted suffix for List parameters with custom inner types.
collectListInnerImports(List<Map<String, dynamic>> tools) Set<String>
Collects unique import URIs for custom List inner types from all tools.
dartType(String type) String
Normalizes a parameter type string to a Dart type for MCP parameter extraction.
escapeDartString(String s) String
Escapes a string for embedding in a Dart single-quoted string literal.
extractListInnerType(String type) String
Extracts the inner type from a List<T> or List<T>? type string.
filterCodeModeTools(List<Map<String, dynamic>> tools) List<Map<String, dynamic>>
Filters tools to those enabled for code mode (codeMode != false).
filterCodeModeVisibleTools(List<Map<String, dynamic>> tools) List<Map<String, dynamic>>
Filters tools to those that remain visible in the standard tools/list response when the server has @Server(codeMode: true).
filterHandlerToolsForCodeMode(List<Map<String, dynamic>> tools) List<Map<String, dynamic>>
Filters tools whose Dart handler needs to be generated when code mode is enabled. A handler is needed if the tool is either visible in tools/list or callable from the sandbox dispatcher.
generateAnnotationsExpression(Map<String, dynamic> tool) String
Generates the ToolAnnotations expression for a tool, or empty string if none.
generateBuildJsWrapper(List<Map<String, dynamic>> codeModeTools) String
Generates the _buildJsWrapper method that constructs the JS sandbox script.
generateCodeModeHandlers(List<Map<String, dynamic>> codeModeTools, int codeModeTimeout) String
Generates all code mode handler methods combined.
generateCodeModeToolRegistrations() String
Generates the search and execute tool registrations for code mode.
generateDispatchCases(List<Map<String, dynamic>> codeModeTools) String
Generates the _dispatchCodeModeToolCall method.
generateExecuteHandler(int codeModeTimeout) String
Generates the _execute handler method.
generatePromptHandlers(List<Map<String, dynamic>> prompts) String
Generates prompt handler methods for prompts/list and prompts/get.
generatePromptSpecs(List<Map<String, dynamic>> prompts) String
Generates prompt spec constants for each prompt.
generateRunCodeSandbox() String
Generates the _runCodeSandbox method.
generateSearchHandler() String
Generates the _search handler method.
generateToolSpecRegistry(List<Map<String, dynamic>> codeModeTools) String
Generates the static const _codeModeToolSpecs declaration.
isCustomList(String type) bool
Returns true if the type is List<non-primitive,non-dynamic> or nullable variant.
isPrimitive(String type) bool
Returns true if the base type (nullable-stripped) is a primitive.
isPrimitiveList(String type) bool
Returns true if the type is List<primitive> or List<primitive>?.
jsType(String dartType) String
Converts a Dart type string to a JavaScript/JSON Schema type string.
kebabCase(String input) String
Converts a camelCase, PascalCase, or snake_case identifier to kebab-case.
needsListConversion(String type) bool
Checks if a type is a List<T> where T is not a primitive.
pascalCase(String s) String
Capitalizes the first letter of a string.
renderMcpParamExtraction(Map<String, dynamic> p, String dartType) String
Renders a single MCP parameter extraction line for either transport.
renderParamValidation(Map<String, dynamic> p) String
Generates validation code for a parameter if it has validation constraints.