@mcp-native/react-native 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 +87 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -7
- package/index.js +0 -1
package/README.md
CHANGED
|
@@ -1,5 +1,90 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @mcp-native/react-native
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
### Trusted native render plans for validated MCP surfaces
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@mcp-native/react-native)
|
|
8
|
+
[](https://www.npmjs.com/package/@mcp-native/react-native)
|
|
9
|
+
[](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 currently produces a serializable render plan. It does not yet ship React components, hooks, or a complete React Native renderer.
|
|
16
|
+
|
|
17
|
+
`@mcp-native/react-native` converts a surface already validated by `@mcp-native/a2ui` into a tree whose component names come from a fixed host-owned catalog. Servers provide data and declared actions—not JavaScript modules or arbitrary component names.
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @mcp-native/react-native
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`@mcp-native/a2ui` and `@mcp-native/core` are installed as dependencies. React and React Native are not dependencies yet because this preview returns data rather than mounting components.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { parseA2uiSurface } from "@mcp-native/a2ui";
|
|
31
|
+
import { createNativeRenderPlan } from "@mcp-native/react-native";
|
|
32
|
+
|
|
33
|
+
const surface = parseA2uiSurface({
|
|
34
|
+
version: "0.1",
|
|
35
|
+
root: {
|
|
36
|
+
id: "card",
|
|
37
|
+
type: "container",
|
|
38
|
+
children: [
|
|
39
|
+
{ id: "title", type: "text", text: "Ready to continue?" },
|
|
40
|
+
{
|
|
41
|
+
id: "continue",
|
|
42
|
+
type: "button",
|
|
43
|
+
label: "Continue",
|
|
44
|
+
action: { type: "tool", name: "continue_flow" },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const plan = createNativeRenderPlan(surface);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`plan` contains only the currently allowed component names:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
type NativeComponentName = "Button" | "Text" | "TextInput" | "View";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The application host decides how each name maps to a locally bundled component and how declared button actions reach `McpNativeRuntime`.
|
|
60
|
+
|
|
61
|
+
## Public API
|
|
62
|
+
|
|
63
|
+
| Export | Purpose |
|
|
64
|
+
| ------------------------ | ----------------------------------------------------------------------------------------------- |
|
|
65
|
+
| `createNativeRenderPlan` | Converts a validated `A2uiSurface` into a `NativeElement` tree. |
|
|
66
|
+
| `NativeElement` | Serializable render-plan node with a key, trusted component name, props, and optional children. |
|
|
67
|
+
| `NativeComponentName` | Union of component names currently allowed in the plan. |
|
|
68
|
+
|
|
69
|
+
## Current mappings
|
|
70
|
+
|
|
71
|
+
| Surface node | Native component | Selected props |
|
|
72
|
+
| ------------ | ---------------- | --------------------------------------------- |
|
|
73
|
+
| `container` | `View` | Nested `children` |
|
|
74
|
+
| `text` | `Text` | Text as `children` |
|
|
75
|
+
| `button` | `Button` | `title` and validated `action` |
|
|
76
|
+
| `text-input` | `TextInput` | `label`, optional `value`, optional `binding` |
|
|
77
|
+
|
|
78
|
+
## Trust boundary
|
|
79
|
+
|
|
80
|
+
- The server cannot select components outside the catalog.
|
|
81
|
+
- The server cannot send executable React Native code.
|
|
82
|
+
- Render plans should only be created from a successfully validated surface.
|
|
83
|
+
- The host must explicitly map component names, bind events, enforce permissions, and approve sensitive tool calls.
|
|
84
|
+
- Future styling and component expansion must preserve allowlists rather than spreading unchecked server props.
|
|
85
|
+
|
|
86
|
+
See [`@mcp-native/a2ui`](https://www.npmjs.com/package/@mcp-native/a2ui) for parsing and [`@mcp-native/core`](https://www.npmjs.com/package/@mcp-native/core) for action dispatch. Install [`mcp-native`](https://www.npmjs.com/package/mcp-native) for every public API.
|
|
87
|
+
|
|
88
|
+
## License
|
|
4
89
|
|
|
5
|
-
|
|
90
|
+
[MIT](https://github.com/pablospaniard/mcp-native/blob/main/LICENSE)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { A2uiSurface } from "@mcp-native/a2ui";
|
|
2
|
+
export type NativeComponentName = "Button" | "Text" | "TextInput" | "View";
|
|
3
|
+
/**
|
|
4
|
+
* A serializable render plan. A React Native host maps these trusted component
|
|
5
|
+
* names to locally bundled components; the MCP server never supplies code.
|
|
6
|
+
*/
|
|
7
|
+
export interface NativeElement {
|
|
8
|
+
readonly key: string;
|
|
9
|
+
readonly component: NativeComponentName;
|
|
10
|
+
readonly props: Readonly<Record<string, unknown>>;
|
|
11
|
+
readonly children?: readonly NativeElement[];
|
|
12
|
+
}
|
|
13
|
+
export declare function createNativeRenderPlan(surface: A2uiSurface): NativeElement;
|
|
14
|
+
//# 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,EAAY,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,SAAS,EAAE,mBAAmB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAClD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CAC9C;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,CAE1E"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function createNativeRenderPlan(surface) {
|
|
2
|
+
return renderNode(surface.root);
|
|
3
|
+
}
|
|
4
|
+
function renderNode(node) {
|
|
5
|
+
switch (node.type) {
|
|
6
|
+
case "container":
|
|
7
|
+
return {
|
|
8
|
+
key: node.id,
|
|
9
|
+
component: "View",
|
|
10
|
+
props: {},
|
|
11
|
+
children: node.children.map(renderNode),
|
|
12
|
+
};
|
|
13
|
+
case "text":
|
|
14
|
+
return {
|
|
15
|
+
key: node.id,
|
|
16
|
+
component: "Text",
|
|
17
|
+
props: { children: node.text },
|
|
18
|
+
};
|
|
19
|
+
case "button":
|
|
20
|
+
return {
|
|
21
|
+
key: node.id,
|
|
22
|
+
component: "Button",
|
|
23
|
+
props: { title: node.label, action: node.action },
|
|
24
|
+
};
|
|
25
|
+
case "text-input":
|
|
26
|
+
return {
|
|
27
|
+
key: node.id,
|
|
28
|
+
component: "TextInput",
|
|
29
|
+
props: {
|
|
30
|
+
label: node.label,
|
|
31
|
+
...(node.value === undefined ? {} : { value: node.value }),
|
|
32
|
+
...(node.binding === undefined ? {} : { binding: node.binding }),
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|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;iBACjE;aACF,CAAC;IACN,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcp-native/react-native",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "React Native renderer primitives for MCP Native.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"a2ui",
|
|
7
|
+
"mcp",
|
|
8
|
+
"model-context-protocol",
|
|
9
|
+
"native-ui",
|
|
10
|
+
"react-native"
|
|
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
|
-
"
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/pablospaniard/mcp-native.git",
|
|
20
|
+
"directory": "packages/react-native"
|
|
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/a2ui": "^0.0.3",
|
|
41
|
+
"@mcp-native/core": "^0.0.3"
|
|
42
|
+
}
|
|
12
43
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|