@react-grab/mcp 0.1.29 → 0.1.30

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { startMcpServer } from \"./server.js\";\n\nstartMcpServer({\n port: Number(process.env.PORT) || undefined,\n stdio: process.argv.includes(\"--stdio\"),\n});\n"],"mappings":";;;AAGA,eAAe;CACb,MAAM,OAAO,QAAQ,IAAI,KAAK,IAAI,KAAA;CAClC,OAAO,QAAQ,KAAK,SAAS,UAAU;CACxC,CAAC"}
package/dist/client.cjs CHANGED
@@ -1,60 +1,62 @@
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
- });
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const HEALTH_CHECK_TIMEOUT_MS = 1e3;
3
+ //#endregion
4
+ //#region src/client.ts
5
+ const sendContextToServer = async (contextUrl, content, prompt) => {
6
+ await fetch(contextUrl, {
7
+ method: "POST",
8
+ headers: { "Content-Type": "application/json" },
9
+ body: JSON.stringify({
10
+ content,
11
+ prompt
12
+ })
13
+ }).catch(() => {});
14
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
- };
15
+ const createMcpPlugin = (options = {}) => {
16
+ const contextUrl = `http://localhost:${options.port ?? 4723}/context`;
17
+ return {
18
+ name: "mcp",
19
+ hooks: {
20
+ onCopySuccess: (_elements, content) => {
21
+ sendContextToServer(contextUrl, [content]);
22
+ },
23
+ transformAgentContext: async (context) => {
24
+ await sendContextToServer(contextUrl, context.content, context.prompt);
25
+ return context;
26
+ }
27
+ }
28
+ };
30
29
  };
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
- }
30
+ const isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
31
+ const MCP_REACHABLE_KEY = "react-grab-mcp-reachable";
32
+ const checkIfMcpServerIsReachable = async (port) => {
33
+ const cached = sessionStorage.getItem(MCP_REACHABLE_KEY);
34
+ if (cached !== null) return cached === "true";
35
+ const isReachable = await fetch(`http://localhost:${port}/health`, { signal: AbortSignal.timeout(HEALTH_CHECK_TIMEOUT_MS) }).then((response) => response.ok).catch(() => false);
36
+ sessionStorage.setItem(MCP_REACHABLE_KEY, String(isReachable));
37
+ return isReachable;
38
+ };
39
+ const attachMcpPlugin = async () => {
40
+ if (typeof window === "undefined") return;
41
+ if (!await checkIfMcpServerIsReachable(4723)) return;
42
+ const plugin = createMcpPlugin();
43
+ const attach = (api) => {
44
+ api.registerPlugin(plugin);
45
+ };
46
+ const existingApi = window.__REACT_GRAB__;
47
+ if (isReactGrabApi(existingApi)) {
48
+ attach(existingApi);
49
+ return;
50
+ }
51
+ window.addEventListener("react-grab:init", (event) => {
52
+ if (!(event instanceof CustomEvent)) return;
53
+ if (!isReactGrabApi(event.detail)) return;
54
+ attach(event.detail);
55
+ }, { once: true });
56
+ const apiAfterListener = window.__REACT_GRAB__;
57
+ if (isReactGrabApi(apiAfterListener)) attach(apiAfterListener);
56
58
  };
57
59
  attachMcpPlugin();
58
-
60
+ //#endregion
59
61
  exports.attachMcpPlugin = attachMcpPlugin;
60
62
  exports.createMcpPlugin = createMcpPlugin;
package/dist/client.d.cts CHANGED
@@ -1,14 +1,16 @@
1
- import { init, Plugin } from 'react-grab/core';
1
+ import { Plugin, init } from "react-grab/core";
2
2
 
3
+ //#region src/client.d.ts
3
4
  interface McpPluginOptions {
4
- port?: number;
5
+ port?: number;
5
6
  }
6
7
  declare const createMcpPlugin: (options?: McpPluginOptions) => Plugin;
7
8
  declare global {
8
- interface Window {
9
- __REACT_GRAB__?: ReturnType<typeof init>;
10
- }
9
+ interface Window {
10
+ __REACT_GRAB__?: ReturnType<typeof init>;
11
+ }
11
12
  }
12
- declare const attachMcpPlugin: () => void;
13
-
13
+ declare const attachMcpPlugin: () => Promise<void>;
14
+ //#endregion
14
15
  export { attachMcpPlugin, createMcpPlugin };
