@mcp-use/cli 3.1.0-canary.2 → 3.1.0-canary.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.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * CommonJS-side Next.js runtime-module shim.
3
+ *
4
+ * Node's ESM loader hooks (registered via `module.register()`) don't
5
+ * intercept CommonJS `require()` calls made by tsx's CJS transformer. tsx
6
+ * compiles TypeScript to CJS by default, so a transitive `import 'server-only'`
7
+ * inside a user tool becomes `require('server-only')` at runtime — which
8
+ * ends up loading the real module and throwing.
9
+ *
10
+ * This file patches `Module._resolveFilename` at require-time so that any
11
+ * CJS `require()` for one of the shimmed specifiers resolves to a sibling
12
+ * no-op module instead.
13
+ *
14
+ * Loaded via `node -r <path>` (or `NODE_OPTIONS=-r <path>`) before the user
15
+ * entry is evaluated. Paired with `next-shims-register.mjs` on the ESM side
16
+ * for belt-and-braces coverage.
17
+ */
18
+
19
+ const Module = require("node:module");
20
+ const path = require("node:path");
21
+
22
+ // Absolute path to the no-op CJS module that satisfies every shimmed specifier.
23
+ const noopPath = path.join(__dirname, "next-shims-noop.cjs");
24
+
25
+ // Single source of truth — see next-shims-registry.json. The loader.mjs reads
26
+ // the same file so ESM and CJS interception stay in lockstep.
27
+ const { shimmedModules } = require("./next-shims-registry.json");
28
+ const SHIMMED = new Set(shimmedModules);
29
+
30
+ const originalResolveFilename = Module._resolveFilename;
31
+
32
+ Module._resolveFilename = function patchedResolveFilename(
33
+ request,
34
+ parent,
35
+ isMain,
36
+ options
37
+ ) {
38
+ if (SHIMMED.has(request)) {
39
+ return noopPath;
40
+ }
41
+ return originalResolveFilename.call(this, request, parent, isMain, options);
42
+ };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Node.js ESM loader hook that resolves Next.js server-runtime modules to
3
+ * no-op implementations when the MCP server runs outside of Next.js.
4
+ *
5
+ * Registered by `next-shims-register.mjs` when the CLI detects `next` in the
6
+ * user's package.json. See cli/src/utils/next-shims.ts for the host wiring.
7
+ *
8
+ * The mapping covers modules that exist inside a Next.js runtime but have
9
+ * no meaningful behavior outside of it. Each shim is a data: URL so the
10
+ * loader has zero on-disk footprint.
11
+ *
12
+ * The list of specifiers we intercept lives in `next-shims-registry.json`
13
+ * so this file and `next-shims-cjs.cjs` can't drift out of sync. The
14
+ * per-module stub bodies (below) still live here because each one has its
15
+ * own export surface.
16
+ */
17
+
18
+ import registry from "./next-shims-registry.json" with { type: "json" };
19
+
20
+ const SHIMS = new Map([
21
+ // `import "server-only"` — throws hard at import time in the real package.
22
+ // In the MCP process there is no client/server boundary to enforce.
23
+ ["server-only", "data:text/javascript,export{};"],
24
+
25
+ // `import "client-only"` — symmetric case; also throws in its real form.
26
+ ["client-only", "data:text/javascript,export{};"],
27
+
28
+ // `import { revalidatePath, revalidateTag, unstable_cache } from "next/cache"`
29
+ // revalidate* are side-effect functions; unstable_cache wraps a function
30
+ // and returns a memoized version — here we return the original untouched.
31
+ [
32
+ "next/cache",
33
+ "data:text/javascript," +
34
+ encodeURIComponent(
35
+ "export function revalidatePath(){}" +
36
+ "export function revalidateTag(){}" +
37
+ "export function unstable_cache(fn){return fn}" +
38
+ "export function unstable_noStore(){}" +
39
+ "export const unstable_cacheLife = ()=>{};" +
40
+ "export const unstable_cacheTag = ()=>{};"
41
+ ),
42
+ ],
43
+
44
+ // `import { headers, cookies, draftMode } from "next/headers"`
45
+ // The real implementation requires an incoming RSC request context. For the
46
+ // MCP server we return inert stand-ins — most tools only read metadata and
47
+ // default to empty values when they're unavailable.
48
+ [
49
+ "next/headers",
50
+ "data:text/javascript," +
51
+ encodeURIComponent(
52
+ "export function headers(){return new Headers();}" +
53
+ "export function cookies(){return{get(){return undefined},getAll(){return []},has(){return false},set(){},delete(){}};}" +
54
+ "export function draftMode(){return{isEnabled:false,enable(){},disable(){}};}"
55
+ ),
56
+ ],
57
+
58
+ // `import { redirect, notFound } from "next/navigation"` — server-side
59
+ // helpers. redirect/notFound throw special errors in Next; we keep their
60
+ // throw semantics so callers fail loudly instead of silently continuing.
61
+ [
62
+ "next/navigation",
63
+ "data:text/javascript," +
64
+ encodeURIComponent(
65
+ "export function redirect(u){const e=new Error('redirect('+u+') called outside Next.js');e.digest='NEXT_REDIRECT;'+u;throw e;}" +
66
+ "export function permanentRedirect(u){return redirect(u);}" +
67
+ "export function notFound(){const e=new Error('notFound() called outside Next.js');e.digest='NEXT_NOT_FOUND';throw e;}" +
68
+ "export const RedirectType={push:'push',replace:'replace'};"
69
+ ),
70
+ ],
71
+
72
+ // `import { NextResponse, NextRequest } from "next/server"` — thin wrappers
73
+ // around Response/Request. The MCP server rarely needs them, but importing
74
+ // the real module pulls in a lot of Next internals. Provide minimal stubs.
75
+ [
76
+ "next/server",
77
+ "data:text/javascript," +
78
+ encodeURIComponent(
79
+ "export class NextResponse extends Response{static json(data,init){return new Response(JSON.stringify(data),{...init,headers:{...(init&&init.headers),'content-type':'application/json'}});}static redirect(url,status){return new Response(null,{status:status||302,headers:{location:String(url)}});}static next(){return new Response(null);}static rewrite(){return new Response(null);}}" +
80
+ "export class NextRequest extends Request{constructor(input,init){super(input,init);this.nextUrl=new URL(typeof input==='string'?input:input.url);this.cookies={get(){return undefined},getAll(){return []},has(){return false},set(){},delete(){}};}}" +
81
+ "export const userAgent=()=>({ua:'',browser:{},device:{},engine:{},os:{},cpu:{},isBot:false});"
82
+ ),
83
+ ],
84
+ ]);
85
+
86
+ // Sanity check: every entry in the registry must have a stub body in SHIMS,
87
+ // and every stub body must correspond to a registered specifier. Drift here
88
+ // means ESM imports succeed while CJS requires fall through (or vice versa),
89
+ // which is the exact invariant the registry exists to prevent.
90
+ {
91
+ const registered = new Set(registry.shimmedModules);
92
+ for (const key of SHIMS.keys()) {
93
+ if (!registered.has(key)) {
94
+ throw new Error(
95
+ `next-shims-loader: "${key}" has a stub body but is not in next-shims-registry.json`
96
+ );
97
+ }
98
+ }
99
+ for (const key of registered) {
100
+ if (!SHIMS.has(key)) {
101
+ throw new Error(
102
+ `next-shims-loader: "${key}" is in next-shims-registry.json but has no stub body in next-shims-loader.mjs`
103
+ );
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * @param {string} specifier
110
+ * @param {{conditions: string[], importAssertions: object, parentURL?: string}} context
111
+ * @param {(specifier: string, context: object) => Promise<{url: string, format?: string, shortCircuit?: boolean}>} nextResolve
112
+ */
113
+ export async function resolve(specifier, context, nextResolve) {
114
+ const shim = SHIMS.get(specifier);
115
+ if (shim) {
116
+ return { url: shim, shortCircuit: true, format: "module" };
117
+ }
118
+ return nextResolve(specifier, context);
119
+ }
@@ -0,0 +1,146 @@
1
+ /**
2
+ * No-op CommonJS module used by the CJS shim.
3
+ *
4
+ * `Module._resolveFilename` in `next-shims-cjs.cjs` redirects every shimmed
5
+ * specifier (`server-only`, `next/cache`, etc.) to this file. A single
6
+ * flexible module satisfies all of them because each caller only accesses
7
+ * the exports relevant to its specifier; anything it doesn't touch is
8
+ * harmless.
9
+ *
10
+ * Keep exports aligned with `next-shims-loader.mjs`.
11
+ */
12
+
13
+ "use strict";
14
+
15
+ // --- next/cache ------------------------------------------------------------
16
+ function revalidatePath() {}
17
+ function revalidateTag() {}
18
+ function unstable_cache(fn) {
19
+ return fn;
20
+ }
21
+ function unstable_noStore() {}
22
+ const unstable_cacheLife = () => {};
23
+ const unstable_cacheTag = () => {};
24
+
25
+ // --- next/headers ----------------------------------------------------------
26
+ function headers() {
27
+ return new Headers();
28
+ }
29
+ function cookies() {
30
+ return {
31
+ get() {
32
+ return undefined;
33
+ },
34
+ getAll() {
35
+ return [];
36
+ },
37
+ has() {
38
+ return false;
39
+ },
40
+ set() {},
41
+ delete() {},
42
+ };
43
+ }
44
+ function draftMode() {
45
+ return {
46
+ isEnabled: false,
47
+ enable() {},
48
+ disable() {},
49
+ };
50
+ }
51
+
52
+ // --- next/navigation -------------------------------------------------------
53
+ function redirect(url) {
54
+ const err = new Error(`redirect(${url}) called outside Next.js`);
55
+ err.digest = "NEXT_REDIRECT;" + url;
56
+ throw err;
57
+ }
58
+ function permanentRedirect(url) {
59
+ return redirect(url);
60
+ }
61
+ function notFound() {
62
+ const err = new Error("notFound() called outside Next.js");
63
+ err.digest = "NEXT_NOT_FOUND";
64
+ throw err;
65
+ }
66
+ const RedirectType = { push: "push", replace: "replace" };
67
+
68
+ // --- next/server -----------------------------------------------------------
69
+ class NextResponse extends Response {
70
+ static json(data, init) {
71
+ const headers = { ...((init && init.headers) || {}) };
72
+ headers["content-type"] = "application/json";
73
+ return new Response(JSON.stringify(data), { ...init, headers });
74
+ }
75
+ static redirect(url, status) {
76
+ return new Response(null, {
77
+ status: status || 302,
78
+ headers: { location: String(url) },
79
+ });
80
+ }
81
+ static next() {
82
+ return new Response(null);
83
+ }
84
+ static rewrite() {
85
+ return new Response(null);
86
+ }
87
+ }
88
+
89
+ class NextRequest extends Request {
90
+ constructor(input, init) {
91
+ super(input, init);
92
+ this.nextUrl = new URL(typeof input === "string" ? input : input.url);
93
+ this.cookies = {
94
+ get() {
95
+ return undefined;
96
+ },
97
+ getAll() {
98
+ return [];
99
+ },
100
+ has() {
101
+ return false;
102
+ },
103
+ set() {},
104
+ delete() {},
105
+ };
106
+ }
107
+ }
108
+
109
+ function userAgent() {
110
+ return {
111
+ ua: "",
112
+ browser: {},
113
+ device: {},
114
+ engine: {},
115
+ os: {},
116
+ cpu: {},
117
+ isBot: false,
118
+ };
119
+ }
120
+
121
+ // --- export surface --------------------------------------------------------
122
+ // `server-only` / `client-only` exports nothing; the import itself is the
123
+ // side effect. Everything else is exported below; callers only read the
124
+ // names their specifier exposes.
125
+ module.exports = {
126
+ // next/cache
127
+ revalidatePath,
128
+ revalidateTag,
129
+ unstable_cache,
130
+ unstable_noStore,
131
+ unstable_cacheLife,
132
+ unstable_cacheTag,
133
+ // next/headers
134
+ headers,
135
+ cookies,
136
+ draftMode,
137
+ // next/navigation
138
+ redirect,
139
+ permanentRedirect,
140
+ notFound,
141
+ RedirectType,
142
+ // next/server
143
+ NextResponse,
144
+ NextRequest,
145
+ userAgent,
146
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Registers the Next.js server-runtime shim loader.
3
+ *
4
+ * Passed as `node --import=<this-file>` by the CLI when spawning tsx in
5
+ * --no-hmr mode, so the shim loader is active before tsx evaluates the
6
+ * user's MCP server entry.
7
+ *
8
+ * The HMR path calls `module.register()` directly in-process; see
9
+ * cli/src/utils/next-shims.ts.
10
+ */
11
+
12
+ import { register } from "node:module";
13
+
14
+ register("./next-shims-loader.mjs", import.meta.url);
@@ -0,0 +1,11 @@
1
+ {
2
+ "$comment": "Single source of truth for the Next.js server-runtime modules we shim in the MCP server context (and reject in widget builds). Loaded by next-shims-cjs.cjs (CommonJS require) and next-shims-loader.mjs (ESM import assertions). When adding a new specifier, also add its stub to next-shims-noop.cjs and its data-URL stub to next-shims-loader.mjs.",
3
+ "shimmedModules": [
4
+ "server-only",
5
+ "client-only",
6
+ "next/cache",
7
+ "next/headers",
8
+ "next/navigation",
9
+ "next/server"
10
+ ]
11
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Next.js runtime-module shim wiring.
3
+ *
4
+ * When the CLI runs an MCP server that lives inside a Next.js app (the
5
+ * `src/mcp/` drop-in layout), transitive imports from the user's tools
6
+ * almost always pull in Next.js server-runtime modules:
7
+ *
8
+ * - `server-only` — throws on import outside an RSC
9
+ * - `next/cache` — revalidatePath / unstable_cache
10
+ * - `next/headers` — headers() / cookies()
11
+ * - `next/navigation` — redirect() / notFound()
12
+ * - `next/server` — NextResponse / NextRequest
13
+ *
14
+ * These are all meaningful only inside a Next.js request; outside of one
15
+ * (i.e., in our MCP server process) they're either unusable or useless.
16
+ * Rather than asking the developer to write shim files, the CLI detects
17
+ * Next.js and installs an ESM loader hook that resolves these specifiers to
18
+ * no-op / inert implementations.
19
+ *
20
+ * Detection: presence of `next` in the user's package.json dependencies or
21
+ * devDependencies.
22
+ *
23
+ * Registration happens in two places:
24
+ * 1. HMR dev mode — inline, via `module.register()` in the parent process
25
+ * before `tsImport` is called.
26
+ * 2. --no-hmr and build — via `NODE_OPTIONS=--import=<register.mjs>` on the
27
+ * spawned tsx/esbuild process.
28
+ */
29
+ /**
30
+ * Returns true when the project has `next` listed in package.json deps.
31
+ *
32
+ * Missing / unreadable package.json returns false silently — the shims are
33
+ * strictly additive, so "can't decide" should mean "don't shim".
34
+ */
35
+ export declare function detectNextJsProject(projectPath: string): Promise<boolean>;
36
+ /**
37
+ * Load Next.js's environment-file cascade into `process.env`.
38
+ *
39
+ * Next.js's dev server reads env files in this priority order (highest
40
+ * wins): `.env.development.local` → `.env.local` → `.env.development` →
41
+ * `.env`. Tools imported from a Next.js app usually assume these variables
42
+ * are populated, so the MCP CLI mirrors the same cascade when it runs
43
+ * inside a Next.js project.
44
+ *
45
+ * The values we set here flow to the spawned tsx child through
46
+ * `runCommand`'s `...process.env` merge.
47
+ */
48
+ export declare function loadNextJsEnvFiles(projectPath: string): Promise<void>;
49
+ /**
50
+ * Register the shim loader in the CURRENT Node.js process.
51
+ *
52
+ * Used by the HMR dev path, which imports the user's entry via
53
+ * `tsx/esm/api.tsImport` in-process (no child process). We install both:
54
+ *
55
+ * - The ESM loader hook (handles `import ...` of shimmed specifiers)
56
+ * - The CJS `Module._resolveFilename` patch (handles `require(...)`, which
57
+ * tsx emits when transpiling TypeScript to CommonJS)
58
+ *
59
+ * Returns `true` if at least one half succeeded, `false` only when neither
60
+ * shim file can be located (graceful degradation — dev still works, users
61
+ * just see the raw Next.js error on `server-only` etc.).
62
+ */
63
+ export declare function registerNextShimsInProcess(): Promise<boolean>;
64
+ /**
65
+ * Build a child-process env that adds both the CJS preload (`-r ...`) and the
66
+ * ESM registration (`--import=...`) to NODE_OPTIONS, preserving any value
67
+ * the user already set.
68
+ *
69
+ * Both are needed because tsx loads user TypeScript as CJS by default (goes
70
+ * through `Module._resolveFilename` — covered by `-r`) while some modules are
71
+ * imported via ESM (covered by `--import=...`).
72
+ *
73
+ * If either shim file can't be found on disk, we degrade gracefully — the
74
+ * dev loop still starts, we just don't shim that half.
75
+ */
76
+ export declare function withNextShimsEnv(baseEnv: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
77
+ //# sourceMappingURL=next-shims.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"next-shims.d.ts","sourceRoot":"","sources":["../../src/utils/next-shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAMH;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAsB3E;AA4DD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,OAAO,CAAC,CAuBnE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,CAAC,UAAU,GACzB,MAAM,CAAC,UAAU,CAkBnB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mcp-use/cli",
3
3
  "type": "module",
4
- "version": "3.1.0-canary.2",
4
+ "version": "3.1.0-canary.3",
5
5
  "description": "The mcp-use CLI is a tool for building and deploying MCP servers with support for ChatGPT Apps, Code Mode, OAuth, Notifications, Sampling, Observability and more.",
6
6
  "author": "mcp-use, Inc.",
7
7
  "license": "MIT",
@@ -56,8 +56,8 @@
56
56
  "vite-plugin-singlefile": "^2.3.2",
57
57
  "ws": "^8.19.0",
58
58
  "zod": "4.3.5",
59
- "@mcp-use/inspector": "2.2.1-canary.2",
60
- "mcp-use": "1.24.3-canary.2"
59
+ "@mcp-use/inspector": "3.0.0-canary.3",
60
+ "mcp-use": "1.25.0-canary.3"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/ws": "^8.18.1",