feat: add ui/update-model-context (#125)

---------

Co-authored-by: Olivier Chafik <ochafik@anthropic.com>
This commit is contained in:
Ido Salomon 2026-01-12 17:21:45 +02:00 • committed by GitHub
commit b273279849
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 918 additions and 3 deletions

View file

@ -162,6 +162,92 @@
}
},
"additionalProperties": false
},
"updateModelContext": {
"description": "Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns.",
"type": "object",
"properties": {
"text": {
"description": "Host supports text content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"image": {
"description": "Host supports image content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"audio": {
"description": "Host supports audio content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resource": {
"description": "Host supports resource content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resourceLink": {
"description": "Host supports resource link content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"structuredContent": {
"description": "Host supports structured content.",
"type": "object",
"properties": {},
"additionalProperties": false
}
},
"additionalProperties": false
},
"message": {
"description": "Host supports receiving content messages (ui/message) from the Guest UI.",
"type": "object",
"properties": {
"text": {
"description": "Host supports text content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"image": {
"description": "Host supports image content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"audio": {
"description": "Host supports audio content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resource": {
"description": "Host supports resource content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resourceLink": {
"description": "Host supports resource link content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"structuredContent": {
"description": "Host supports structured content.",
"type": "object",
"properties": {},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false
@ -2377,6 +2463,92 @@
}
},
"additionalProperties": false
},
"updateModelContext": {
"description": "Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns.",
"type": "object",
"properties": {
"text": {
"description": "Host supports text content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"image": {
"description": "Host supports image content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"audio": {
"description": "Host supports audio content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resource": {
"description": "Host supports resource content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resourceLink": {
"description": "Host supports resource link content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"structuredContent": {
"description": "Host supports structured content.",
"type": "object",
"properties": {},
"additionalProperties": false
}
},
"additionalProperties": false
},
"message": {
"description": "Host supports receiving content messages (ui/message) from the Guest UI.",
"type": "object",
"properties": {
"text": {
"description": "Host supports text content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"image": {
"description": "Host supports image content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"audio": {
"description": "Host supports audio content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resource": {
"description": "Host supports resource content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resourceLink": {
"description": "Host supports resource link content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"structuredContent": {
"description": "Host supports structured content.",
"type": "object",
"properties": {},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false,
@ -4631,6 +4803,49 @@
],
"description": "Style variables for theming MCP apps.\n\nIndividual style keys are optional - hosts may provide any subset of these values.\nValues are strings containing CSS values (colors, sizes, font stacks, etc.).\n\nNote: This type uses `Record<K, string | undefined>` rather than `Partial<Record<K, string>>`\nfor compatibility with Zod schema generation. Both are functionally equivalent for validation."
},
"McpUiSupportedContentBlockModalities": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"text": {
"description": "Host supports text content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"image": {
"description": "Host supports image content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"audio": {
"description": "Host supports audio content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resource": {
"description": "Host supports resource content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"resourceLink": {
"description": "Host supports resource link content blocks.",
"type": "object",
"properties": {},
"additionalProperties": false
},
"structuredContent": {
"description": "Host supports structured content.",
"type": "object",
"properties": {},
"additionalProperties": false
}
},
"additionalProperties": false
},
"McpUiTheme": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"anyOf": [
@ -5138,6 +5353,351 @@
}
],
"description": "Tool visibility scope - who can access the tool."
},
"McpUiUpdateModelContextRequest": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"method": {
"type": "string",
"const": "ui/update-model-context"
},
"params": {
"type": "object",
"properties": {
"content": {
"description": "Context content blocks (text, image, etc.).",
"type": "array",
"items": {
"anyOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "text"
},
"text": {
"type": "string"
},
"annotations": {
"type": "object",
"properties": {
"audience": {
"type": "array",
"items": {
"type": "string",
"enum": ["user", "assistant"]
}
},
"priority": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"lastModified": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
}
},
"additionalProperties": false
},
"_meta": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
},
"required": ["type", "text"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "image"
},
"data": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"annotations": {
"type": "object",
"properties": {
"audience": {
"type": "array",
"items": {
"type": "string",
"enum": ["user", "assistant"]
}
},
"priority": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"lastModified": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
}
},
"additionalProperties": false
},
"_meta": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
},
"required": ["type", "data", "mimeType"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "audio"
},
"data": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"annotations": {
"type": "object",
"properties": {
"audience": {
"type": "array",
"items": {
"type": "string",
"enum": ["user", "assistant"]
}
},
"priority": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"lastModified": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
}
},
"additionalProperties": false
},
"_meta": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
},
"required": ["type", "data", "mimeType"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"title": {
"type": "string"
},
"icons": {
"type": "array",
"items": {
"type": "object",
"properties": {
"src": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"sizes": {
"type": "array",
"items": {
"type": "string"
}
},
"theme": {
"type": "string",
"enum": ["light", "dark"]
}
},
"required": ["src"],
"additionalProperties": false
}
},
"uri": {
"type": "string"
},
"description": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"annotations": {
"type": "object",
"properties": {
"audience": {
"type": "array",
"items": {
"type": "string",
"enum": ["user", "assistant"]
}
},
"priority": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"lastModified": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
}
},
"additionalProperties": false
},
"_meta": {
"type": "object",
"properties": {},
"additionalProperties": {}
},
"type": {
"type": "string",
"const": "resource_link"
}
},
"required": ["name", "uri", "type"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "resource"
},
"resource": {
"anyOf": [
{
"type": "object",
"properties": {
"uri": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"_meta": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
},
"text": {
"type": "string"
}
},
"required": ["uri", "text"],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"uri": {
"type": "string"
},
"mimeType": {
"type": "string"
},
"_meta": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
},
"blob": {
"type": "string"
}
},
"required": ["uri", "blob"],
"additionalProperties": false
}
]
},
"annotations": {
"type": "object",
"properties": {
"audience": {
"type": "array",
"items": {
"type": "string",
"enum": ["user", "assistant"]
}
},
"priority": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"lastModified": {
"type": "string",
"format": "date-time",
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
}
},
"additionalProperties": false
},
"_meta": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {}
}
},
"required": ["type", "resource"],
"additionalProperties": false
}
]
}
},
"structuredContent": {
"description": "Structured content for machine-readable context data.",
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"description": "Structured content for machine-readable context data."
}
}
},
"additionalProperties": false
}
},
"required": ["method", "params"],
"additionalProperties": false
}
}
}