16
+ //# sourceMappingURL=client.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.cts","names":[],"sources":["../src/client.ts"],"mappings":";;;UAGU,gBAAA;EACR,IAAA;AAAA;AAAA,cAeW,eAAA,GAAmB,OAAA,GAAS,gBAAA,KAAwB,MAAA;AAAA,QAqBzD,MAAA;EAAA,UACI,MAAA;IACR,cAAA,GAAiB,UAAA,QAAkB,IAAA;EAAA;AAAA;AAAA,cAoB1B,eAAA,QAA4B,OAAA"}
package/dist/client.d.ts CHANGED
@@ -1,14 +1,16 @@
1
- import { init, Plugin } from 'react-grab/core';
1
+ import { Plugin, init } from "react-grab/core";
2
2
 
3
+ //#region src/client.d.ts
3
4
  interface McpPluginOptions {
4
- port?: number;
5
+ port?: number;
5
6
  }
6
7
  declare const createMcpPlugin: (options?: McpPluginOptions) => Plugin;
7
8
  declare global {
8
- interface Window {
9
- __REACT_GRAB__?: ReturnType<typeof init>;
10
- }
9
+ interface Window {
10
+ __REACT_GRAB__?: ReturnType<typeof init>;
11
+ }
11
12
  }
12
- declare const attachMcpPlugin: () => void;
13
-
13
+ declare const attachMcpPlugin: () => Promise<void>;
14
+ //#endregion
14
15
  export { attachMcpPlugin, createMcpPlugin };
16
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;UAGU,gBAAA;EACR,IAAA;AAAA;AAAA,cAeW,eAAA,GAAmB,OAAA,GAAS,gBAAA,KAAwB,MAAA;AAAA,QAqBzD,MAAA;EAAA,UACI,MAAA;IACR,cAAA,GAAiB,UAAA,QAAkB,IAAA;EAAA;AAAA;AAAA,cAoB1B,eAAA,QAA4B,OAAA"}
@@ -1,2 +1 @@
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;})({});
1
+ var ReactGrabMcp=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=async(e,t,n)=>{await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:t,prompt:n})}).catch(()=>{})},n=(e={})=>{let n=`http://localhost:${e.port??4723}/context`;return{name:`mcp`,hooks:{onCopySuccess:(e,r)=>{t(n,[r])},transformAgentContext:async e=>(await t(n,e.content,e.prompt),e)}}},r=e=>typeof e==`object`&&!!e&&`registerPlugin`in e,i=`react-grab-mcp-reachable`,a=async e=>{let t=sessionStorage.getItem(i);if(t!==null)return t===`true`;let n=await fetch(`http://localhost:${e}/health`,{signal:AbortSignal.timeout(1e3)}).then(e=>e.ok).catch(()=>!1);return sessionStorage.setItem(i,String(n)),n},o=async()=>{if(typeof window>`u`||!await a(4723))return;let e=n(),t=t=>{t.registerPlugin(e)},i=window.__REACT_GRAB__;if(r(i)){t(i);return}window.addEventListener(`react-grab:init`,e=>{e instanceof CustomEvent&&r(e.detail)&&t(e.detail)},{once:!0});let o=window.__REACT_GRAB__;r(o)&&t(o)};return o(),e.attachMcpPlugin=o,e.createMcpPlugin=n,e})({});
@@ -0,0 +1 @@
1
+ var ReactGrabMcp=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=async(e,t,n)=>{await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({content:t,prompt:n})}).catch(()=>{})},n=(e={})=>{let n=`http://localhost:${e.port??4723}/context`;return{name:`mcp`,hooks:{onCopySuccess:(e,r)=>{t(n,[r])},transformAgentContext:async e=>(await t(n,e.content,e.prompt),e)}}},r=e=>typeof e==`object`&&!!e&&`registerPlugin`in e,i=`react-grab-mcp-reachable`,a=async e=>{let t=sessionStorage.getItem(i);if(t!==null)return t===`true`;let n=await fetch(`http://localhost:${e}/health`,{signal:AbortSignal.timeout(1e3)}).then(e=>e.ok).catch(()=>!1);return sessionStorage.setItem(i,String(n)),n},o=async()=>{if(typeof window>`u`||!await a(4723))return;let e=n(),t=t=>{t.registerPlugin(e)},i=window.__REACT_GRAB__;if(r(i)){t(i);return}window.addEventListener(`react-grab:init`,e=>{e instanceof CustomEvent&&r(e.detail)&&t(e.detail)},{once:!0});let o=window.__REACT_GRAB__;r(o)&&t(o)};return o(),e.attachMcpPlugin=o,e.createMcpPlugin=n,e})({});
package/dist/client.js CHANGED
@@ -1,57 +1,62 @@
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
- });
1
+ const HEALTH_CHECK_TIMEOUT_MS = 1e3;
2
+ //#endregion
3
+ //#region src/client.ts
4
+ const sendContextToServer = async (contextUrl, content, prompt) => {
5
+ await fetch(contextUrl, {
6
+ method: "POST",
7
+ headers: { "Content-Type": "application/json" },
8
+ body: JSON.stringify({
9
+ content,
10
+ prompt
11
+ })
12
+ }).catch(() => {});
13
+ };
14
+ const createMcpPlugin = (options = {}) => {
15
+ const contextUrl = `http://localhost:${options.port ?? 4723}/context`;
16
+ return {
17
+ name: "mcp",
18
+ hooks: {
19
+ onCopySuccess: (_elements, content) => {
20
+ sendContextToServer(contextUrl, [content]);
21
+ },
22
+ transformAgentContext: async (context) => {
23
+ await sendContextToServer(contextUrl, context.content, context.prompt);
24
+ return context;
25
+ }
26
+ }
27
+ };
12
28
  };
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
- };
29
+ const isReactGrabApi = (value) => typeof value === "object" && value !== null && "registerPlugin" in value;
30
+ const MCP_REACHABLE_KEY = "react-grab-mcp-reachable";
31
+ const checkIfMcpServerIsReachable = async (port) => {
32
+ const cached = sessionStorage.getItem(MCP_REACHABLE_KEY);
33
+ if (cached !== null) return cached === "true";
34
+ const isReachable = await fetch(`http://localhost:${port}/health`, { signal: AbortSignal.timeout(HEALTH_CHECK_TIMEOUT_MS) }).then((response) => response.ok).catch(() => false);
35
+ sessionStorage.setItem(MCP_REACHABLE_KEY, String(isReachable));
36
+ return isReachable;
28
37
  };
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
- }
38
+ const attachMcpPlugin = async () => {
39
+ if (typeof window === "undefined") return;
40
+ if (!await checkIfMcpServerIsReachable(4723)) return;
41
+ const plugin = createMcpPlugin();
42
+ const attach = (api) => {
43
+ api.registerPlugin(plugin);
44
+ };
45
+ const existingApi = window.__REACT_GRAB__;
46
+ if (isReactGrabApi(existingApi)) {
47
+ attach(existingApi);
48
+ return;
49
+ }
50
+ window.addEventListener("react-grab:init", (event) => {
51
+ if (!(event instanceof CustomEvent)) return;
52
+ if (!isReactGrabApi(event.detail)) return;
53
+ attach(event.detail);
54
+ }, { once: true });
55
+ const apiAfterListener = window.__REACT_GRAB__;
56
+ if (isReactGrabApi(apiAfterListener)) attach(apiAfterListener);
54
57
  };
