Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## [0.12.3] - Unreleased

- Nothing yet.
- Render list signatures and call examples from array item schemas, keeping number, boolean, object, and unknown arrays type-correct. (Issue #221, thanks @VincXiong)

## [0.12.2] - 2026-06-27

Expand Down
49 changes: 45 additions & 4 deletions src/cli/generate/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function extractOptions(tool: ServerToolInfo): GeneratedOption[] {
const defaultValue = getDescriptorDefault(descriptor);
const formatInfo = getDescriptorFormatHint(descriptor);
const placeholder = buildPlaceholder(property, type, enumValues, formatInfo?.slug);
const exampleValue = buildExampleValue(property, type, enumValues, defaultValue);
const exampleValue = buildExampleValue(property, type, enumValues, defaultValue, arrayItemType);
return {
property,
cliName: toCliOption(property),
Expand Down Expand Up @@ -181,7 +181,8 @@ export function buildExampleValue(
property: string,
type: GeneratedOption['type'],
enumValues: string[] | undefined,
defaultValue: unknown
defaultValue: unknown,
arrayItemType?: GeneratedOption['arrayItemType']
): string | undefined {
if (enumValues && enumValues.length > 0) {
return enumValues[0] as string;
Expand All @@ -199,7 +200,16 @@ export function buildExampleValue(
case 'boolean':
return 'true';
case 'array':
return 'value1,value2';
switch (arrayItemType) {
case 'number':
return '1,2';
case 'boolean':
return 'true,false';
case 'object':
return '[{"key":"value"}]';
default:
return 'value1,value2';
}
case 'object':
return '{"key":"value"}';
default:
Expand All @@ -214,6 +224,28 @@ export function buildExampleValue(
}

export function pickExampleLiteral(option: GeneratedOption): string | undefined {
if (option.type === 'array') {
if (Array.isArray(option.defaultValue)) {
try {
return JSON.stringify(option.defaultValue);
} catch {
return undefined;
}
}
if (option.enumValues && option.enumValues.length > 0) {
return JSON.stringify([option.enumValues[0]]);
}
switch (option.arrayItemType) {
case 'number':
return '[1, 2]';
case 'boolean':
return '[true, false]';
case 'object':
return '[{"key":"value"}]';
default:
break;
}
}
if (option.enumValues && option.enumValues.length > 0) {
return JSON.stringify(option.enumValues[0]);
}
Expand Down Expand Up @@ -251,7 +283,16 @@ export function buildFallbackLiteral(option: GeneratedOption): string {
case 'boolean':
return 'true';
case 'array':
return '["value1"]';
switch (option.arrayItemType) {
case 'number':
return '[1]';
case 'boolean':
return '[true]';
case 'object':
return '[{"key":"value"}]';
default:
return '["value1"]';
}
case 'object':
return '{"key":"value"}';
default: {
Expand Down
88 changes: 88 additions & 0 deletions tests/generate-cli-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ describe('generate helpers', () => {
expect(buildExampleValue('itemId', 'string', undefined, undefined)).toBe('example-id');
expect(buildExampleValue('mode', 'string', ['fast'], undefined)).toBe('fast');
expect(buildExampleValue('fields', 'object', undefined, undefined)).toBe('{"key":"value"}');
expect(buildExampleValue('scores', 'array', undefined, undefined, 'number')).toBe('1,2');
expect(buildExampleValue('flags', 'array', undefined, undefined, 'boolean')).toBe('true,false');
expect(buildExampleValue('records', 'array', undefined, undefined, 'object')).toBe('[{"key":"value"}]');

expect(inferType({ type: 'boolean' })).toBe('boolean');
expect(inferType({ type: 'integer' })).toBe('number');
Expand Down Expand Up @@ -143,6 +146,61 @@ describe('generate helpers', () => {
placeholder: '<items>',
})
).toBe('["foo", "bar"]');
expect(
pickExampleLiteral({
type: 'array',
arrayItemType: 'number',
exampleValue: '1,2',
property: 'scores',
cliName: 'scores',
required: true,
placeholder: '<scores>',
})
).toBe('[1, 2]');
expect(
pickExampleLiteral({
type: 'array',
arrayItemType: 'boolean',
exampleValue: 'true,false',
property: 'flags',
cliName: 'flags',
required: true,
placeholder: '<flags>',
})
).toBe('[true, false]');
expect(
pickExampleLiteral({
type: 'array',
arrayItemType: 'object',
exampleValue: '[{"key":"value"}]',
property: 'records',
cliName: 'records',
required: true,
placeholder: '<records>',
})
).toBe('[{"key":"value"}]');
expect(
pickExampleLiteral({
type: 'array',
arrayItemType: 'number',
defaultValue: [3, 5],
property: 'scores',
cliName: 'scores',
required: true,
placeholder: '<scores>',
})
).toBe('[3,5]');
expect(
pickExampleLiteral({
type: 'array',
arrayItemType: 'string',
enumValues: ['alpha', 'beta'],
property: 'labels',
cliName: 'labels',
required: true,
placeholder: '<labels>',
})
).toBe('["alpha"]');
expect(
pickExampleLiteral({
type: 'string',
Expand All @@ -162,6 +220,36 @@ describe('generate helpers', () => {
placeholder: '<issue-id>',
})
).toBe('"example-id"');
expect(
buildFallbackLiteral({
type: 'array',
arrayItemType: 'number',
property: 'scores',
cliName: 'scores',
required: false,
placeholder: '<scores>',
})
).toBe('[1]');
expect(
buildFallbackLiteral({
type: 'array',
arrayItemType: 'boolean',
property: 'flags',
cliName: 'flags',
required: false,
placeholder: '<flags>',
})
).toBe('[true]');
expect(
buildFallbackLiteral({
type: 'array',
arrayItemType: 'object',
property: 'records',
cliName: 'records',
required: false,
placeholder: '<records>',
})
).toBe('[{"key":"value"}]');
expect(
buildFallbackLiteral({
type: 'array',
Expand Down
18 changes: 18 additions & 0 deletions tests/list-detail-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ describe('formatCallExpressionExample', () => {
);
expect(example).toBe('mcporter call \'https://mcp.sentry.dev/mcp?agent=1.use_sentry(request: "value")\'');
});

it('keeps array examples consistent with their item types', () => {
const example = formatCallExpressionExample('fixture', 'array_probe', [
baseOption({ property: 'scores', type: 'array', arrayItemType: 'number', exampleValue: '1,2' }),
baseOption({ property: 'flags', type: 'array', arrayItemType: 'boolean', exampleValue: 'true,false' }),
baseOption({
property: 'records',
type: 'array',
arrayItemType: 'object',
exampleValue: '[{"key":"value"}]',
}),
baseOption({ property: 'names', type: 'array', arrayItemType: 'string', exampleValue: 'value1,value2' }),
]);

expect(example).toBe(
'mcporter call fixture.array_probe(scores: [1, 2], flags: [true, false], records: [{"key":"value"}], names: ["value1", "value2"])'
);
});
});

describe('formatExampleBlock', () => {
Expand Down