Skip to content

Commit 181a4dc

Browse files
antonpk1claude
andcommitted
feat: add UI resource metadata types for CSP and rendering config
Add types for parsing `_meta.ui` field from resources/read responses: - McpUiResourceCspSchema: CSP domain declarations (connectDomains for fetch/XHR/WebSocket, resourceDomains for scripts/images/fonts) - McpUiResourceMetaSchema: Full metadata including CSP, dedicated domain for widget sandbox, and border preference Hosts need these to construct CSP headers and configure iframe sandboxing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1a6f237 commit 181a4dc

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/types.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,40 @@ type _VerifyInitializedNotification = VerifySchemaMatches<
823823
typeof McpUiInitializedNotificationSchema,
824824
McpUiInitializedNotification
825825
>;
826+
827+
// =============================================================================
828+
// UI Resource Metadata Types
829+
// =============================================================================
830+
831+
/**
832+
* Content Security Policy configuration for UI resources.
833+
*
834+
* Servers declare which external origins their UI needs to access.
835+
* Hosts use this to enforce appropriate CSP headers.
836+
*
837+
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx
838+
*/
839+
export const McpUiResourceCspSchema = z.object({
840+
/** Origins for network requests (fetch/XHR/WebSocket). Maps to CSP connect-src */
841+
connectDomains: z.array(z.string()).optional(),
842+
/** Origins for static resources (images, scripts, stylesheets, fonts). Maps to CSP img-src, script-src, style-src, font-src */
843+
resourceDomains: z.array(z.string()).optional(),
844+
});
845+
export type McpUiResourceCsp = z.infer<typeof McpUiResourceCspSchema>;
846+
847+
/**
848+
* UI Resource metadata for security and rendering configuration.
849+
*
850+
* Included in the `_meta.ui` field of UI resource content returned via resources/read.
851+
*
852+
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx
853+
*/
854+
export const McpUiResourceMetaSchema = z.object({
855+
/** Content Security Policy configuration */
856+
csp: McpUiResourceCspSchema.optional(),
857+
/** Dedicated origin for widget sandbox */
858+
domain: z.string().optional(),
859+
/** Visual boundary preference - true if UI prefers a visible border */
860+
prefersBorder: z.boolean().optional(),
861+
});
862+
export type McpUiResourceMeta = z.infer<typeof McpUiResourceMetaSchema>;

0 commit comments

Comments
 (0)