@boundless-oss/atlas
Version:
Atlas - MCP Server for comprehensive startup project management
102 lines (94 loc) • 3.06 kB
text/typescript
import { describe, it, expect } from 'vitest';
describe('JSON Schema Fix Verification', () => {
it('should demonstrate why required field is necessary', () => {
// According to JSON Schema specification and Anthropic's tool documentation,
// when an inputSchema has properties, it should always include a required field
// This is INVALID according to strict JSON Schema validation
const invalidToolSchema = {
name: 'list_items',
description: 'List items with optional filters',
inputSchema: {
type: 'object',
properties: {
filter: { type: 'string' },
limit: { type: 'number' }
}
// Missing: required: []
}
};
// This is VALID - even with empty required array
const validToolSchema = {
name: 'list_items',
description: 'List items with optional filters',
inputSchema: {
type: 'object',
properties: {
filter: { type: 'string' },
limit: { type: 'number' }
},
required: [] // All parameters are optional
}
};
// This is also VALID - with some required parameters
const validToolSchemaWithRequired = {
name: 'create_item',
description: 'Create a new item',
inputSchema: {
type: 'object',
properties: {
name: { type: 'string' },
description: { type: 'string' }
},
required: ['name'] // name is required, description is optional
}
};
// Verify the schemas
expect(invalidToolSchema.inputSchema).not.toHaveProperty('required');
expect(validToolSchema.inputSchema).toHaveProperty('required');
expect(validToolSchemaWithRequired.inputSchema.required).toContain('name');
});
it('should show the pattern for fixing schemas', () => {
// Before fix:
const before = `{
name: 'list_epics',
description: 'List all epics with optional filtering',
inputSchema: {
type: 'object',
properties: {
status: {
type: 'string',
enum: ['planned', 'active', 'completed', 'cancelled'],
description: 'Filter by epic status'
},
owner: {
type: 'string',
description: 'Filter by epic owner'
},
},
},
}`;
// After fix:
const after = `{
name: 'list_epics',
description: 'List all epics with optional filtering',
inputSchema: {
type: 'object',
properties: {
status: {
type: 'string',
enum: ['planned', 'active', 'completed', 'cancelled'],
description: 'Filter by epic status'
},
owner: {
type: 'string',
description: 'Filter by epic owner'
},
},
required: [], // Added this line - all parameters are optional
},
}`;
// This test just documents the fix pattern
expect(before).not.toContain('required:');
expect(after).toContain('required: []');
});
});