@@ -445,6 +445,7 @@ function parseToolArgs(args, schemaProperties = {}) {
445445 /** @type {Record<string, unknown> } */
446446 const result = { } ;
447447 let jsonOutput = false ;
448+ const hasSchemaProperties = Object . keys ( schemaProperties ) . length > 0 ;
448449 const { normalizedSchemaKeyMap, ambiguousNormalizedSchemaKeys } = buildNormalizedSchemaKeyMap ( schemaProperties ) ;
449450
450451 for ( let i = 0 ; i < args . length ; i ++ ) {
@@ -458,13 +459,13 @@ function parseToolArgs(args, schemaProperties = {}) {
458459 jsonOutput = true ;
459460 } else {
460461 const canonicalKey = resolveSchemaPropertyKey ( key , schemaProperties , normalizedSchemaKeyMap , ambiguousNormalizedSchemaKeys ) ;
461- result [ canonicalKey ] = coerceToolArgValue ( canonicalKey , raw . slice ( eqIdx + 1 ) , schemaProperties [ canonicalKey ] , result [ canonicalKey ] ) ;
462+ result [ canonicalKey ] = coerceToolArgValue ( canonicalKey , raw . slice ( eqIdx + 1 ) , schemaProperties [ canonicalKey ] , result [ canonicalKey ] , ! hasSchemaProperties ) ;
462463 }
463464 } else if ( raw === "json" ) {
464465 jsonOutput = true ;
465466 } else if ( i + 1 < args . length && ! args [ i + 1 ] . startsWith ( "--" ) ) {
466467 const canonicalKey = resolveSchemaPropertyKey ( raw , schemaProperties , normalizedSchemaKeyMap , ambiguousNormalizedSchemaKeys ) ;
467- result [ canonicalKey ] = coerceToolArgValue ( canonicalKey , args [ i + 1 ] , schemaProperties [ canonicalKey ] , result [ canonicalKey ] ) ;
468+ result [ canonicalKey ] = coerceToolArgValue ( canonicalKey , args [ i + 1 ] , schemaProperties [ canonicalKey ] , result [ canonicalKey ] , ! hasSchemaProperties ) ;
468469 i ++ ;
469470 } else {
470471 const canonicalKey = resolveSchemaPropertyKey ( raw , schemaProperties , normalizedSchemaKeyMap , ambiguousNormalizedSchemaKeys ) ;
@@ -549,9 +550,10 @@ function resolveSchemaPropertyKey(key, schemaProperties, normalizedSchemaKeyMap,
549550 * @param {string } rawValue - Raw CLI value
550551 * @param {{type?: string|string[]}|undefined } schemaProperty - JSON schema property
551552 * @param {unknown } existingValue - Existing value (for repeated flags)
553+ * @param {boolean } [allowNumericFallback=false] - Allow numeric parsing when schema is unavailable
552554 * @returns {unknown }
553555 */
554- function coerceToolArgValue ( key , rawValue , schemaProperty , existingValue ) {
556+ function coerceToolArgValue ( key , rawValue , schemaProperty , existingValue , allowNumericFallback = false ) {
555557 /** @type {string[] } */
556558 const types = [ ] ;
557559 if ( schemaProperty && typeof schemaProperty === "object" && "type" in schemaProperty && schemaProperty . type != null ) {
@@ -620,6 +622,26 @@ function coerceToolArgValue(key, rawValue, schemaProperty, existingValue) {
620622 }
621623 }
622624
625+ // When schema metadata is unavailable (e.g. empty tools cache), apply
626+ // conservative numeric coercion fallback for CLI ergonomics.
627+ if ( allowNumericFallback && types . length === 0 ) {
628+ const trimmedValue = rawValue . trim ( ) ;
629+
630+ if ( / ^ - ? \d + $ / . test ( trimmedValue ) ) {
631+ const parsedInt = Number . parseInt ( trimmedValue , 10 ) ;
632+ if ( ! Number . isNaN ( parsedInt ) && Number . isSafeInteger ( parsedInt ) ) {
633+ return parsedInt ;
634+ }
635+ }
636+
637+ if ( / ^ - ? (?: (?: \d + \. \d * | \. \d + ) (?: [ e E ] [ + - ] ? \d + ) ? | \d + [ e E ] [ + - ] ? \d + ) $ / . test ( trimmedValue ) ) {
638+ const parsedFloat = Number . parseFloat ( trimmedValue ) ;
639+ if ( ! Number . isNaN ( parsedFloat ) && Number . isFinite ( parsedFloat ) ) {
640+ return parsedFloat ;
641+ }
642+ }
643+ }
644+
623645 return rawValue ;
624646}
625647
0 commit comments