react-native-mcp-kit 1.0.0
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/LICENSE +21 -0
- package/README.md +868 -0
- package/dist/babel/index.d.ts +3 -0
- package/dist/babel/index.d.ts.map +1 -0
- package/dist/babel/index.js +11 -0
- package/dist/babel/index.js.map +1 -0
- package/dist/babel/stripPlugin.d.ts +5 -0
- package/dist/babel/stripPlugin.d.ts.map +1 -0
- package/dist/babel/stripPlugin.js +100 -0
- package/dist/babel/stripPlugin.js.map +1 -0
- package/dist/babel/testIdPlugin.d.ts +5 -0
- package/dist/babel/testIdPlugin.d.ts.map +1 -0
- package/dist/babel/testIdPlugin.js +69 -0
- package/dist/babel/testIdPlugin.js.map +1 -0
- package/dist/client/contexts/McpContext/McpContext.d.ts +3 -0
- package/dist/client/contexts/McpContext/McpContext.d.ts.map +1 -0
- package/dist/client/contexts/McpContext/McpContext.js +6 -0
- package/dist/client/contexts/McpContext/McpContext.js.map +1 -0
- package/dist/client/contexts/McpContext/McpProvider.d.ts +3 -0
- package/dist/client/contexts/McpContext/McpProvider.d.ts.map +1 -0
- package/dist/client/contexts/McpContext/McpProvider.js +28 -0
- package/dist/client/contexts/McpContext/McpProvider.js.map +1 -0
- package/dist/client/contexts/McpContext/index.d.ts +4 -0
- package/dist/client/contexts/McpContext/index.d.ts.map +1 -0
- package/dist/client/contexts/McpContext/index.js +8 -0
- package/dist/client/contexts/McpContext/index.js.map +1 -0
- package/dist/client/contexts/McpContext/types.d.ts +12 -0
- package/dist/client/contexts/McpContext/types.d.ts.map +1 -0
- package/dist/client/contexts/McpContext/types.js +3 -0
- package/dist/client/contexts/McpContext/types.js.map +1 -0
- package/dist/client/contexts/McpTreeContext/McpTracker.d.ts +10 -0
- package/dist/client/contexts/McpTreeContext/McpTracker.d.ts.map +1 -0
- package/dist/client/contexts/McpTreeContext/McpTracker.js +101 -0
- package/dist/client/contexts/McpTreeContext/McpTracker.js.map +1 -0
- package/dist/client/contexts/McpTreeContext/McpTreeContext.d.ts +2 -0
- package/dist/client/contexts/McpTreeContext/McpTreeContext.d.ts.map +1 -0
- package/dist/client/contexts/McpTreeContext/McpTreeContext.js +6 -0
- package/dist/client/contexts/McpTreeContext/McpTreeContext.js.map +1 -0
- package/dist/client/contexts/McpTreeContext/McpTreeRegistry.d.ts +16 -0
- package/dist/client/contexts/McpTreeContext/McpTreeRegistry.d.ts.map +1 -0
- package/dist/client/contexts/McpTreeContext/McpTreeRegistry.js +96 -0
- package/dist/client/contexts/McpTreeContext/McpTreeRegistry.js.map +1 -0
- package/dist/client/contexts/McpTreeContext/index.d.ts +5 -0
- package/dist/client/contexts/McpTreeContext/index.d.ts.map +1 -0
- package/dist/client/contexts/McpTreeContext/index.js +10 -0
- package/dist/client/contexts/McpTreeContext/index.js.map +1 -0
- package/dist/client/contexts/McpTreeContext/types.d.ts +14 -0
- package/dist/client/contexts/McpTreeContext/types.d.ts.map +1 -0
- package/dist/client/contexts/McpTreeContext/types.js +3 -0
- package/dist/client/contexts/McpTreeContext/types.js.map +1 -0
- package/dist/client/core/McpClient.d.ts +25 -0
- package/dist/client/core/McpClient.d.ts.map +1 -0
- package/dist/client/core/McpClient.js +183 -0
- package/dist/client/core/McpClient.js.map +1 -0
- package/dist/client/hooks/useMcpModule.d.ts +4 -0
- package/dist/client/hooks/useMcpModule.d.ts.map +1 -0
- package/dist/client/hooks/useMcpModule.js +17 -0
- package/dist/client/hooks/useMcpModule.js.map +1 -0
- package/dist/client/hooks/useMcpState.d.ts +3 -0
- package/dist/client/hooks/useMcpState.d.ts.map +1 -0
- package/dist/client/hooks/useMcpState.js +20 -0
- package/dist/client/hooks/useMcpState.js.map +1 -0
- package/dist/client/hooks/useMcpTool.d.ts +4 -0
- package/dist/client/hooks/useMcpTool.d.ts.map +1 -0
- package/dist/client/hooks/useMcpTool.js +20 -0
- package/dist/client/hooks/useMcpTool.js.map +1 -0
- package/dist/client/index.d.ts +8 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +15 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/models/types.d.ts +12 -0
- package/dist/client/models/types.d.ts.map +1 -0
- package/dist/client/models/types.js +3 -0
- package/dist/client/models/types.js.map +1 -0
- package/dist/client/utils/connection.d.ts +17 -0
- package/dist/client/utils/connection.d.ts.map +1 -0
- package/dist/client/utils/connection.js +71 -0
- package/dist/client/utils/connection.js.map +1 -0
- package/dist/client/utils/moduleRunner.d.ts +13 -0
- package/dist/client/utils/moduleRunner.d.ts.map +1 -0
- package/dist/client/utils/moduleRunner.js +59 -0
- package/dist/client/utils/moduleRunner.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/alert/alert.d.ts +3 -0
- package/dist/modules/alert/alert.d.ts.map +1 -0
- package/dist/modules/alert/alert.js +50 -0
- package/dist/modules/alert/alert.js.map +1 -0
- package/dist/modules/alert/index.d.ts +2 -0
- package/dist/modules/alert/index.d.ts.map +1 -0
- package/dist/modules/alert/index.js +6 -0
- package/dist/modules/alert/index.js.map +1 -0
- package/dist/modules/components/components.d.ts +8 -0
- package/dist/modules/components/components.d.ts.map +1 -0
- package/dist/modules/components/components.js +315 -0
- package/dist/modules/components/components.js.map +1 -0
- package/dist/modules/components/index.d.ts +3 -0
- package/dist/modules/components/index.d.ts.map +1 -0
- package/dist/modules/components/index.js +6 -0
- package/dist/modules/components/index.js.map +1 -0
- package/dist/modules/components/types.d.ts +18 -0
- package/dist/modules/components/types.d.ts.map +1 -0
- package/dist/modules/components/types.js +3 -0
- package/dist/modules/components/types.js.map +1 -0
- package/dist/modules/components/utils.d.ts +18 -0
- package/dist/modules/components/utils.d.ts.map +1 -0
- package/dist/modules/components/utils.js +386 -0
- package/dist/modules/components/utils.js.map +1 -0
- package/dist/modules/console/console.d.ts +4 -0
- package/dist/modules/console/console.d.ts.map +1 -0
- package/dist/modules/console/console.js +176 -0
- package/dist/modules/console/console.js.map +1 -0
- package/dist/modules/console/index.d.ts +3 -0
- package/dist/modules/console/index.d.ts.map +1 -0
- package/dist/modules/console/index.js +6 -0
- package/dist/modules/console/index.js.map +1 -0
- package/dist/modules/console/types.d.ts +13 -0
- package/dist/modules/console/types.d.ts.map +1 -0
- package/dist/modules/console/types.js +3 -0
- package/dist/modules/console/types.js.map +1 -0
- package/dist/modules/device/device.d.ts +3 -0
- package/dist/modules/device/device.d.ts.map +1 -0
- package/dist/modules/device/device.js +182 -0
- package/dist/modules/device/device.js.map +1 -0
- package/dist/modules/device/index.d.ts +3 -0
- package/dist/modules/device/index.d.ts.map +1 -0
- package/dist/modules/device/index.js +6 -0
- package/dist/modules/device/index.js.map +1 -0
- package/dist/modules/device/types.d.ts +24 -0
- package/dist/modules/device/types.d.ts.map +1 -0
- package/dist/modules/device/types.js +3 -0
- package/dist/modules/device/types.js.map +1 -0
- package/dist/modules/errors/errors.d.ts +4 -0
- package/dist/modules/errors/errors.d.ts.map +1 -0
- package/dist/modules/errors/errors.js +133 -0
- package/dist/modules/errors/errors.js.map +1 -0
- package/dist/modules/errors/index.d.ts +3 -0
- package/dist/modules/errors/index.d.ts.map +1 -0
- package/dist/modules/errors/index.js +6 -0
- package/dist/modules/errors/index.js.map +1 -0
- package/dist/modules/errors/types.d.ts +12 -0
- package/dist/modules/errors/types.d.ts.map +1 -0
- package/dist/modules/errors/types.js +3 -0
- package/dist/modules/errors/types.js.map +1 -0
- package/dist/modules/fiberTree/fiberTree.d.ts +8 -0
- package/dist/modules/fiberTree/fiberTree.d.ts.map +1 -0
- package/dist/modules/fiberTree/fiberTree.js +337 -0
- package/dist/modules/fiberTree/fiberTree.js.map +1 -0
- package/dist/modules/fiberTree/index.d.ts +3 -0
- package/dist/modules/fiberTree/index.d.ts.map +1 -0
- package/dist/modules/fiberTree/index.js +6 -0
- package/dist/modules/fiberTree/index.js.map +1 -0
- package/dist/modules/fiberTree/types.d.ts +18 -0
- package/dist/modules/fiberTree/types.d.ts.map +1 -0
- package/dist/modules/fiberTree/types.js +3 -0
- package/dist/modules/fiberTree/types.js.map +1 -0
- package/dist/modules/fiberTree/utils.d.ts +18 -0
- package/dist/modules/fiberTree/utils.d.ts.map +1 -0
- package/dist/modules/fiberTree/utils.js +386 -0
- package/dist/modules/fiberTree/utils.js.map +1 -0
- package/dist/modules/i18next/i18next.d.ts +4 -0
- package/dist/modules/i18next/i18next.d.ts.map +1 -0
- package/dist/modules/i18next/i18next.js +133 -0
- package/dist/modules/i18next/i18next.js.map +1 -0
- package/dist/modules/i18next/index.d.ts +3 -0
- package/dist/modules/i18next/index.d.ts.map +1 -0
- package/dist/modules/i18next/index.js +6 -0
- package/dist/modules/i18next/index.js.map +1 -0
- package/dist/modules/i18next/types.d.ts +12 -0
- package/dist/modules/i18next/types.d.ts.map +1 -0
- package/dist/modules/i18next/types.js +3 -0
- package/dist/modules/i18next/types.js.map +1 -0
- package/dist/modules/index.d.ts +12 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/index.js +26 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/navigation/index.d.ts +3 -0
- package/dist/modules/navigation/index.d.ts.map +1 -0
- package/dist/modules/navigation/index.js +6 -0
- package/dist/modules/navigation/index.js.map +1 -0
- package/dist/modules/navigation/navigation.d.ts +4 -0
- package/dist/modules/navigation/navigation.d.ts.map +1 -0
- package/dist/modules/navigation/navigation.js +240 -0
- package/dist/modules/navigation/navigation.js.map +1 -0
- package/dist/modules/navigation/types.d.ts +34 -0
- package/dist/modules/navigation/types.d.ts.map +1 -0
- package/dist/modules/navigation/types.js +3 -0
- package/dist/modules/navigation/types.js.map +1 -0
- package/dist/modules/network/index.d.ts +3 -0
- package/dist/modules/network/index.d.ts.map +1 -0
- package/dist/modules/network/index.js +6 -0
- package/dist/modules/network/index.js.map +1 -0
- package/dist/modules/network/network.d.ts +4 -0
- package/dist/modules/network/network.d.ts.map +1 -0
- package/dist/modules/network/network.js +276 -0
- package/dist/modules/network/network.js.map +1 -0
- package/dist/modules/network/types.d.ts +26 -0
- package/dist/modules/network/types.d.ts.map +1 -0
- package/dist/modules/network/types.js +3 -0
- package/dist/modules/network/types.js.map +1 -0
- package/dist/modules/reactQuery/index.d.ts +3 -0
- package/dist/modules/reactQuery/index.d.ts.map +1 -0
- package/dist/modules/reactQuery/index.js +6 -0
- package/dist/modules/reactQuery/index.js.map +1 -0
- package/dist/modules/reactQuery/reactQuery.d.ts +4 -0
- package/dist/modules/reactQuery/reactQuery.d.ts.map +1 -0
- package/dist/modules/reactQuery/reactQuery.js +160 -0
- package/dist/modules/reactQuery/reactQuery.js.map +1 -0
- package/dist/modules/reactQuery/types.d.ts +29 -0
- package/dist/modules/reactQuery/types.d.ts.map +1 -0
- package/dist/modules/reactQuery/types.js +3 -0
- package/dist/modules/reactQuery/types.js.map +1 -0
- package/dist/modules/screenshot/index.d.ts +3 -0
- package/dist/modules/screenshot/index.d.ts.map +1 -0
- package/dist/modules/screenshot/index.js +6 -0
- package/dist/modules/screenshot/index.js.map +1 -0
- package/dist/modules/screenshot/screenshot.d.ts +4 -0
- package/dist/modules/screenshot/screenshot.d.ts.map +1 -0
- package/dist/modules/screenshot/screenshot.js +89 -0
- package/dist/modules/screenshot/screenshot.js.map +1 -0
- package/dist/modules/screenshot/types.d.ts +5 -0
- package/dist/modules/screenshot/types.d.ts.map +1 -0
- package/dist/modules/screenshot/types.js +3 -0
- package/dist/modules/screenshot/types.js.map +1 -0
- package/dist/modules/storage/index.d.ts +3 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +6 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/storage.d.ts +4 -0
- package/dist/modules/storage/storage.d.ts.map +1 -0
- package/dist/modules/storage/storage.js +124 -0
- package/dist/modules/storage/storage.js.map +1 -0
- package/dist/modules/storage/types.d.ts +11 -0
- package/dist/modules/storage/types.d.ts.map +1 -0
- package/dist/modules/storage/types.js +3 -0
- package/dist/modules/storage/types.js.map +1 -0
- package/dist/modules/tree/index.d.ts +2 -0
- package/dist/modules/tree/index.d.ts.map +1 -0
- package/dist/modules/tree/index.js +6 -0
- package/dist/modules/tree/index.js.map +1 -0
- package/dist/modules/tree/tree.d.ts +3 -0
- package/dist/modules/tree/tree.d.ts.map +1 -0
- package/dist/modules/tree/tree.js +274 -0
- package/dist/modules/tree/tree.js.map +1 -0
- package/dist/server/bridge.d.ts +24 -0
- package/dist/server/bridge.d.ts.map +1 -0
- package/dist/server/bridge.js +152 -0
- package/dist/server/bridge.js.map +1 -0
- package/dist/server/cli.d.ts +3 -0
- package/dist/server/cli.d.ts.map +1 -0
- package/dist/server/cli.js +17 -0
- package/dist/server/cli.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +30 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/mcpServer.d.ts +19 -0
- package/dist/server/mcpServer.d.ts.map +1 -0
- package/dist/server/mcpServer.js +303 -0
- package/dist/server/mcpServer.js.map +1 -0
- package/dist/server/types.d.ts +12 -0
- package/dist/server/types.d.ts.map +1 -0
- package/dist/server/types.js +3 -0
- package/dist/server/types.js.map +1 -0
- package/dist/shared/protocol.d.ts +54 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +8 -0
- package/dist/shared/protocol.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpServerWrapper = void 0;
|
|
4
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
5
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
const zod_1 = require("zod");
|
|
7
|
+
const protocol_1 = require("../shared/protocol");
|
|
8
|
+
const BASE_INSTRUCTIONS = `You are connected to a running React Native app via the react-native-mcp-kit bridge.
|
|
9
|
+
|
|
10
|
+
## How to interact
|
|
11
|
+
|
|
12
|
+
1. Use \`connection_status\` to check if the app is connected
|
|
13
|
+
2. Use \`list_tools\` to see all available tools with descriptions and examples
|
|
14
|
+
3. Use \`call\` to invoke any tool with format: module${protocol_1.MODULE_SEPARATOR}method (e.g. navigation${protocol_1.MODULE_SEPARATOR}navigate)
|
|
15
|
+
4. Use \`state_list\` / \`state_get\` to read app state exposed by the developer
|
|
16
|
+
`;
|
|
17
|
+
class McpServerWrapper {
|
|
18
|
+
bridge;
|
|
19
|
+
dynamicTools = new Map();
|
|
20
|
+
mcp;
|
|
21
|
+
modules = [];
|
|
22
|
+
stateStore = new Map();
|
|
23
|
+
constructor(bridge) {
|
|
24
|
+
this.bridge = bridge;
|
|
25
|
+
this.mcp = new mcp_js_1.McpServer({ name: 'react-native-mcp-kit', version: '1.0.0' }, { instructions: BASE_INSTRUCTIONS });
|
|
26
|
+
this.registerTools();
|
|
27
|
+
}
|
|
28
|
+
addDynamicTool(module, name, description) {
|
|
29
|
+
this.dynamicTools.set(`${module}${protocol_1.MODULE_SEPARATOR}${name}`, { description, module });
|
|
30
|
+
}
|
|
31
|
+
removeDynamicTool(module, name) {
|
|
32
|
+
this.dynamicTools.delete(`${module}${protocol_1.MODULE_SEPARATOR}${name}`);
|
|
33
|
+
}
|
|
34
|
+
setModules(modules) {
|
|
35
|
+
this.modules = modules;
|
|
36
|
+
}
|
|
37
|
+
setState(key, value) {
|
|
38
|
+
this.stateStore.set(key, value);
|
|
39
|
+
}
|
|
40
|
+
removeState(key) {
|
|
41
|
+
this.stateStore.delete(key);
|
|
42
|
+
}
|
|
43
|
+
async start() {
|
|
44
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
45
|
+
await this.mcp.connect(transport);
|
|
46
|
+
}
|
|
47
|
+
registerTools() {
|
|
48
|
+
this.mcp.registerTool('call', {
|
|
49
|
+
annotations: {
|
|
50
|
+
openWorldHint: true,
|
|
51
|
+
title: 'Call Tool',
|
|
52
|
+
},
|
|
53
|
+
description: 'Call a tool registered by the React Native app. Use list_tools first to see available tools.',
|
|
54
|
+
inputSchema: {
|
|
55
|
+
args: zod_1.z
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe('Arguments as JSON string (e.g. {"screen": "AUTH_LOGIN_SCREEN"})'),
|
|
59
|
+
tool: zod_1.z
|
|
60
|
+
.string()
|
|
61
|
+
.describe(`Tool name in format "module${protocol_1.MODULE_SEPARATOR}method" (e.g. "navigation${protocol_1.MODULE_SEPARATOR}navigate")`),
|
|
62
|
+
},
|
|
63
|
+
}, async ({ args, tool }) => {
|
|
64
|
+
if (!this.bridge.isClientConnected()) {
|
|
65
|
+
return {
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
text: JSON.stringify({ error: 'React Native app is not connected' }),
|
|
69
|
+
type: 'text',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
// Find the module by matching prefix
|
|
75
|
+
let mod;
|
|
76
|
+
let moduleName = '';
|
|
77
|
+
let methodName = '';
|
|
78
|
+
for (const m of this.modules) {
|
|
79
|
+
const prefix = `${m.name}${protocol_1.MODULE_SEPARATOR}`;
|
|
80
|
+
if (tool.startsWith(prefix)) {
|
|
81
|
+
mod = m;
|
|
82
|
+
moduleName = m.name;
|
|
83
|
+
methodName = tool.slice(prefix.length);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// If no module matched, check for dynamic tool prefix
|
|
88
|
+
if (!mod) {
|
|
89
|
+
if (tool.startsWith(protocol_1.DYNAMIC_PREFIX)) {
|
|
90
|
+
moduleName = `${protocol_1.MODULE_SEPARATOR}dynamic`;
|
|
91
|
+
methodName = tool.slice(protocol_1.DYNAMIC_PREFIX.length);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const idx = tool.indexOf(protocol_1.MODULE_SEPARATOR);
|
|
95
|
+
if (idx <= 0) {
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
text: JSON.stringify({
|
|
100
|
+
error: `Invalid tool name "${tool}". Use "module${protocol_1.MODULE_SEPARATOR}method" format.`,
|
|
101
|
+
}),
|
|
102
|
+
type: 'text',
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
moduleName = tool.slice(0, idx);
|
|
108
|
+
methodName = tool.slice(idx + protocol_1.MODULE_SEPARATOR.length);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
let parsedArgs = {};
|
|
112
|
+
if (args) {
|
|
113
|
+
try {
|
|
114
|
+
parsedArgs = JSON.parse(args);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return {
|
|
118
|
+
content: [
|
|
119
|
+
{ text: JSON.stringify({ error: 'Invalid JSON in args' }), type: 'text' },
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!mod) {
|
|
125
|
+
// No module matched — try as dynamic tool via bridge
|
|
126
|
+
try {
|
|
127
|
+
const result = await this.bridge.call(moduleName, methodName, parsedArgs);
|
|
128
|
+
return { content: this.formatResult(result) };
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
const allModules = this.modules
|
|
132
|
+
.map((m) => {
|
|
133
|
+
return m.name;
|
|
134
|
+
})
|
|
135
|
+
.join(', ');
|
|
136
|
+
const dynNames = [...this.dynamicTools.keys()].join(', ');
|
|
137
|
+
return {
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
text: JSON.stringify({
|
|
141
|
+
error: `Tool "${tool}" not found. Modules: ${allModules}. Dynamic: ${dynNames || 'none'}`,
|
|
142
|
+
}),
|
|
143
|
+
type: 'text',
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const toolDef = mod.tools.find((t) => {
|
|
150
|
+
return t.name === methodName;
|
|
151
|
+
});
|
|
152
|
+
if (!toolDef) {
|
|
153
|
+
return {
|
|
154
|
+
content: [
|
|
155
|
+
{
|
|
156
|
+
text: JSON.stringify({
|
|
157
|
+
error: `Tool "${methodName}" not found in module "${moduleName}". Available: ${mod.tools
|
|
158
|
+
.map((t) => {
|
|
159
|
+
return t.name;
|
|
160
|
+
})
|
|
161
|
+
.join(', ')}`,
|
|
162
|
+
}),
|
|
163
|
+
type: 'text',
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const result = await this.bridge.call(moduleName, methodName, parsedArgs, toolDef.timeout);
|
|
169
|
+
return { content: this.formatResult(result) };
|
|
170
|
+
});
|
|
171
|
+
this.mcp.registerTool('list_tools', {
|
|
172
|
+
annotations: {
|
|
173
|
+
readOnlyHint: true,
|
|
174
|
+
title: 'List Tools',
|
|
175
|
+
},
|
|
176
|
+
description: 'List all tools registered by the React Native app, grouped by module',
|
|
177
|
+
}, async () => {
|
|
178
|
+
if (!this.bridge.isClientConnected()) {
|
|
179
|
+
return {
|
|
180
|
+
content: [
|
|
181
|
+
{
|
|
182
|
+
text: JSON.stringify({
|
|
183
|
+
connected: false,
|
|
184
|
+
error: 'React Native app is not connected',
|
|
185
|
+
}),
|
|
186
|
+
type: 'text',
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const moduleTools = this.modules.map((mod) => {
|
|
192
|
+
return {
|
|
193
|
+
description: mod.description,
|
|
194
|
+
module: mod.name,
|
|
195
|
+
tools: mod.tools.map((t) => {
|
|
196
|
+
return {
|
|
197
|
+
description: t.description,
|
|
198
|
+
inputSchema: t.inputSchema,
|
|
199
|
+
name: `${mod.name}${protocol_1.MODULE_SEPARATOR}${t.name}`,
|
|
200
|
+
};
|
|
201
|
+
}),
|
|
202
|
+
};
|
|
203
|
+
});
|
|
204
|
+
// Add dynamic tools (from useMcpTool hooks)
|
|
205
|
+
if (this.dynamicTools.size > 0) {
|
|
206
|
+
const dynamicByModule = new Map();
|
|
207
|
+
for (const [fullName, info] of this.dynamicTools) {
|
|
208
|
+
const existing = dynamicByModule.get(info.module) ?? [];
|
|
209
|
+
existing.push({
|
|
210
|
+
description: info.description,
|
|
211
|
+
inputSchema: undefined,
|
|
212
|
+
name: fullName,
|
|
213
|
+
});
|
|
214
|
+
dynamicByModule.set(info.module, existing);
|
|
215
|
+
}
|
|
216
|
+
for (const [module, dynTools] of dynamicByModule) {
|
|
217
|
+
moduleTools.push({
|
|
218
|
+
description: 'Dynamically registered tools from useMcpTool hooks',
|
|
219
|
+
module: `${module} (dynamic)`,
|
|
220
|
+
tools: dynTools,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
content: [{ text: JSON.stringify(moduleTools, null, 2), type: 'text' }],
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
this.mcp.registerTool('connection_status', {
|
|
229
|
+
annotations: {
|
|
230
|
+
readOnlyHint: true,
|
|
231
|
+
title: 'Connection Status',
|
|
232
|
+
},
|
|
233
|
+
description: 'Check if the React Native app is connected',
|
|
234
|
+
}, async () => {
|
|
235
|
+
return {
|
|
236
|
+
content: [
|
|
237
|
+
{
|
|
238
|
+
text: JSON.stringify({
|
|
239
|
+
connected: this.bridge.isClientConnected(),
|
|
240
|
+
modules: this.modules.map((m) => {
|
|
241
|
+
return m.name;
|
|
242
|
+
}),
|
|
243
|
+
}),
|
|
244
|
+
type: 'text',
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
};
|
|
248
|
+
});
|
|
249
|
+
this.mcp.registerTool('state_get', {
|
|
250
|
+
annotations: {
|
|
251
|
+
readOnlyHint: true,
|
|
252
|
+
title: 'Get State',
|
|
253
|
+
},
|
|
254
|
+
description: 'Read a state value exposed by the React Native app via useMcpState',
|
|
255
|
+
inputSchema: {
|
|
256
|
+
key: zod_1.z.string().describe('State key to read (e.g. "cart", "auth")'),
|
|
257
|
+
},
|
|
258
|
+
}, async ({ key }) => {
|
|
259
|
+
const value = this.stateStore.get(key);
|
|
260
|
+
if (value === undefined) {
|
|
261
|
+
return {
|
|
262
|
+
content: [
|
|
263
|
+
{
|
|
264
|
+
text: JSON.stringify({
|
|
265
|
+
error: `State "${key}" not found. Use state_list to see available keys.`,
|
|
266
|
+
}),
|
|
267
|
+
type: 'text',
|
|
268
|
+
},
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
content: [{ text: JSON.stringify(value, null, 2), type: 'text' }],
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
this.mcp.registerTool('state_list', {
|
|
277
|
+
annotations: {
|
|
278
|
+
readOnlyHint: true,
|
|
279
|
+
title: 'List State',
|
|
280
|
+
},
|
|
281
|
+
description: 'List all available state keys exposed by the React Native app',
|
|
282
|
+
}, async () => {
|
|
283
|
+
const keys = Array.from(this.stateStore.keys());
|
|
284
|
+
return {
|
|
285
|
+
content: [{ text: JSON.stringify({ keys }, null, 2), type: 'text' }],
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
formatResult(result) {
|
|
290
|
+
if (Array.isArray(result) && result.length > 0) {
|
|
291
|
+
const first = result[0];
|
|
292
|
+
if (typeof first === 'object' &&
|
|
293
|
+
first !== null &&
|
|
294
|
+
'type' in first &&
|
|
295
|
+
first.type === 'image') {
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return [{ text: JSON.stringify(result, null, 2), type: 'text' }];
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.McpServerWrapper = McpServerWrapper;
|
|
303
|
+
//# sourceMappingURL=mcpServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpServer.js","sourceRoot":"","sources":["../../src/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,YAAY,CACnB,YAAY,EACZ;YACE,WAAW,EAAE;gBACX,YAAY,EAAE,IAAI;gBAClB,KAAK,EAAE,YAAY;aACpB;YACD,WAAW,EAAE,+DAA+D;SAC7E,EACD,KAAK,IAAI,EAAE;YACT,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;YAChD,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,CAAC;aAC9E,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAEO,YAAY,CAAC,MAAe;QAClC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACxB,IACE,OAAO,KAAK,KAAK,QAAQ;gBACzB,KAAK,KAAK,IAAI;gBACd,MAAM,IAAI,KAAK;gBACf,KAAK,CAAC,IAAI,KAAK,OAAO,EACtB,CAAC;gBACD,OAAO,MAAkE,CAAC;YAC5E,CAAC;QACH,CAAC;QAED,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,CAAC,CAAC;IAC5E,CAAC;CACF;AA9UD,4CA8UC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ModuleDescriptor, type ModuleToolDescriptor } from '../shared/protocol';
|
|
2
|
+
export interface BridgeEvents {
|
|
3
|
+
onRegistration: (modules: ModuleDescriptor[]) => void;
|
|
4
|
+
onStateRemove: (key: string) => void;
|
|
5
|
+
onStateUpdate: (key: string, value: unknown) => void;
|
|
6
|
+
onToolRegister: (module: string, tool: ModuleToolDescriptor) => void;
|
|
7
|
+
onToolUnregister: (module: string, toolName: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface ServerConfig {
|
|
10
|
+
port?: number;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAErF,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,IAAI,CAAC;IACtD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACrD,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACrE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/server/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Separator between module name and tool name in MCP call format */
|
|
2
|
+
export declare const MODULE_SEPARATOR = "__";
|
|
3
|
+
/** Prefix for dynamic tools registered via useMcpTool */
|
|
4
|
+
export declare const DYNAMIC_PREFIX = "__dynamic__";
|
|
5
|
+
export interface ModuleToolDescriptor {
|
|
6
|
+
description: string;
|
|
7
|
+
name: string;
|
|
8
|
+
inputSchema?: Record<string, unknown>;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ModuleDescriptor {
|
|
12
|
+
name: string;
|
|
13
|
+
tools: ModuleToolDescriptor[];
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface RegistrationMessage {
|
|
17
|
+
modules: ModuleDescriptor[];
|
|
18
|
+
type: 'registration';
|
|
19
|
+
}
|
|
20
|
+
export interface ToolRequest {
|
|
21
|
+
args: Record<string, unknown>;
|
|
22
|
+
id: string;
|
|
23
|
+
method: string;
|
|
24
|
+
module: string;
|
|
25
|
+
type: 'tool_request';
|
|
26
|
+
}
|
|
27
|
+
export interface ToolResponse {
|
|
28
|
+
id: string;
|
|
29
|
+
type: 'tool_response';
|
|
30
|
+
error?: string;
|
|
31
|
+
result?: unknown;
|
|
32
|
+
}
|
|
33
|
+
export interface StateUpdateMessage {
|
|
34
|
+
key: string;
|
|
35
|
+
type: 'state_update';
|
|
36
|
+
value: unknown;
|
|
37
|
+
}
|
|
38
|
+
export interface StateRemoveMessage {
|
|
39
|
+
key: string;
|
|
40
|
+
type: 'state_remove';
|
|
41
|
+
}
|
|
42
|
+
export interface ToolRegisterMessage {
|
|
43
|
+
module: string;
|
|
44
|
+
tool: ModuleToolDescriptor;
|
|
45
|
+
type: 'tool_register';
|
|
46
|
+
}
|
|
47
|
+
export interface ToolUnregisterMessage {
|
|
48
|
+
module: string;
|
|
49
|
+
toolName: string;
|
|
50
|
+
type: 'tool_unregister';
|
|
51
|
+
}
|
|
52
|
+
export type ClientMessage = RegistrationMessage | StateRemoveMessage | StateUpdateMessage | ToolRegisterMessage | ToolResponse | ToolUnregisterMessage;
|
|
53
|
+
export type ServerMessage = ToolRequest;
|
|
54
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/shared/protocol.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,eAAO,MAA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BAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAID,MAAM,MAAM,aAAa,GACrB,mBAAmB,GACnB,kBAAkB,GAClB,kBAAkB,GAClB,mBAAmB,GACnB,YAAY,GACZ,qBAAqB,CAAC;AAE1B,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DYNAMIC_PREFIX = exports.MODULE_SEPARATOR = void 0;
|
|
4
|
+
/** Separator between module name and tool name in MCP call format */
|
|
5
|
+
exports.MODULE_SEPARATOR = '__';
|
|
6
|
+
/** Prefix for dynamic tools registered via useMcpTool */
|
|
7
|
+
exports.DYNAMIC_PREFIX = `${exports.MODULE_SEPARATOR}dynamic${exports.MODULE_SEPARATOR}`;
|
|
8
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/shared/protocol.ts"],"names":[],"mappings":";;;AAAA,qEAAqE;AACxD,QAAA,gBAAgB,GAAG,IAAI,CAAC;AAErC,yDAAyD;AAC5C,QAAA,cAAc,GAAG,GAAG,wBAAgB,UAAU,wBAAgB,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-mcp-kit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Bidirectional MCP bridge connecting AI agents to running React Native apps",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Aliaksei Pranko",
|
|
7
|
+
"homepage": "https://github.com/pranko17/react-native-mcp-kit#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/pranko17/react-native-mcp-kit.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ai",
|
|
14
|
+
"ai-testing",
|
|
15
|
+
"agent",
|
|
16
|
+
"automation",
|
|
17
|
+
"claude",
|
|
18
|
+
"debugging",
|
|
19
|
+
"devtools",
|
|
20
|
+
"fiber",
|
|
21
|
+
"inspection",
|
|
22
|
+
"mcp",
|
|
23
|
+
"model-context-protocol",
|
|
24
|
+
"react-native",
|
|
25
|
+
"rn",
|
|
26
|
+
"screenshot",
|
|
27
|
+
"testing"
|
|
28
|
+
],
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"main": "dist/index.js",
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"bin": {
|
|
37
|
+
"react-native-mcp-kit": "dist/server/cli.js"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
".": "./dist/index.js",
|
|
41
|
+
"./client": "./dist/client/index.js",
|
|
42
|
+
"./modules": "./dist/modules/index.js",
|
|
43
|
+
"./babel": "./dist/babel/index.js",
|
|
44
|
+
"./babel/test-id-plugin": "./dist/babel/testIdPlugin.js",
|
|
45
|
+
"./babel/strip-plugin": "./dist/babel/stripPlugin.js",
|
|
46
|
+
"./server": "./dist/server/index.js"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc && tsc-alias",
|
|
50
|
+
"dev": "tsc --watch",
|
|
51
|
+
"lint": "eslint --ext .ts --ext .tsx ./src",
|
|
52
|
+
"lint:fix": "eslint --ext .ts --ext .tsx ./src --fix",
|
|
53
|
+
"lint:ts": "tsc --noEmit"
|
|
54
|
+
},
|
|
55
|
+
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610",
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@babel/core": "^7.29.0",
|
|
58
|
+
"@types/babel__core": "^7.20.5",
|
|
59
|
+
"@types/node": "^25.5.2",
|
|
60
|
+
"@types/react": "^19.2.14",
|
|
61
|
+
"@types/ws": "^8.18.1",
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^8.48.0",
|
|
63
|
+
"@typescript-eslint/parser": "^8.48.0",
|
|
64
|
+
"eslint": "^8.57.0",
|
|
65
|
+
"eslint-config-prettier": "^10.1.8",
|
|
66
|
+
"eslint-import-resolver-alias": "^1.1.2",
|
|
67
|
+
"eslint-plugin-import": "^2.32.0",
|
|
68
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
69
|
+
"eslint-plugin-react": "^7.37.5",
|
|
70
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
71
|
+
"eslint-plugin-sort-destructure-keys": "^3.0.0",
|
|
72
|
+
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
73
|
+
"eslint-plugin-typescript-sort-keys": "^3.3.0",
|
|
74
|
+
"prettier": "^3.8.1",
|
|
75
|
+
"tsc-alias": "^1.8.16",
|
|
76
|
+
"typescript": "~5.7.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependencies": {
|
|
79
|
+
"@shopify/react-native-skia": ">=1.0",
|
|
80
|
+
"react": ">=19"
|
|
81
|
+
},
|
|
82
|
+
"peerDependenciesMeta": {
|
|
83
|
+
"@shopify/react-native-skia": {
|
|
84
|
+
"optional": true
|
|
85
|
+
},
|
|
86
|
+
"react": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"dependencies": {
|
|
91
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
92
|
+
"ws": "^8.20.0",
|
|
93
|
+
"zod": "^4.3.6"
|
|
94
|
+
}
|
|
95
|
+
}
|