init-xmcp 1.5.0 → 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.
@@ -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 tanstack = options.framework === "tanstack";
25
- const platformFlag = tanstack && options.cloudflare ? " --cf" : "";
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 = tanstack ? `${build} && vite build` : build;
45
+ packageJson.scripts.build = host ? `${build} && ${host} build` : build;
34
46
  }
35
47
 
36
48
  if (packageJson.scripts.dev) {
37
- packageJson.scripts.dev = tanstack
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 = tanstack
42
- ? `${build} && (${dev} & vite dev)`
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 { detectTanstackCloudflare } from "./helpers/create-tanstack-route.js";
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 the TanStack adapter for Cloudflare Workers", false)
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 === "tanstack" &&
139
- (options.cf || detectTanstackCloudflare(projectRoot));
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" || detectedFramework === "tanstack") &&
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" || detectedFramework === "tanstack") &&
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 === "tanstack" ? "mcp.ts" : "route.ts"}`
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
- console.log(` • tsconfig.json`);
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';