55
58
  attachMcpPlugin();
56
-
59
+ //#endregion
57
60
  export { attachMcpPlugin, createMcpPlugin };
61
+
62
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","names":[],"sources":["../src/constants.ts","../src/client.ts"],"sourcesContent":["export const CONTEXT_TTL_MS = 5 * 60 * 1000;\nexport const DEFAULT_MCP_PORT = 4723;\nexport const HEALTH_CHECK_TIMEOUT_MS = 1000;\nexport const POST_KILL_DELAY_MS = 100;\n","import type { init, ReactGrabAPI, Plugin, AgentContext } from \"react-grab/core\";\nimport { DEFAULT_MCP_PORT, HEALTH_CHECK_TIMEOUT_MS } from \"./constants.js\";\n\ninterface McpPluginOptions {\n port?: number;\n}\n\nconst sendContextToServer = async (\n contextUrl: string,\n content: string[],\n prompt?: string,\n): Promise<void> => {\n await fetch(contextUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ content, prompt }),\n }).catch(() => {});\n};\n\nexport const createMcpPlugin = (options: McpPluginOptions = {}): Plugin => {\n const port = options.port ?? DEFAULT_MCP_PORT;\n const contextUrl = `http://localhost:${port}/context`;\n\n return {\n name: \"mcp\",\n hooks: {\n onCopySuccess: (_elements: Element[], content: string) => {\n void sendContextToServer(contextUrl, [content]);\n },\n transformAgentContext: async (context: AgentContext): Promise<AgentContext> => {\n await sendContextToServer(contextUrl, context.content, context.prompt);\n return context;\n },\n },\n };\n};\n\nconst isReactGrabApi = (value: unknown): value is ReactGrabAPI =>\n typeof value === \"object\" && value !== null && \"registerPlugin\" in value;\n\ndeclare global {\n interface Window {\n __REACT_GRAB__?: ReturnType<typeof init>;\n }\n}\n\nconst MCP_REACHABLE_KEY = \"react-grab-mcp-reachable\";\n\nconst checkIfMcpServerIsReachable = async (port: number): Promise<boolean> => {\n const cached = sessionStorage.getItem(MCP_REACHABLE_KEY);\n if (cached !== null) return cached === \"true\";\n\n const isReachable = await fetch(`http://localhost:${port}/health`, {\n signal: AbortSignal.timeout(HEALTH_CHECK_TIMEOUT_MS),\n })\n .then((response) => response.ok)\n .catch(() => false);\n\n sessionStorage.setItem(MCP_REACHABLE_KEY, String(isReachable));\n return isReachable;\n};\n\nexport const attachMcpPlugin = async (): Promise<void> => {\n if (typeof window === \"undefined\") return;\n\n const isReachable = await checkIfMcpServerIsReachable(DEFAULT_MCP_PORT);\n if (!isReachable) return;\n\n const plugin = createMcpPlugin();\n\n const attach = (api: ReactGrabAPI) => {\n api.registerPlugin(plugin);\n };\n\n const existingApi = window.__REACT_GRAB__;\n if (isReactGrabApi(existingApi)) {\n attach(existingApi);\n return;\n }\n\n window.addEventListener(\n \"react-grab:init\",\n (event: Event) => {\n if (!(event instanceof CustomEvent)) return;\n if (!isReactGrabApi(event.detail)) return;\n attach(event.detail);\n },\n { once: true },\n );\n\n // HACK: Check again after adding listener in case of race condition\n const apiAfterListener = window.__REACT_GRAB__;\n if (isReactGrabApi(apiAfterListener)) {\n attach(apiAfterListener);\n }\n};\n\nattachMcpPlugin();\n"],"mappings":"AAEA,MAAa,0BAA0B;;;ACKvC,MAAM,sBAAsB,OAC1B,YACA,SACA,WACkB;AAClB,OAAM,MAAM,YAAY;EACtB,QAAQ;EACR,SAAS,EAAE,gBAAgB,oBAAoB;EAC/C,MAAM,KAAK,UAAU;GAAE;GAAS;GAAQ,CAAC;EAC1C,CAAC,CAAC,YAAY,GAAG;;AAGpB,MAAa,mBAAmB,UAA4B,EAAE,KAAa;CAEzE,MAAM,aAAa,oBADN,QAAQ,QAAA,KACuB;AAE5C,QAAO;EACL,MAAM;EACN,OAAO;GACL,gBAAgB,WAAsB,YAAoB;AACnD,wBAAoB,YAAY,CAAC,QAAQ,CAAC;;GAEjD,uBAAuB,OAAO,YAAiD;AAC7E,UAAM,oBAAoB,YAAY,QAAQ,SAAS,QAAQ,OAAO;AACtE,WAAO;;GAEV;EACF;;AAGH,MAAM,kBAAkB,UACtB,OAAO,UAAU,YAAY,UAAU,QAAQ,oBAAoB;AAQrE,MAAM,oBAAoB;AAE1B,MAAM,8BAA8B,OAAO,SAAmC;CAC5E,MAAM,SAAS,eAAe,QAAQ,kBAAkB;AACxD,KAAI,WAAW,KAAM,QAAO,WAAW;CAEvC,MAAM,cAAc,MAAM,MAAM,oBAAoB,KAAK,UAAU,EACjE,QAAQ,YAAY,QAAQ,wBAAwB,EACrD,CAAC,CACC,MAAM,aAAa,SAAS,GAAG,CAC/B,YAAY,MAAM;AAErB,gBAAe,QAAQ,mBAAmB,OAAO,YAAY,CAAC;AAC9D,QAAO;;AAGT,MAAa,kBAAkB,YAA2B;AACxD,KAAI,OAAO,WAAW,YAAa;AAGnC,KAAI,CADgB,MAAM,4BAAA,KAA6C,CACrD;CAElB,MAAM,SAAS,iBAAiB;CAEhC,MAAM,UAAU,QAAsB;AACpC,MAAI,eAAe,OAAO;;CAG5B,MAAM,cAAc,OAAO;AAC3B,KAAI,eAAe,YAAY,EAAE;AAC/B,SAAO,YAAY;AACnB;;AAGF,QAAO,iBACL,oBACC,UAAiB;AAChB,MAAI,EAAE,iBAAiB,aAAc;AACrC,MAAI,CAAC,eAAe,MAAM,OAAO,CAAE;AACnC,SAAO,MAAM,OAAO;IAEtB,EAAE,MAAM,MAAM,CACf;CAGD,MAAM,mBAAmB,OAAO;AAChC,KAAI,eAAe,iBAAiB,CAClC,QAAO,iBAAiB;;AAI5B,iBAAiB"}