(metadata: {
toolName?: string | null
toolDescription?: string | null
parameterSchema?: unknown
})
| 156 | } |
| 157 | |
| 158 | export function validateMcpToolMetadataForStorage(metadata: { |
| 159 | toolName?: string | null |
| 160 | toolDescription?: string | null |
| 161 | parameterSchema?: unknown |
| 162 | }): string | null { |
| 163 | if (metadata.toolName && utf8Size(metadata.toolName) > MAX_MCP_TOOL_NAME_BYTES) { |
| 164 | return `Tool name exceeds maximum size of ${MAX_MCP_TOOL_NAME_BYTES} bytes` |
| 165 | } |
| 166 | |
| 167 | if ( |
| 168 | metadata.toolDescription && |
| 169 | utf8Size(metadata.toolDescription) > MAX_MCP_TOOL_DESCRIPTION_BYTES |
| 170 | ) { |
| 171 | return `Tool description exceeds maximum size of ${MAX_MCP_TOOL_DESCRIPTION_BYTES} bytes` |
| 172 | } |
| 173 | |
| 174 | if (metadata.parameterSchema !== undefined) { |
| 175 | const parameterSchemaBytes = jsonSize(metadata.parameterSchema) |
| 176 | if (parameterSchemaBytes === null) { |
| 177 | return 'Tool parameter schema must be JSON serializable' |
| 178 | } |
| 179 | if (parameterSchemaBytes > MAX_MCP_PARAMETER_SCHEMA_BYTES) { |
| 180 | return `Tool parameter schema exceeds maximum size of ${MAX_MCP_PARAMETER_SCHEMA_BYTES} bytes` |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return null |
| 185 | } |
no test coverage detected