Skip to content
Open
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
22 changes: 20 additions & 2 deletions src/core/__tests__/structured-output-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ function expectStandaloneCompile(schema: JsonObject): void {
expect(() => ajv.compile(schema)).not.toThrow();
}

function stripRegistrationResourceEnvelope(schema: JsonObject): JsonObject {
const stripped = JSON.parse(JSON.stringify(schema)) as JsonObject;
delete stripped.$schema;
delete stripped.$id;
delete stripped.$defs;
return stripped;
}

describe('structured output schema bundling', () => {
beforeEach(() => {
__resetMcpOutputSchemaCacheForTests();
Expand Down Expand Up @@ -119,10 +127,20 @@ describe('structured output schema bundling', () => {
$id: 'https://xcodebuildmcp.com/schemas/structured-output/xcodebuildmcp.output.simulator-list/1.registration.schema.json',
type: 'object',
oneOf: [
getMcpOutputSchema(ref),
getMcpOutputSchema({ schema: 'xcodebuildmcp.output.error', version: '1' }),
stripRegistrationResourceEnvelope(getMcpOutputSchema(ref)),
stripRegistrationResourceEnvelope(
getMcpOutputSchema({ schema: 'xcodebuildmcp.output.error', version: '1' }),
),
],
$defs: {
...((getMcpOutputSchema(ref).$defs as JsonObject) ?? {}),
...((getMcpOutputSchema({ schema: 'xcodebuildmcp.output.error', version: '1' })
.$defs as JsonObject) ?? {}),
},
});
expect((jsonSchema.oneOf as JsonObject[])[0].$defs).toBeUndefined();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke test asserts opposite of new behavior

High Severity

The smoke test in e2e-mcp-discovery.test.ts asserts listSimsOutputSchema?.oneOf?.[0]?.$defs is defined, but the production code change in getMcpOutputSchemaForRegistrationJson now strips $defs from oneOf entries via inlineRegistrationSchemaResource. The unit test explicitly asserts the opposite: oneOf[0].$defs is undefined. This smoke test will fail at runtime because it was not updated to match the new inlining behavior.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by project rule: Bugbot Review Guide for XcodeBuildMCP

Reviewed by Cursor Bugbot for commit 5c5a61d. Configure here.

expect((jsonSchema.oneOf as JsonObject[])[0].$id).toBeUndefined();
expect((jsonSchema.$defs as JsonObject).errorConsistency).toBeDefined();
expectNoExternalCommonRefs(jsonSchema);
expectStandaloneCompile(jsonSchema);
});
Expand Down
41 changes: 39 additions & 2 deletions src/core/structured-output-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ function bundleSchema(rootSchema: JsonObject, commonSchema: JsonObject): JsonObj
return bundled;
}

function inlineRegistrationSchemaResource(schema: JsonObject): {
schema: JsonObject;
defs: JsonObject;
} {
const inlinedSchema = cloneJson(schema);
const defsCandidate = inlinedSchema.$defs === undefined ? {} : cloneJson(inlinedSchema.$defs);
if (!isRecord(defsCandidate)) {
throw new Error('Structured output registration $defs must be an object when present.');
}

delete inlinedSchema.$schema;
delete inlinedSchema.$id;
delete inlinedSchema.$defs;

return {
schema: inlinedSchema,
defs: defsCandidate,
};
}

export function getMcpOutputSchema(ref: StructuredOutputSchemaRef): JsonObject {
assertSchemaRef(ref);
const cacheKey = `${ref.schema}@${ref.version}`;
Expand All @@ -226,13 +246,30 @@ function getMcpOutputSchemaForRegistrationJson(ref: StructuredOutputSchemaRef):
if (ref.schema === STRUCTURED_ERROR_SCHEMA_REF.schema) {
return toolSchema;
}
const errorSchema = getMcpOutputSchema(STRUCTURED_ERROR_SCHEMA_REF);
const toolResource = inlineRegistrationSchemaResource(toolSchema);
const errorResource = inlineRegistrationSchemaResource(errorSchema);
const defs: JsonObject = {};

return {
for (const [name, definition] of Object.entries(toolResource.defs)) {
mergeDefinition(defs, name, definition);
}
for (const [name, definition] of Object.entries(errorResource.defs)) {
mergeDefinition(defs, name, definition);
}

const registrationSchema: JsonObject = {
$schema: 'https://json-schema.org/draft/2020-12/schema',
$id: `https://xcodebuildmcp.com/schemas/structured-output/${ref.schema}/${ref.version}.registration.schema.json`,
type: 'object',
oneOf: [toolSchema, getMcpOutputSchema(STRUCTURED_ERROR_SCHEMA_REF)],
oneOf: [toolResource.schema, errorResource.schema],
};

if (Object.keys(defs).length > 0) {
registrationSchema.$defs = defs;
}

return registrationSchema;
}

export function getMcpOutputSchemaForRegistration(ref: StructuredOutputSchemaRef): McpOutputSchema {
Expand Down