Skip to content

feat: add wasm-unsafe-eval CSP option#667

Open
idosal wants to merge 1 commit into
mainfrom
codex/wasm-unsafe-eval-csp
Open

feat: add wasm-unsafe-eval CSP option#667
idosal wants to merge 1 commit into
mainfrom
codex/wasm-unsafe-eval-csp

Conversation

@idosal
Copy link
Copy Markdown
Contributor

@idosal idosal commented May 26, 2026

Summary

  • Adds an explicit wasmUnsafeEval option to _meta.ui.csp / McpUiResourceCsp and regenerates the protocol schemas.
  • Updates the Apps spec CSP examples so hosts can map that option to the script-src source expression 'wasm-unsafe-eval'.

This PR implements the conservative declarative path. If Hosts agree that wasm-unsafe-eval is safe enough to include by default, we can simplify the spec.

Fixes #605.

Test Plan

  • npm run generate:schemas
  • npm run build
  • bun test examples/basic-host/test/csp.test.ts
  • npm run --workspace examples/basic-host build
  • npm test
  • npm run build:all (pre-commit)
  • Manual CSP inspection with tsx: wasmUnsafeEval: true adds 'wasm-unsafe-eval'; omission preserves the existing script-src.

Copilot AI review requested due to automatic review settings May 26, 2026 22:04
@github-actions
Copy link
Copy Markdown
Contributor

📖 Docs Preview Deployed

Preview (stable) https://pr-667.mcp-ext-apps-docs-preview.pages.dev
This commit https://020012d8.mcp-ext-apps-docs-preview.pages.dev
Commit 9bbbaec

Includes drafts and future-dated posts. All pages served with noindex, nofollow — search engines will not crawl this preview.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 26, 2026

Open in StackBlitz

@modelcontextprotocol/ext-apps

npm i https://pkg.pr.new/@modelcontextprotocol/ext-apps@667

@modelcontextprotocol/server-basic-preact

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-preact@667

@modelcontextprotocol/server-basic-react

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-react@667

@modelcontextprotocol/server-basic-solid

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-solid@667

@modelcontextprotocol/server-basic-svelte

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-svelte@667

@modelcontextprotocol/server-basic-vanillajs

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vanillajs@667

@modelcontextprotocol/server-basic-vue

npm i https://pkg.pr.new/@modelcontextprotocol/server-basic-vue@667

@modelcontextprotocol/server-budget-allocator

npm i https://pkg.pr.new/@modelcontextprotocol/server-budget-allocator@667

@modelcontextprotocol/server-cohort-heatmap

npm i https://pkg.pr.new/@modelcontextprotocol/server-cohort-heatmap@667

@modelcontextprotocol/server-customer-segmentation

npm i https://pkg.pr.new/@modelcontextprotocol/server-customer-segmentation@667

@modelcontextprotocol/server-debug

npm i https://pkg.pr.new/@modelcontextprotocol/server-debug@667

@modelcontextprotocol/server-map

npm i https://pkg.pr.new/@modelcontextprotocol/server-map@667

@modelcontextprotocol/server-pdf

npm i https://pkg.pr.new/@modelcontextprotocol/server-pdf@667

@modelcontextprotocol/server-scenario-modeler

npm i https://pkg.pr.new/@modelcontextprotocol/server-scenario-modeler@667

@modelcontextprotocol/server-shadertoy

npm i https://pkg.pr.new/@modelcontextprotocol/server-shadertoy@667

@modelcontextprotocol/server-sheet-music

npm i https://pkg.pr.new/@modelcontextprotocol/server-sheet-music@667

@modelcontextprotocol/server-system-monitor

npm i https://pkg.pr.new/@modelcontextprotocol/server-system-monitor@667

@modelcontextprotocol/server-threejs

npm i https://pkg.pr.new/@modelcontextprotocol/server-threejs@667

@modelcontextprotocol/server-transcript

