init-xmcp 1.5.0 → 1.7.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 +9 -0
- package/README.md +45 -0
- 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 -8
|
@@ -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,7 +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("--cf", "Build
|
|
52
|
+
.option("--cf", "Build a Fetch adapter for Cloudflare Workers", false)
|
|
50
53
|
.option("--skip-route", "Skip route creation", false)
|
|
51
54
|
.action(async (options) => {
|
|
52
55
|
console.log(chalk.bold(`\ninit-xmcp@${packageJson.version}`));
|
|
@@ -134,9 +137,27 @@ const program = new Command()
|
|
|
134
137
|
if (detectedFramework === "tanstack" && !options.skipRoute) {
|
|
135
138
|
routePath = options.routePath || "src/routes";
|
|
136
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
|
+
}
|
|
137
158
|
const cloudflare =
|
|
138
|
-
detectedFramework
|
|
139
|
-
(options.cf ||
|
|
159
|
+
isFetchFramework(detectedFramework) &&
|
|
160
|
+
(options.cf || detectFetchCloudflare(projectRoot, detectedFramework));
|
|
140
161
|
|
|
141
162
|
// determine package manager
|
|
142
163
|
let packageManager: "npm" | "yarn" | "pnpm" | "bun";
|
|
@@ -193,7 +214,8 @@ const program = new Command()
|
|
|
193
214
|
}
|
|
194
215
|
|
|
195
216
|
if (
|
|
196
|
-
(detectedFramework === "nextjs" ||
|
|
217
|
+
(detectedFramework === "nextjs" ||
|
|
218
|
+
isFetchFramework(detectedFramework)) &&
|
|
197
219
|
!options.skipRoute
|
|
198
220
|
) {
|
|
199
221
|
prompts.push({
|
|
@@ -252,7 +274,8 @@ const program = new Command()
|
|
|
252
274
|
}
|
|
253
275
|
|
|
254
276
|
if (
|
|
255
|
-
(detectedFramework === "nextjs" ||
|
|
277
|
+
(detectedFramework === "nextjs" ||
|
|
278
|
+
isFetchFramework(detectedFramework)) &&
|
|
256
279
|
!options.skipRoute &&
|
|
257
280
|
answers.routePath
|
|
258
281
|
) {
|
|
@@ -362,7 +385,7 @@ const program = new Command()
|
|
|
362
385
|
|
|
363
386
|
if (routePath) {
|
|
364
387
|
console.log(
|
|
365
|
-
` • ${routePath}/${detectedFramework === "
|
|
388
|
+
` • ${routePath}/${detectedFramework === "sveltekit" ? "+server.ts" : isFetchFramework(detectedFramework) ? "mcp.ts" : "route.ts"}`
|
|
366
389
|
);
|
|
367
390
|
}
|
|
368
391
|
|
|
@@ -375,10 +398,38 @@ const program = new Command()
|
|
|
375
398
|
|
|
376
399
|
console.log(chalk.blue("\n❯ Files updated:"));
|
|
377
400
|
console.log(` • package.json`);
|
|
378
|
-
|
|
401
|
+
if (!isFetchFramework(detectedFramework))
|
|
402
|
+
console.log(` • tsconfig.json`);
|
|
379
403
|
|
|
380
404
|
console.log(chalk.blue("\nNext steps:"));
|
|
381
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
|
+
|
|
382
433
|
// code integration for express projects
|
|
383
434
|
if (detectedFramework === "express") {
|
|
384
435
|
const integrationCode = `import { xmcpHandler } from '@xmcp/adapter';
|