@mcp-native/webview 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,90 @@
1
+ <div align="center">
2
+
1
3
  # @mcp-native/webview
2
4
 
3
- Part of MCP Native a native UI runtime for Model Context Protocol applications.
5
+ ### A deny-by-default HTML MCP App compatibility boundary
6
+
7
+ [![npm](https://img.shields.io/npm/v/@mcp-native/webview)](https://www.npmjs.com/package/@mcp-native/webview)
8
+ [![downloads](https://img.shields.io/npm/dm/@mcp-native/webview)](https://www.npmjs.com/package/@mcp-native/webview)
9
+ [![license](https://img.shields.io/npm/l/@mcp-native/webview)](https://github.com/pablospaniard/mcp-native/blob/main/LICENSE)
10
+
11
+ [GitHub](https://github.com/pablospaniard/mcp-native) · [Architecture](https://github.com/pablospaniard/mcp-native/blob/main/docs/RFC-0001-architecture.md) · [Security](https://github.com/pablospaniard/mcp-native/blob/main/SECURITY.md)
12
+
13
+ </div>
14
+
15
+ > **Experimental:** this package defines document validation and policy decisions. It does not yet mount or sandbox a platform WebView.
16
+
17
+ `@mcp-native/webview` handles the compatibility path for MCP resources that contain HTML. It recognizes supported MIME types, prefers inline documents, and rejects remote documents unless the host explicitly grants them through policy.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ npm install @mcp-native/webview
23
+ ```
24
+
25
+ `@mcp-native/core` is installed as a dependency. The package is ESM-only and includes TypeScript declarations.
26
+
27
+ ## Inline HTML
28
+
29
+ ```ts
30
+ import { createWebViewDocument } from "@mcp-native/webview";
31
+
32
+ const document = createWebViewDocument({
33
+ uri: "mcp://example/app",
34
+ mimeType: "text/html",
35
+ text: "<main>Hello from an MCP App</main>",
36
+ });
37
+
38
+ // { kind: "inline", html: "...", baseUrl: "mcp://example/app" }
39
+ ```
40
+
41
+ ## Remote documents are denied by default
42
+
43
+ ```ts
44
+ import { createWebViewDocument, WebViewPolicyError } from "@mcp-native/webview";
45
+
46
+ const resource = {
47
+ uri: "https://example.com/app",
48
+ mimeType: "text/html",
49
+ };
50
+
51
+ try {
52
+ createWebViewDocument(resource);
53
+ } catch (error) {
54
+ if (error instanceof WebViewPolicyError) {
55
+ console.error(error.message);
56
+ }
57
+ }
58
+
59
+ const allowed = createWebViewDocument(resource, {
60
+ allowRemoteDocuments: true,
61
+ });
62
+ ```
63
+
64
+ ## Public API
65
+
66
+ | Export | Purpose |
67
+ | ----------------------- | ------------------------------------------------------------------------------ |
68
+ | `isHtmlResource` | Returns whether a resource declares a supported HTML MIME type. |
69
+ | `createWebViewDocument` | Validates a resource and returns an inline or policy-approved remote document. |
70
+ | `WebViewPolicy` | Host policy controlling whether remote documents are allowed. |
71
+ | `WebViewDocument` | Discriminated union for inline and remote documents. |
72
+ | `WebViewPolicyError` | Error thrown for unsupported MIME types or denied remote documents. |
73
+
74
+ Supported MIME types are `text/html` and `text/html+skybridge`.
75
+
76
+ ## Host responsibilities
77
+
78
+ Returning a `WebViewDocument` is not permission to render it without further controls. A production host must still define:
79
+
80
+ - allowed origins and navigation rules;
81
+ - bridge message schemas and directionality;
82
+ - storage, cookie, download, and external-link policy;
83
+ - camera, microphone, location, clipboard, and filesystem permissions;
84
+ - process isolation and platform-specific WebView hardening.
85
+
86
+ See the repository's [security policy](https://github.com/pablospaniard/mcp-native/blob/main/SECURITY.md) before expanding this boundary. Install [`mcp-native`](https://www.npmjs.com/package/mcp-native) for the complete public API.
87
+
88
+ ## License
4
89
 
5
- Early development.
90
+ [MIT](https://github.com/pablospaniard/mcp-native/blob/main/LICENSE)
@@ -0,0 +1,18 @@
1
+ import type { McpResource } from "@mcp-native/core";
2
+ export interface WebViewPolicy {
3
+ readonly allowRemoteDocuments?: boolean;
4
+ }
5
+ export type WebViewDocument = {
6
+ readonly kind: "inline";
7
+ readonly html: string;
8
+ readonly baseUrl: string;
9
+ } | {
10
+ readonly kind: "remote";
11
+ readonly uri: string;
12
+ };
13
+ export declare class WebViewPolicyError extends Error {
14
+ constructor(message: string);
15
+ }
16
+ export declare function isHtmlResource(resource: McpResource): boolean;
17
+ export declare function createWebViewDocument(resource: McpResource, policy?: WebViewPolicy): WebViewDocument;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CACzC;AAED,MAAM,MAAM,eAAe,GACvB;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACF;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAE7D;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,WAAW,EACrB,MAAM,GAAE,aAAkB,GACzB,eAAe,CAgBjB"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ const HTML_MIME_TYPES = new Set(["text/html", "text/html+skybridge"]);
2
+ export class WebViewPolicyError extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "WebViewPolicyError";
6
+ }
7
+ }
8
+ export function isHtmlResource(resource) {
9
+ return resource.mimeType !== undefined && HTML_MIME_TYPES.has(resource.mimeType);
10
+ }
11
+ export function createWebViewDocument(resource, policy = {}) {
12
+ if (!isHtmlResource(resource)) {
13
+ throw new WebViewPolicyError(`Unsupported WebView MIME type: ${resource.mimeType ?? "unknown"}`);
14
+ }
15
+ if (resource.text !== undefined) {
16
+ return { kind: "inline", html: resource.text, baseUrl: resource.uri };
17
+ }
18
+ if (policy.allowRemoteDocuments !== true) {
19
+ throw new WebViewPolicyError("Remote WebView documents are disabled by policy");
20
+ }
21
+ return { kind: "remote", uri: resource.uri };
22
+ }
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAiBtE,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAC,QAAqB;IAClD,OAAO,QAAQ,CAAC,QAAQ,KAAK,SAAS,IAAI,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACnF,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,QAAqB,EACrB,MAAM,GAAkB,EAAE;IAE1B,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9B,MAAM,IAAI,kBAAkB,CAC1B,kCAAkC,QAAQ,CAAC,QAAQ,IAAI,SAAS,EAAE,CACnE,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;IACxE,CAAC;IAED,IAAI,MAAM,CAAC,oBAAoB,KAAK,IAAI,EAAE,CAAC;QACzC,MAAM,IAAI,kBAAkB,CAAC,iDAAiD,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC;AAC/C,CAAC"}
package/package.json CHANGED
@@ -1,12 +1,42 @@
1
1
  {
2
2
  "name": "@mcp-native/webview",
3
- "version": "0.0.1",
4
- "main": "index.js",
5
- "scripts": {
6
- "test": "echo \"Error: no test specified\" && exit 1"
3
+ "version": "0.0.3",
4
+ "description": "Policy-gated WebView fallback primitives for MCP Native.",
5
+ "keywords": [
6
+ "mcp",
7
+ "mcp-apps",
8
+ "model-context-protocol",
9
+ "security",
10
+ "webview"
11
+ ],
12
+ "homepage": "https://github.com/pablospaniard/mcp-native#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/pablospaniard/mcp-native/issues"
7
15
  },
8
- "keywords": [],
9
- "author": "",
10
16
  "license": "MIT",
11
- "description": "MCP Native - webview package"
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/pablospaniard/mcp-native.git",
20
+ "directory": "packages/webview"
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "dependencies": {
40
+ "@mcp-native/core": "^0.0.3"
41
+ }
12
42
  }
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = {};