@@ -203,6 +203,26 @@ function bundleSchema(rootSchema: JsonObject, commonSchema: JsonObject): JsonObj
203203 return bundled ;
204204}
205205
206+ function inlineRegistrationSchemaResource ( schema : JsonObject ) : {
207+ schema : JsonObject ;
208+ defs : JsonObject ;
209+ } {
210+ const inlinedSchema = cloneJson ( schema ) ;
211+ const defsCandidate = inlinedSchema . $defs === undefined ? { } : cloneJson ( inlinedSchema . $defs ) ;
212+ if ( ! isRecord ( defsCandidate ) ) {
213+ throw new Error ( 'Structured output registration $defs must be an object when present.' ) ;
214+ }
215+
216+ delete inlinedSchema . $schema ;
217+ delete inlinedSchema . $id ;
218+ delete inlinedSchema . $defs ;
219+
220+ return {
221+ schema : inlinedSchema ,
222+ defs : defsCandidate ,
223+ } ;
224+ }
225+
206226export function getMcpOutputSchema ( ref : StructuredOutputSchemaRef ) : JsonObject {
207227 assertSchemaRef ( ref ) ;
208228 const cacheKey = `${ ref . schema } @${ ref . version } ` ;
@@ -226,13 +246,30 @@ function getMcpOutputSchemaForRegistrationJson(ref: StructuredOutputSchemaRef):
226246 if ( ref . schema === STRUCTURED_ERROR_SCHEMA_REF . schema ) {
227247 return toolSchema ;
228248 }
249+ const errorSchema = getMcpOutputSchema ( STRUCTURED_ERROR_SCHEMA_REF ) ;
250+ const toolResource = inlineRegistrationSchemaResource ( toolSchema ) ;
251+ const errorResource = inlineRegistrationSchemaResource ( errorSchema ) ;
252+ const defs : JsonObject = { } ;
229253
230- return {
254+ for ( const [ name , definition ] of Object . entries ( toolResource . defs ) ) {
255+ mergeDefinition ( defs , name , definition ) ;
256+ }
257+ for ( const [ name , definition ] of Object . entries ( errorResource . defs ) ) {
258+ mergeDefinition ( defs , name , definition ) ;
259+ }
260+
261+ const registrationSchema : JsonObject = {
231262 $schema : 'https://json-schema.org/draft/2020-12/schema' ,
232263 $id : `https://xcodebuildmcp.com/schemas/structured-output/${ ref . schema } /${ ref . version } .registration.schema.json` ,
233264 type : 'object' ,
234- oneOf : [ toolSchema , getMcpOutputSchema ( STRUCTURED_ERROR_SCHEMA_REF ) ] ,
265+ oneOf : [ toolResource . schema , errorResource . schema ] ,
235266 } ;
267+
268+ if ( Object . keys ( defs ) . length > 0 ) {
269+ registrationSchema . $defs = defs ;
270+ }
271+
272+ return registrationSchema ;
236273}
237274
238275export function getMcpOutputSchemaForRegistration ( ref : StructuredOutputSchemaRef ) : McpOutputSchema {
0 commit comments