diff --git a/src/cli/call-arguments.ts b/src/cli/call-arguments.ts index 47af74b..ea705a3 100644 --- a/src/cli/call-arguments.ts +++ b/src/cli/call-arguments.ts @@ -17,6 +17,7 @@ export interface CallArgsParseResult { output: OutputFormat; timeoutMs?: number; ephemeral?: EphemeralServerSpec; + rawStrings?: boolean; } export function parseCallArguments(args: string[]): CallArgsParseResult { @@ -68,6 +69,11 @@ export function parseCallArguments(args: string[]): CallArgsParseResult { index += 1; continue; } + if (token === '--raw-strings' || token === '--no-coerce') { + result.rawStrings = true; + index += 1; + continue; + } if (token === '--args') { const value = args[index + 1]; if (!value) { @@ -168,12 +174,12 @@ export function parseCallArguments(args: string[]): CallArgsParseResult { } const parsed = parseKeyValueToken(token, positional[index + 1]); if (!parsed) { - trailingPositional.push(coerceValue(token)); + trailingPositional.push(coerceValue(token, result.rawStrings)); index += 1; continue; } index += parsed.consumed; - const value = coerceValue(parsed.rawValue); + const value = coerceValue(parsed.rawValue, result.rawStrings); if (parsed.key === 'tool' && !result.tool) { if (typeof value !== 'string') { throw new Error("Argument 'tool' must be a string value."); @@ -273,7 +279,7 @@ function extractHttpCallExpression(raw: string): ReturnType { ); warnSpy.mockRestore(); }); + + it('coerces numeric strings to numbers by default', () => { + const parsed = parseCallArguments(['server.tool', 'code=123456']); + expect(parsed.args.code).toBe(123456); + expect(typeof parsed.args.code).toBe('number'); + }); + + it('preserves numeric strings when --raw-strings flag is used', () => { + const parsed = parseCallArguments(['--raw-strings', 'server.tool', 'code=123456']); + expect(parsed.args.code).toBe('123456'); + expect(typeof parsed.args.code).toBe('string'); + expect(parsed.rawStrings).toBe(true); + }); + + it('preserves leading zeros when --raw-strings flag is used', () => { + const parsed = parseCallArguments(['--raw-strings', 'server.tool', 'pin=000123']); + expect(parsed.args.pin).toBe('000123'); + expect(typeof parsed.args.pin).toBe('string'); + }); + + it('preserves numeric strings when --no-coerce alias is used', () => { + const parsed = parseCallArguments(['--no-coerce', 'server.tool', 'id=007']); + expect(parsed.args.id).toBe('007'); + expect(typeof parsed.args.id).toBe('string'); + }); });