npm i https://pkg.pr.new/@modelcontextprotocol/server-transcript@667

@modelcontextprotocol/server-video-resource

npm i https://pkg.pr.new/@modelcontextprotocol/server-video-resource@667

@modelcontextprotocol/server-wiki-explorer

npm i https://pkg.pr.new/@modelcontextprotocol/server-wiki-explorer@667

commit: f252149

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an explicit wasmUnsafeEval boolean to the UI CSP metadata (_meta.ui.csp / McpUiResourceCsp) so hosts can selectively allow WebAssembly compilation via the CSP script-src source expression 'wasm-unsafe-eval'. It also updates the published spec examples accordingly and refactors the examples/basic-host CSP logic into a reusable helper with basic unit tests.

Changes:

  • Add wasmUnsafeEval?: boolean to McpUiResourceCsp and regenerate the TypeScript/Zod/JSON schemas.
  • Update Apps specification examples to show mapping wasmUnsafeEval'wasm-unsafe-eval' in script-src.
  • Extract examples/basic-host CSP building into src/csp.ts and add tests around the new option.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/spec.types.ts Adds wasmUnsafeEval to the CSP metadata type and documents mapping to 'wasm-unsafe-eval'.
src/generated/schema.ts Regenerates Zod schema to include optional wasmUnsafeEval.
src/generated/schema.json Regenerates JSON schema to include optional wasmUnsafeEval.
specification/draft/apps.mdx Updates draft spec CSP interface + reference CSP construction example to include wasmUnsafeEval.
specification/2026-01-26/apps.mdx Updates versioned spec CSP interface + example to include wasmUnsafeEval.
examples/basic-host/src/csp.ts New helper to build CSP headers (adds 'wasm-unsafe-eval' when requested).
examples/basic-host/test/csp.test.ts Adds unit tests verifying 'wasm-unsafe-eval' is included/omitted based on wasmUnsafeEval.
examples/basic-host/serve.ts Refactors server to import and use the extracted buildCspHeader helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +8 to +11
function sanitizeCspDomains(domains?: string[]): string[] {
if (!domains) return [];
return domains.filter((d) => typeof d === "string" && !/[;\r\n'" ]/.test(d));
}
Comment on lines +20 to +27
const scriptSources = [
"'self'",
"'unsafe-inline'",
"'unsafe-eval'",
...(csp?.wasmUnsafeEval === true ? ["'wasm-unsafe-eval'"] : []),
"blob:",
"data:",
].join(" ");
Comment on lines +2524 to 2529
const wasmUnsafeEval = csp?.wasmUnsafeEval ? "'wasm-unsafe-eval'" : "";

const cspValue = `
default-src 'none';
script-src 'self' 'unsafe-inline' ${csp?.resourceDomains?.join(' ') || ''};
script-src 'self' 'unsafe-inline' ${wasmUnsafeEval} ${csp?.resourceDomains?.join(' ') || ''};
style-src 'self' 'unsafe-inline' ${csp?.resourceDomains?.join(' ') || ''};
Comment on lines +1739 to 1744
const wasmUnsafeEval = csp?.wasmUnsafeEval ? "'wasm-unsafe-eval'" : "";

const cspValue = `
default-src 'none';
script-src 'self' 'unsafe-inline' ${csp?.resourceDomains?.join(' ') || ''};
script-src 'self' 'unsafe-inline' ${wasmUnsafeEval} ${csp?.resourceDomains?.join(' ') || ''};
style-src 'self' 'unsafe-inline' ${csp?.resourceDomains?.join(' ') || ''};
Comment thread src/spec.types.ts
* @description Whether the UI requires WebAssembly compilation.
*
* - Maps to the CSP `script-src` source expression `'wasm-unsafe-eval'`
* - Empty or false → WebAssembly compilation remains blocked by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support wasm-unsafe-eval CSP directive to enable WebAssembly in MCP Apps

2 participants