@react-grab/mcp 0.1.1
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/dist/cli.cjs +25585 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +25574 -0
- package/dist/client.cjs +60 -0
- package/dist/client.d.cts +14 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.global.js +2 -0
- package/dist/client.js +57 -0
- package/dist/server.cjs +25580 -0
- package/dist/server.d.cts +7 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +25569 -0
- package/package.json +40 -0
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/constants.ts
|
|
4
|
+
var DEFAULT_MCP_PORT = 4723;
|
|
5
|
+
|
|
6
|
+
// src/client.ts
|
|
7
|
+
var sendContextToServer = async (contextUrl, content, prompt) => {
|
|
8
|
+
await fetch(contextUrl, {
|
|
9
|
+
method: "POST",
|
|
10
|
+
headers: { "Content-Type": "application/json" },
|
|
11
|
+
body: JSON.stringify({ content, prompt })
|
|
12
|
+
}).catch(() => {
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var createMcpPlugin = (options = {}) => {
|
|
16
|
+
const port = options.port ?? DEFAULT_MCP_PORT;
|
|
17
|
+
const contextUrl = `http://localhost:${port}/context`;
|
|
18
|
+
return {
|
|
19
|
+
name: "mcp",
|
|
20
|
+
hooks: {
|
|
21
|
+
onCopySuccess: (_elements, content) => {
|
|
22
|
+
void sendContextToServer(contextUrl, [content]);
|
|
23
|
+
},
|
|
24
|
+
transformAgentContext: async (context) => {
|
|
25
|
+
await sendContextToServer(contextUrl, context.content, context.prompt);
|
|
26
|
+
return context;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
|
|
32
|
+
var attachMcpPlugin = () => {
|
|
33
|
+
if (typeof window === "undefined") return;
|
|
34
|
+
const plugin = createMcpPlugin();
|
|
35
|
+
const attach = (api) => {
|
|
36
|
+
api.registerPlugin(plugin);
|
|
37
|
+
};
|
|
38
|
+
const existingApi = window.__REACT_GRAB__;
|
|
39
|
+
if (isReactGrabApi(existingApi)) {
|
|
40
|
+
attach(existingApi);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
window.addEventListener(
|
|
44
|
+
"react-grab:init",
|
|
45
|
+
(event) => {
|
|
46
|
+
if (!(event instanceof CustomEvent)) return;
|
|
47
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
48
|
+
attach(event.detail);
|
|
49
|
+
},
|
|
50
|
+
{ once: true }
|
|
51
|
+
);
|
|
52
|
+
const apiAfterListener = window.__REACT_GRAB__;
|
|
53
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
54
|
+
attach(apiAfterListener);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
attachMcpPlugin();
|
|
58
|
+
|
|
59
|
+
exports.attachMcpPlugin = attachMcpPlugin;
|
|
60
|
+
exports.createMcpPlugin = createMcpPlugin;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { init, Plugin } from 'react-grab/core';
|
|
2
|
+
|
|
3
|
+
interface McpPluginOptions {
|
|
4
|
+
port?: number;
|
|
5
|
+
}
|
|
6
|
+
declare const createMcpPlugin: (options?: McpPluginOptions) => Plugin;
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
__REACT_GRAB__?: ReturnType<typeof init>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const attachMcpPlugin: () => void;
|
|
13
|
+
|
|
14
|
+
export { attachMcpPlugin, createMcpPlugin };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { init, Plugin } from 'react-grab/core';
|
|
2
|
+
|
|
3
|
+
interface McpPluginOptions {
|
|
4
|
+
port?: number;
|
|
5
|
+
}
|
|
6
|
+
declare const createMcpPlugin: (options?: McpPluginOptions) => Plugin;
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
__REACT_GRAB__?: ReturnType<typeof init>;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
declare const attachMcpPlugin: () => void;
|
|
13
|
+
|
|
14
|
+
export { attachMcpPlugin, createMcpPlugin };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var ReactGrabMcp=(function(exports){'use strict';var c=async(t,r,n)=>{await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({content:r,prompt:n})}).catch(()=>{});},a=(t={})=>{let n=`http://localhost:${t.port??4723}/context`;return {name:"mcp",hooks:{onCopySuccess:(e,o)=>{c(n,[o]);},transformAgentContext:async e=>(await c(n,e.content,e.prompt),e)}}},i=t=>typeof t=="object"&&t!==null&&"registerPlugin"in t,p=()=>{if(typeof window>"u")return;let t=a(),r=o=>{o.registerPlugin(t);},n=window.__REACT_GRAB__;if(i(n)){r(n);return}window.addEventListener("react-grab:init",o=>{o instanceof CustomEvent&&i(o.detail)&&r(o.detail);},{once:true});let e=window.__REACT_GRAB__;i(e)&&r(e);};p();
|
|
2
|
+
exports.attachMcpPlugin=p;exports.createMcpPlugin=a;return exports;})({});
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/constants.ts
|
|
2
|
+
var DEFAULT_MCP_PORT = 4723;
|
|
3
|
+
|
|
4
|
+
// src/client.ts
|
|
5
|
+
var sendContextToServer = async (contextUrl, content, prompt) => {
|
|
6
|
+
await fetch(contextUrl, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
headers: { "Content-Type": "application/json" },
|
|
9
|
+
body: JSON.stringify({ content, prompt })
|
|
10
|
+
}).catch(() => {
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var createMcpPlugin = (options = {}) => {
|
|
14
|
+
const port = options.port ?? DEFAULT_MCP_PORT;
|
|
15
|
+
const contextUrl = `http://localhost:${port}/context`;
|
|
16
|
+
return {
|
|
17
|
+
name: "mcp",
|
|
18
|
+
hooks: {
|
|
19
|
+
onCopySuccess: (_elements, content) => {
|
|
20
|
+
void sendContextToServer(contextUrl, [content]);
|
|
21
|
+
},
|
|
22
|
+
transformAgentContext: async (context) => {
|
|
23
|
+
await sendContextToServer(contextUrl, context.content, context.prompt);
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
|
|
30
|
+
var attachMcpPlugin = () => {
|
|
31
|
+
if (typeof window === "undefined") return;
|
|
32
|
+
const plugin = createMcpPlugin();
|
|
33
|
+
const attach = (api) => {
|
|
34
|
+
api.registerPlugin(plugin);
|
|
35
|
+
};
|
|
36
|
+
const existingApi = window.__REACT_GRAB__;
|
|
37
|
+
if (isReactGrabApi(existingApi)) {
|
|
38
|
+
attach(existingApi);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
window.addEventListener(
|
|
42
|
+
"react-grab:init",
|
|
43
|
+
(event) => {
|
|
44
|
+
if (!(event instanceof CustomEvent)) return;
|
|
45
|
+
if (!isReactGrabApi(event.detail)) return;
|
|
46
|
+
attach(event.detail);
|
|
47
|
+
},
|
|
48
|
+
{ once: true }
|
|
49
|
+
);
|
|
50
|
+
const apiAfterListener = window.__REACT_GRAB__;
|
|
51
|
+
if (isReactGrabApi(apiAfterListener)) {
|
|
52
|
+
attach(apiAfterListener);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
attachMcpPlugin();
|
|
56
|
+
|
|
57
|
+
export { attachMcpPlugin, createMcpPlugin };
|