View file

@ -83,6 +83,10 @@ export type McpUiResourceTeardownResultSchemaInferredType = z.infer<
typeof generated.McpUiResourceTeardownResultSchema
>;
export type McpUiSupportedContentBlockModalitiesSchemaInferredType = z.infer<
typeof generated.McpUiSupportedContentBlockModalitiesSchema
>;
export type McpUiHostCapabilitiesSchemaInferredType = z.infer<
typeof generated.McpUiHostCapabilitiesSchema
>;
@ -135,6 +139,10 @@ export type McpUiHostContextChangedNotificationSchemaInferredType = z.infer<
typeof generated.McpUiHostContextChangedNotificationSchema
>;
export type McpUiUpdateModelContextRequestSchemaInferredType = z.infer<
typeof generated.McpUiUpdateModelContextRequestSchema
>;
export type McpUiInitializeRequestSchemaInferredType = z.infer<
typeof generated.McpUiInitializeRequestSchema
>;
@ -223,6 +231,12 @@ expectType<spec.McpUiResourceTeardownResult>(
expectType<McpUiResourceTeardownResultSchemaInferredType>(
{} as spec.McpUiResourceTeardownResult,
);
expectType<spec.McpUiSupportedContentBlockModalities>(
{} as McpUiSupportedContentBlockModalitiesSchemaInferredType,
);
expectType<McpUiSupportedContentBlockModalitiesSchemaInferredType>(
{} as spec.McpUiSupportedContentBlockModalities,
);
expectType<spec.McpUiHostCapabilities>(
{} as McpUiHostCapabilitiesSchemaInferredType,
);
@ -289,6 +303,12 @@ expectType<spec.McpUiHostContextChangedNotification>(
expectType<McpUiHostContextChangedNotificationSchemaInferredType>(
{} as spec.McpUiHostContextChangedNotification,
);
expectType<spec.McpUiUpdateModelContextRequest>(
{} as McpUiUpdateModelContextRequestSchemaInferredType,
);
expectType<McpUiUpdateModelContextRequestSchemaInferredType>(
{} as spec.McpUiUpdateModelContextRequest,
);
expectType<spec.McpUiInitializeRequest>(
{} as McpUiInitializeRequestSchemaInferredType,
);

View file

@ -358,6 +358,36 @@ export const McpUiResourceTeardownResultSchema = z.record(
z.unknown(),
);
export const McpUiSupportedContentBlockModalitiesSchema = z.object({
/** @description Host supports text content blocks. */
text: z.object({}).optional().describe("Host supports text content blocks."),
/** @description Host supports image content blocks. */
image: z
.object({})
.optional()
.describe("Host supports image content blocks."),
/** @description Host supports audio content blocks. */
audio: z
.object({})
.optional()
.describe("Host supports audio content blocks."),
/** @description Host supports resource content blocks. */
resource: z
.object({})
.optional()
.describe("Host supports resource content blocks."),
/** @description Host supports resource link content blocks. */
resourceLink: z
.object({})
.optional()
.describe("Host supports resource link content blocks."),
/** @description Host supports structured content. */
structuredContent: z
.object({})
.optional()
.describe("Host supports structured content."),
});
/**
* @description Capabilities supported by the host application.
* @see {@link McpUiInitializeResult} for the initialization result that includes these capabilities
@ -411,6 +441,15 @@ export const McpUiHostCapabilitiesSchema = z.object({
})
.optional()
.describe("Sandbox configuration applied by the host."),
/** @description Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns. */
updateModelContext:
McpUiSupportedContentBlockModalitiesSchema.optional().describe(
"Host accepts context updates (ui/update-model-context) to be included in the model's context for future turns.",
),
/** @description Host supports receiving content messages (ui/message) from the Guest UI. */
message: McpUiSupportedContentBlockModalitiesSchema.optional().describe(
"Host supports receiving content messages (ui/message) from the Guest UI.",
),
});
/**
@ -714,6 +753,39 @@ export const McpUiHostContextChangedNotificationSchema = z.object({
),
});
/**
* @description Request to update the agent's context without requiring a follow-up action (Guest UI -> Host).
*
* Unlike `notifications/message` which is for debugging/logging, this request is intended
* to update the Host's model context. Each request overwrites the previous context sent by the Guest UI.
* Unlike messages, context updates do not trigger follow-ups.
*
* The host will typically defer sending the context to the model until the next user message
* (including `ui/message`), and will only send the last update received.
*
* @see {@link app.App.updateModelContext} for the method that sends this request
*/
export const McpUiUpdateModelContextRequestSchema = z.object({
method: z.literal("ui/update-model-context"),
params: z.object({
/** @description Context content blocks (text, image, etc.). */
content: z
.array(ContentBlockSchema)
.optional()
.describe("Context content blocks (text, image, etc.)."),
/** @description Structured content for machine-readable context data. */
structuredContent: z
.record(
z.string(),
z
.unknown()
.describe("Structured content for machine-readable context data."),
)
.optional()
.describe("Structured content for machine-readable context data."),
}),
});
/**
* @description Initialization request sent from Guest UI to Host.
* @see {@link app.App.connect} for the method that sends this request