fix(mcp): sync required array with properties in tool schemas (#754)
* fix(mcp): sync required array with properties in tool schemas MCP servers can emit schemas where the required array contains keys not present in properties. This causes API 400 errors: "Extra required key 'X' supplied." - Add sanitizeSchemaRequired() to filter required arrays - Apply it to MCP tool inputJSONSchema before sending to API - Also fix filterSwarmFieldsFromSchema to update required after removing properties Fixes #525 * test: add MCP schema required sanitization test
This commit is contained in:
@@ -78,3 +78,28 @@ test('toolToAPISchema keeps skill required for SkillTool', async () => {
|
||||
required: ['skill'],
|
||||
})
|
||||
})
|
||||
|
||||
test('toolToAPISchema removes extra required keys not in properties (MCP schema sanitization)', async () => {
|
||||
const schema = await toolToAPISchema(
|
||||
{
|
||||
name: 'mcp__test__create_object',
|
||||
inputSchema: z.strictObject({}),
|
||||
inputJSONSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
name: { type: 'string' },
|
||||
},
|
||||
required: ['name', 'attributes'],
|
||||
},
|
||||
prompt: async () => 'Create an object',
|
||||
} as unknown as Tool,
|
||||
{
|
||||
getToolPermissionContext: async () => getEmptyToolPermissionContext(),
|
||||
tools: [] as unknown as Tools,
|
||||
agents: [],
|
||||
},
|
||||
)
|
||||
|
||||
const inputSchema = (schema as { input_schema: { required?: string[] } }).input_schema
|
||||
expect(inputSchema.required).toEqual(['name'])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user