init-xmcp 1.4.1 → 1.6.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +14 -1
- package/README.md +49 -4
- package/dist/__tests__/fetch.test.d.ts +1 -0
- package/dist/__tests__/fetch.test.js +217 -0
- package/dist/helpers/create-fetch-route.d.ts +12 -0
- package/dist/helpers/create-fetch-route.js +129 -0
- package/dist/helpers/detect-framework.d.ts +1 -1
- package/dist/helpers/detect-framework.js +12 -0
- package/dist/helpers/generate-config.js +9 -1
- package/dist/helpers/init.js +14 -2
- package/dist/helpers/update-package.js +19 -6
- package/dist/index.js +44 -8
- package/package.json +1 -1
- package/src/__tests__/fetch.test.ts +294 -0
- package/src/helpers/create-fetch-route.ts +179 -0
- package/src/helpers/detect-framework.ts +21 -1
- package/src/helpers/generate-config.ts +11 -1
- package/src/helpers/init.ts +20 -2
- package/src/helpers/update-package.ts +20 -6
- package/src/index.ts +59 -12
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isFetchFramework } from "./create-fetch-route.js";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import fs from "fs-extra";
|
|
3
4
|
import type { Framework } from "./detect-framework.js";
|
|
@@ -21,8 +22,19 @@ export function updatePackageJson(
|
|
|
21
22
|
packageJson.devDependencies = packageJson.devDependencies ?? {};
|
|
22
23
|
packageJson.devDependencies["@xmcp-dev/compiler"] ??= "latest";
|
|
23
24
|
|
|
24
|
-
const
|
|
25
|
-
const
|
|
25
|
+
const fetchFramework = isFetchFramework(options.framework);
|
|
26
|
+
const hostCommands = {
|
|
27
|
+
tanstack: "vite",
|
|
28
|
+
sveltekit: "vite",
|
|
29
|
+
nuxt: "nuxt",
|
|
30
|
+
"react-router": "react-router",
|
|
31
|
+
astro: "astro",
|
|
32
|
+
};
|
|
33
|
+
const host =
|
|
34
|
+
options.framework && options.framework in hostCommands
|
|
35
|
+
? hostCommands[options.framework as keyof typeof hostCommands]
|
|
36
|
+
: undefined;
|
|
37
|
+
const platformFlag = fetchFramework && options.cloudflare ? " --cf" : "";
|
|
26
38
|
const build = `xmcp build${platformFlag}`;
|
|
27
39
|
const dev = `xmcp dev${platformFlag}`;
|
|
28
40
|
|
|
@@ -30,16 +42,18 @@ export function updatePackageJson(
|
|
|
30
42
|
if (packageJson.scripts.build) {
|
|
31
43
|
packageJson.scripts.build = `${build} && ${packageJson.scripts.build}`;
|
|
32
44
|
} else {
|
|
33
|
-
packageJson.scripts.build =
|
|
45
|
+
packageJson.scripts.build = host ? `${build} && ${host} build` : build;
|
|
34
46
|
}
|
|
35
47
|
|
|
36
48
|
if (packageJson.scripts.dev) {
|
|
37
|
-
packageJson.scripts.dev =
|
|
49
|
+
packageJson.scripts.dev = fetchFramework
|
|
38
50
|
? `${build} && (${dev} & ${packageJson.scripts.dev})`
|
|
39
51
|
: `${dev} & ${packageJson.scripts.dev}`;
|
|
40
52
|
} else {
|
|
41
|
-
packageJson.scripts.dev =
|
|
42
|
-
?
|
|
53
|
+
packageJson.scripts.dev = fetchFramework
|
|
54
|
+
? host
|
|
55
|
+
? `${build} && (${dev} & ${host} dev)`
|
|
56
|
+
: `${build} && ${dev}`
|
|
43
57
|
: dev;
|
|
44
58
|
}
|
|
45
59
|
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,10 @@ import { Command } from "commander";
|
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import inquirer from "inquirer";
|
|
6
6
|
import { init } from "./helpers/init.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
detectFetchCloudflare,
|
|
9
|
+
isFetchFramework,
|
|
10
|
+
} from "./helpers/create-fetch-route.js";
|
|
8
11
|
import {
|
|
9
12
|
detectFramework,
|
|
10
13
|
detectTypeScript,
|
|
@@ -46,11 +49,7 @@ const program = new Command()
|
|
|
46
49
|
.option("--skip-tools", "Skip tool creation", false)
|
|
47
50
|
.option("--skip-prompts", "Skip prompt creation", false)
|
|
48
51
|
.option("--skip-resources", "Skip resource creation", false)
|
|
49
|
-
.option(
|
|
50
|
-
"--cf",
|
|
51
|
-
"Build the TanStack Start adapter for Cloudflare Workers",
|
|
52
|
-
false
|
|
53
|
-
)
|
|
52
|
+
.option("--cf", "Build a Fetch adapter for Cloudflare Workers", false)
|
|
54
53
|
.option("--skip-route", "Skip route creation", false)
|
|
55
54
|
.action(async (options) => {
|
|
56
55
|
console.log(chalk.bold(`\ninit-xmcp@${packageJson.version}`));
|
|
@@ -138,9 +137,27 @@ const program = new Command()
|
|
|
138
137
|
if (detectedFramework === "tanstack" && !options.skipRoute) {
|
|
139
138
|
routePath = options.routePath || "src/routes";
|
|
140
139
|
}
|
|
140
|
+
if (detectedFramework === "hono" && !options.skipRoute) {
|
|
141
|
+
routePath = options.routePath || "src/routes";
|
|
142
|
+
}
|
|
143
|
+
if (detectedFramework === "sveltekit" && !options.skipRoute) {
|
|
144
|
+
routePath = options.routePath || "src/routes/mcp";
|
|
145
|
+
}
|
|
146
|
+
if (!options.skipRoute) {
|
|
147
|
+
const defaults = {
|
|
148
|
+
nuxt: "server/routes",
|
|
149
|
+
"react-router": "app/routes",
|
|
150
|
+
astro: "src/pages",
|
|
151
|
+
};
|
|
152
|
+
if (detectedFramework in defaults) {
|
|
153
|
+
routePath =
|
|
154
|
+
options.routePath ||
|
|
155
|
+
defaults[detectedFramework as keyof typeof defaults];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
141
158
|
const cloudflare =
|
|
142
|
-
detectedFramework
|
|
143
|
-
(options.cf ||
|
|
159
|
+
isFetchFramework(detectedFramework) &&
|
|
160
|
+
(options.cf || detectFetchCloudflare(projectRoot, detectedFramework));
|
|
144
161
|
|
|
145
162
|
// determine package manager
|
|
146
163
|
let packageManager: "npm" | "yarn" | "pnpm" | "bun";
|
|
@@ -197,7 +214,8 @@ const program = new Command()
|
|
|
197
214
|
}
|
|
198
215
|
|
|
199
216
|
if (
|
|
200
|
-
(detectedFramework === "nextjs" ||
|
|
217
|
+
(detectedFramework === "nextjs" ||
|
|
218
|
+
isFetchFramework(detectedFramework)) &&
|
|
201
219
|
!options.skipRoute
|
|
202
220
|
) {
|
|
203
221
|
prompts.push({
|
|
@@ -256,7 +274,8 @@ const program = new Command()
|
|
|
256
274
|
}
|
|
257
275
|
|
|
258
276
|
if (
|
|
259
|
-
(detectedFramework === "nextjs" ||
|
|
277
|
+
(detectedFramework === "nextjs" ||
|
|
278
|
+
isFetchFramework(detectedFramework)) &&
|
|
260
279
|
!options.skipRoute &&
|
|
261
280
|
answers.routePath
|
|
262
281
|
) {
|
|
@@ -366,7 +385,7 @@ const program = new Command()
|
|
|
366
385
|
|
|
367
386
|
if (routePath) {
|
|
368
387
|
console.log(
|
|
369
|
-
` • ${routePath}/${detectedFramework === "
|
|
388
|
+
` • ${routePath}/${detectedFramework === "sveltekit" ? "+server.ts" : isFetchFramework(detectedFramework) ? "mcp.ts" : "route.ts"}`
|
|
370
389
|
);
|
|
371
390
|
}
|
|
372
391
|
|
|
@@ -379,10 +398,38 @@ const program = new Command()
|
|
|
379
398
|
|
|
380
399
|
console.log(chalk.blue("\n❯ Files updated:"));
|
|
381
400
|
console.log(` • package.json`);
|
|
382
|
-
|
|
401
|
+
if (!isFetchFramework(detectedFramework))
|
|
402
|
+
console.log(` • tsconfig.json`);
|
|
383
403
|
|
|
384
404
|
console.log(chalk.blue("\nNext steps:"));
|
|
385
405
|
|
|
406
|
+
if (detectedFramework === "hono") {
|
|
407
|
+
if (routePath) {
|
|
408
|
+
console.log(
|
|
409
|
+
`Mount the router from ${routePath}/mcp.ts in your Hono app:\n\napp.route("/mcp", mcp);\n`
|
|
410
|
+
);
|
|
411
|
+
} else {
|
|
412
|
+
console.log(
|
|
413
|
+
'Import xmcpHandler from .xmcp/adapter/index.js and register app.all("/mcp", (c) => xmcpHandler(c.req.raw)).'
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
console.log(
|
|
417
|
+
"Keep your existing Hono dev/build commands after the xmcp commands. See https://xmcp.dev/docs/adapters/hono"
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (detectedFramework === "nuxt") {
|
|
422
|
+
console.log(
|
|
423
|
+
"Add .xmcp to nitro.externals.inline in nuxt.config.ts so Nitro bundles the adapter during development. See https://xmcp.dev/docs/adapters/nuxt"
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (detectedFramework === "react-router" && routePath) {
|
|
428
|
+
console.log(
|
|
429
|
+
`Register ${routePath}/mcp.ts as a resource route in your route config (no default component). See https://xmcp.dev/docs/adapters/react-router`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
|
|
386
433
|
// code integration for express projects
|
|
387
434
|
if (detectedFramework === "express") {
|
|
388
435
|
const integrationCode = `import { xmcpHandler } from '@xmcp/adapter';
|