MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getFormatHint

Function getFormatHint

src/utils/mcp/elicitationValidation.ts:258–288  ·  view source on GitHub ↗
(
  schema: PrimitiveSchemaDefinition,
)

Source from the content-addressed store, hash-verified

256 * Returns a helpful placeholder/hint for a given format
257 */
258export function getFormatHint(
259 schema: PrimitiveSchemaDefinition,
260): string | undefined {
261 if (schema.type === 'string') {
262 if (!hasStringFormat(schema)) {
263 return undefined
264 }
265
266 const { description, example } = STRING_FORMATS[schema.format] || {}
267 return `${description}, e.g. ${example}`
268 }
269
270 if (schema.type === 'number' || schema.type === 'integer') {
271 const isInteger = schema.type === 'integer'
272 const formatNum = (n: number) =>
273 Number.isInteger(n) && !isInteger ? `${n}.0` : String(n)
274
275 if (schema.minimum !== undefined && schema.maximum !== undefined) {
276 return `(${schema.type} between ${formatNum(schema.minimum!)} and ${formatNum(schema.maximum!)})`
277 } else if (schema.minimum !== undefined) {
278 return `(${schema.type} >= ${formatNum(schema.minimum!)})`
279 } else if (schema.maximum !== undefined) {
280 return `(${schema.type} <= ${formatNum(schema.maximum!)})`
281 } else {
282 const example = schema.type === 'integer' ? '42' : '3.14'
283 return `(${schema.type}, e.g. ${example})`
284 }
285 }
286
287 return undefined
288}
289
290/**
291 * Check if a schema is a date or date-time format that supports NL parsing

Callers

nothing calls this directly

Calls 2

hasStringFormatFunction · 0.85
formatNumFunction · 0.85

Tested by

no test coverage detected