init-xmcp 0.2.2-canary.0 → 0.2.2-canary.2

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,4 +1,4 @@
1
1
 
2
- > init-xmcp@0.2.2-canary.0 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
2
+ > init-xmcp@0.2.2-canary.2 build /home/runner/work/xmcp/xmcp/packages/init-xmcp
3
3
  > tsc
4
4
 
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Create resources directory and resource files
3
+ * @param projectRoot - Project root directory
4
+ * @param resourcesPath - Path for resources directory (relative to project root)
5
+ */
6
+ export declare function createResources(projectRoot: string, resourcesPath: string): void;
@@ -0,0 +1,62 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+ /**
5
+ * Create resources directory and resource files
6
+ * @param projectRoot - Project root directory
7
+ * @param resourcesPath - Path for resources directory (relative to project root)
8
+ */
9
+ export function createResources(projectRoot, resourcesPath) {
10
+ // normalize the path to handle any path separators correctly
11
+ const normalizedResourcesPath = path.normalize(resourcesPath);
12
+ const resourcesDirPath = path.join(projectRoot, normalizedResourcesPath);
13
+ try {
14
+ // create resources directory and all parent directories
15
+ fs.ensureDirSync(resourcesDirPath);
16
+ // create (config) subdirectory
17
+ const configDirPath = path.join(resourcesDirPath, "(config)");
18
+ fs.ensureDirSync(configDirPath);
19
+ const staticResourceFilePath = path.join(configDirPath, "app.ts");
20
+ fs.writeFileSync(staticResourceFilePath, staticResourceTemplate);
21
+ // create (users)/[userId] subdirectory structure
22
+ const usersDirPath = path.join(resourcesDirPath, "(users)", "[userId]");
23
+ fs.ensureDirSync(usersDirPath);
24
+ const dynamicResourceFilePath = path.join(usersDirPath, "profile.ts");
25
+ fs.writeFileSync(dynamicResourceFilePath, dynamicResourceTemplate);
26
+ console.log(chalk.green(`Created static resource: ${normalizedResourcesPath}/(config)/app.ts`));
27
+ console.log(chalk.green(`Created dynamic resource: ${normalizedResourcesPath}/(users)/[userId]/profile.ts`));
28
+ }
29
+ catch (error) {
30
+ console.error(chalk.red(`Failed to create resources: ${error}`));
31
+ throw error;
32
+ }
33
+ }
34
+ const staticResourceTemplate = `import { type ResourceMetadata } from "xmcp";
35
+
36
+ export const metadata: ResourceMetadata = {
37
+ name: "app-config",
38
+ title: "Application Config",
39
+ description: "Application configuration data",
40
+ };
41
+
42
+ export default function handler() {
43
+ return "App configuration here";
44
+ }
45
+ `;
46
+ const dynamicResourceTemplate = `import { z } from "zod";
47
+ import { type ResourceMetadata, type InferSchema } from "xmcp";
48
+
49
+ export const schema = {
50
+ userId: z.string().describe("The ID of the user"),
51
+ };
52
+
53
+ export const metadata: ResourceMetadata = {
54
+ name: "user-profile",
55
+ title: "User Profile",
56
+ description: "User profile information",
57
+ };
58
+
59
+ export default function handler({ userId }: InferSchema<typeof schema>) {
60
+ return \`Profile data for user \${userId}\`;
61
+ }
62
+ `;
@@ -4,4 +4,4 @@
4
4
  * @param frameworkAdapter - Selected framework adapter
5
5
  * @param toolsPath - Optional path for tools directory
6
6
  */
7
- export declare function generateConfig(projectPath: string, frameworkAdapter: string, toolsPath?: string, promptsPath?: string): void;
7
+ export declare function generateConfig(projectPath: string, frameworkAdapter: string, toolsPath?: string, promptsPath?: string, resourcesPath?: string): void;
@@ -6,7 +6,7 @@ import fs from "fs-extra";
6
6
  * @param frameworkAdapter - Selected framework adapter
7
7
  * @param toolsPath - Optional path for tools directory
8
8
  */
9
- export function generateConfig(projectPath, frameworkAdapter, toolsPath, promptsPath) {
9
+ export function generateConfig(projectPath, frameworkAdapter, toolsPath, promptsPath, resourcesPath) {
10
10
  let configContent = `import { type XmcpConfig } from "xmcp";
11
11
 
12
12
  const config: XmcpConfig = {
@@ -14,7 +14,7 @@ const config: XmcpConfig = {
14
14
  experimental: {
15
15
  adapter: "${frameworkAdapter}",
16
16
  },`;
17
- if (toolsPath || promptsPath) {
17
+ if (toolsPath || promptsPath || resourcesPath) {
18
18
  configContent += `
19
19
  paths: {`;
20
20
  if (toolsPath) {
@@ -24,6 +24,10 @@ const config: XmcpConfig = {
24
24
  if (promptsPath) {
25
25
  configContent += `
26
26
  prompts: "${promptsPath}",`;
27
+ }
28
+ if (resourcesPath) {
29
+ configContent += `
30
+ resources: "${resourcesPath}",`;
27
31
  }
28
32
  configContent += `
29
33
  },`;
@@ -4,6 +4,7 @@ interface InitOptions {
4
4
  framework: Framework;
5
5
  toolsPath: string | undefined;
6
6
  promptsPath: string | undefined;
7
+ resourcesPath: string | undefined;
7
8
  routePath: string | undefined;
8
9
  packageManager: "npm" | "yarn" | "pnpm" | "bun";
9
10
  }
@@ -6,9 +6,10 @@ import { updateGitignore } from "./update-gitignore.js";
6
6
  import { createTool } from "./create-tool.js";
7
7
  import { createRoute } from "./create-handler.js";
8
8
  import { createPrompt } from "./create-prompt.js";
9
+ import { createResources } from "./create-resources.js";
9
10
  export async function init(options) {
10
- const { projectRoot, framework, toolsPath, promptsPath, routePath, packageManager, } = options;
11
- generateConfig(projectRoot, framework, toolsPath, promptsPath);
11
+ const { projectRoot, framework, toolsPath, promptsPath, resourcesPath, routePath, packageManager, } = options;
12
+ generateConfig(projectRoot, framework, toolsPath, promptsPath, resourcesPath);
12
13
  await install(projectRoot, packageManager);
13
14
  updatePackageJson(projectRoot);
14
15
  updateTsConfig(projectRoot);
@@ -19,6 +20,9 @@ export async function init(options) {
19
20
  if (promptsPath) {
20
21
  createPrompt(projectRoot, promptsPath);
21
22
  }
23
+ if (resourcesPath) {
24
+ createResources(projectRoot, resourcesPath);
25
+ }
22
26
  if (framework === "nextjs" && routePath) {
23
27
  createRoute(projectRoot, routePath);
24
28
  }
package/dist/index.js CHANGED
@@ -22,8 +22,11 @@ const program = new Command()
22
22
  .option("--package-manager <manager>", "Specify package manager (npm, yarn, pnpm, bun)", "")
23
23
  .option("--tools-path <path>", "Specify custom tools path", "")
24
24
  .option("--prompts-path <path>", "Specify custom prompts path", "")
25
+ .option("--resources-path <path>", "Specify custom resources path", "")
25
26
  .option("--route-path <path>", "Specify custom route path", "")
26
27
  .option("--skip-tools", "Skip tool creation", false)
28
+ .option("--skip-prompts", "Skip prompt creation", false)
29
+ .option("--skip-resources", "Skip resource creation", false)
27
30
  .option("--skip-route", "Skip route creation", false)
28
31
  .action(async (options) => {
29
32
  console.log(chalk.bold(`\ninit-xmcp@${packageJson.version}`));
@@ -70,6 +73,18 @@ const program = new Command()
70
73
  promptsPath = hasSrcFolder ? "src/prompts" : "prompts";
71
74
  }
72
75
  }
76
+ // determine resources path
77
+ let resourcesPath;
78
+ if (!options.skipResources) {
79
+ if (options.resourcesPath) {
80
+ resourcesPath = options.resourcesPath;
81
+ }
82
+ else {
83
+ // check if src folder exists and default to src/resources if it does, otherwise resources
84
+ const hasSrcFolder = fs.existsSync(path.join(projectRoot, "src"));
85
+ resourcesPath = hasSrcFolder ? "src/resources" : "resources";
86
+ }
87
+ }
73
88
  // determine route path
74
89
  let routePath;
75
90
  if (detectedFramework === "nextjs" && !options.skipRoute) {
@@ -115,6 +130,14 @@ const program = new Command()
115
130
  default: promptsPath,
116
131
  });
117
132
  }
133
+ if (!options.skipResources) {
134
+ prompts.push({
135
+ type: "input",
136
+ name: "resourcesPath",
137
+ message: "Resources directory path:",
138
+ default: resourcesPath,
139
+ });
140
+ }
118
141
  if (detectedFramework === "nextjs" && !options.skipRoute) {
119
142
  prompts.push({
120
143
  type: "input",
@@ -156,6 +179,9 @@ const program = new Command()
156
179
  if (!options.skipPrompts) {
157
180
  promptsPath = answers.promptsPath;
158
181
  }
182
+ if (!options.skipResources) {
183
+ resourcesPath = answers.resourcesPath;
184
+ }
159
185
  if (detectedFramework === "nextjs" &&
160
186
  !options.skipRoute &&
161
187
  answers.routePath) {
@@ -221,6 +247,7 @@ const program = new Command()
221
247
  framework: detectedFramework,
222
248
  toolsPath,
223
249
  promptsPath,
250
+ resourcesPath,
224
251
  routePath,
225
252
  packageManager,
226
253
  });
@@ -233,6 +260,10 @@ const program = new Command()
233
260
  if (promptsPath) {
234
261
  console.log(` • ${promptsPath}/review-code.ts`);
235
262
  }
263
+ if (resourcesPath) {
264
+ console.log(` • ${resourcesPath}/(config)/app.ts`);
265
+ console.log(` • ${resourcesPath}/(users)/[userId]/profile.ts`);
266
+ }
236
267
  if (routePath) {
237
268
  console.log(` • ${routePath}/route.ts`);
238
269
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "init-xmcp",
3
- "version": "0.2.2-canary.0",
3
+ "version": "0.2.2-canary.2",
4
4
  "author": {
5
5
  "name": "Basement Studio",
6
6
  "email": "hello@basement.studio",
@@ -0,0 +1,81 @@
1
+ import fs from "fs-extra";
2
+ import path from "path";
3
+ import chalk from "chalk";
4
+
5
+ /**
6
+ * Create resources directory and resource files
7
+ * @param projectRoot - Project root directory
8
+ * @param resourcesPath - Path for resources directory (relative to project root)
9
+ */
10
+ export function createResources(
11
+ projectRoot: string,
12
+ resourcesPath: string
13
+ ): void {
14
+ // normalize the path to handle any path separators correctly
15
+ const normalizedResourcesPath = path.normalize(resourcesPath);
16
+ const resourcesDirPath = path.join(projectRoot, normalizedResourcesPath);
17
+
18
+ try {
19
+ // create resources directory and all parent directories
20
+ fs.ensureDirSync(resourcesDirPath);
21
+
22
+ // create (config) subdirectory
23
+ const configDirPath = path.join(resourcesDirPath, "(config)");
24
+ fs.ensureDirSync(configDirPath);
25
+
26
+ const staticResourceFilePath = path.join(configDirPath, "app.ts");
27
+ fs.writeFileSync(staticResourceFilePath, staticResourceTemplate);
28
+
29
+ // create (users)/[userId] subdirectory structure
30
+ const usersDirPath = path.join(resourcesDirPath, "(users)", "[userId]");
31
+ fs.ensureDirSync(usersDirPath);
32
+
33
+ const dynamicResourceFilePath = path.join(usersDirPath, "profile.ts");
34
+ fs.writeFileSync(dynamicResourceFilePath, dynamicResourceTemplate);
35
+
36
+ console.log(
37
+ chalk.green(
38
+ `Created static resource: ${normalizedResourcesPath}/(config)/app.ts`
39
+ )
40
+ );
41
+ console.log(
42
+ chalk.green(
43
+ `Created dynamic resource: ${normalizedResourcesPath}/(users)/[userId]/profile.ts`
44
+ )
45
+ );
46
+ } catch (error) {
47
+ console.error(chalk.red(`Failed to create resources: ${error}`));
48
+ throw error;
49
+ }
50
+ }
51
+
52
+ const staticResourceTemplate = `import { type ResourceMetadata } from "xmcp";
53
+
54
+ export const metadata: ResourceMetadata = {
55
+ name: "app-config",
56
+ title: "Application Config",
57
+ description: "Application configuration data",
58
+ };
59
+
60
+ export default function handler() {
61
+ return "App configuration here";
62
+ }
63
+ `;
64
+
65
+ const dynamicResourceTemplate = `import { z } from "zod";
66
+ import { type ResourceMetadata, type InferSchema } from "xmcp";
67
+
68
+ export const schema = {
69
+ userId: z.string().describe("The ID of the user"),
70
+ };
71
+
72
+ export const metadata: ResourceMetadata = {
73
+ name: "user-profile",
74
+ title: "User Profile",
75
+ description: "User profile information",
76
+ };
77
+
78
+ export default function handler({ userId }: InferSchema<typeof schema>) {
79
+ return \`Profile data for user \${userId}\`;
80
+ }
81
+ `;
@@ -11,7 +11,8 @@ export function generateConfig(
11
11
  projectPath: string,
12
12
  frameworkAdapter: string,
13
13
  toolsPath?: string,
14
- promptsPath?: string
14
+ promptsPath?: string,
15
+ resourcesPath?: string
15
16
  ): void {
16
17
  let configContent = `import { type XmcpConfig } from "xmcp";
17
18
 
@@ -21,7 +22,7 @@ const config: XmcpConfig = {
21
22
  adapter: "${frameworkAdapter}",
22
23
  },`;
23
24
 
24
- if (toolsPath || promptsPath) {
25
+ if (toolsPath || promptsPath || resourcesPath) {
25
26
  configContent += `
26
27
  paths: {`;
27
28
 
@@ -34,6 +35,11 @@ const config: XmcpConfig = {
34
35
  configContent += `
35
36
  prompts: "${promptsPath}",`;
36
37
  }
38
+
39
+ if (resourcesPath) {
40
+ configContent += `
41
+ resources: "${resourcesPath}",`;
42
+ }
37
43
  configContent += `
38
44
  },`;
39
45
  }
@@ -6,14 +6,15 @@ import { updateGitignore } from "./update-gitignore.js";
6
6
  import { createTool } from "./create-tool.js";
7
7
  import { Framework } from "./detect-framework.js";
8
8
  import { createRoute } from "./create-handler.js";
9
- import chalk from "chalk";
10
9
  import { createPrompt } from "./create-prompt.js";
10
+ import { createResources } from "./create-resources.js";
11
11
 
12
12
  interface InitOptions {
13
13
  projectRoot: string;
14
14
  framework: Framework;
15
15
  toolsPath: string | undefined;
16
16
  promptsPath: string | undefined;
17
+ resourcesPath: string | undefined;
17
18
  routePath: string | undefined;
18
19
  packageManager: "npm" | "yarn" | "pnpm" | "bun";
19
20
  }
@@ -24,11 +25,12 @@ export async function init(options: InitOptions) {
24
25
  framework,
25
26
  toolsPath,
26
27
  promptsPath,
28
+ resourcesPath,
27
29
  routePath,
28
30
  packageManager,
29
31
  } = options;
30
32
 
31
- generateConfig(projectRoot, framework, toolsPath, promptsPath);
33
+ generateConfig(projectRoot, framework, toolsPath, promptsPath, resourcesPath);
32
34
 
33
35
  await install(projectRoot, packageManager);
34
36
 
@@ -46,6 +48,10 @@ export async function init(options: InitOptions) {
46
48
  createPrompt(projectRoot, promptsPath);
47
49
  }
48
50
 
51
+ if (resourcesPath) {
52
+ createResources(projectRoot, resourcesPath);
53
+ }
54
+
49
55
  if (framework === "nextjs" && routePath) {
50
56
  createRoute(projectRoot, routePath);
51
57
  }
package/src/index.ts CHANGED
@@ -40,8 +40,11 @@ const program = new Command()
40
40
  )
41
41
  .option("--tools-path <path>", "Specify custom tools path", "")
42
42
  .option("--prompts-path <path>", "Specify custom prompts path", "")
43
+ .option("--resources-path <path>", "Specify custom resources path", "")
43
44
  .option("--route-path <path>", "Specify custom route path", "")
44
45
  .option("--skip-tools", "Skip tool creation", false)
46
+ .option("--skip-prompts", "Skip prompt creation", false)
47
+ .option("--skip-resources", "Skip resource creation", false)
45
48
  .option("--skip-route", "Skip route creation", false)
46
49
  .action(async (options) => {
47
50
  console.log(chalk.bold(`\ninit-xmcp@${packageJson.version}`));
@@ -91,7 +94,6 @@ const program = new Command()
91
94
  }
92
95
 
93
96
  // determine prompts path
94
-
95
97
  let promptsPath: string | undefined;
96
98
  if (!options.skipPrompts) {
97
99
  if (options.promptsPath) {
@@ -103,6 +105,18 @@ const program = new Command()
103
105
  }
104
106
  }
105
107
 
108
+ // determine resources path
109
+ let resourcesPath: string | undefined;
110
+ if (!options.skipResources) {
111
+ if (options.resourcesPath) {
112
+ resourcesPath = options.resourcesPath;
113
+ } else {
114
+ // check if src folder exists and default to src/resources if it does, otherwise resources
115
+ const hasSrcFolder = fs.existsSync(path.join(projectRoot, "src"));
116
+ resourcesPath = hasSrcFolder ? "src/resources" : "resources";
117
+ }
118
+ }
119
+
106
120
  // determine route path
107
121
  let routePath: string | undefined;
108
122
  if (detectedFramework === "nextjs" && !options.skipRoute) {
@@ -155,6 +169,15 @@ const program = new Command()
155
169
  });
156
170
  }
157
171
 
172
+ if (!options.skipResources) {
173
+ prompts.push({
174
+ type: "input",
175
+ name: "resourcesPath",
176
+ message: "Resources directory path:",
177
+ default: resourcesPath,
178
+ });
179
+ }
180
+
158
181
  if (detectedFramework === "nextjs" && !options.skipRoute) {
159
182
  prompts.push({
160
183
  type: "input",
@@ -202,6 +225,9 @@ const program = new Command()
202
225
  if (!options.skipPrompts) {
203
226
  promptsPath = answers.promptsPath;
204
227
  }
228
+ if (!options.skipResources) {
229
+ resourcesPath = answers.resourcesPath;
230
+ }
205
231
  if (
206
232
  detectedFramework === "nextjs" &&
207
233
  !options.skipRoute &&
@@ -287,6 +313,7 @@ const program = new Command()
287
313
  framework: detectedFramework,
288
314
  toolsPath,
289
315
  promptsPath,
316
+ resourcesPath,
290
317
  routePath,
291
318
  packageManager,
292
319
  });
@@ -303,6 +330,11 @@ const program = new Command()
303
330
  console.log(` • ${promptsPath}/review-code.ts`);
304
331
  }
305
332
 
333
+ if (resourcesPath) {
334
+ console.log(` • ${resourcesPath}/(config)/app.ts`);
335
+ console.log(` • ${resourcesPath}/(users)/[userId]/profile.ts`);
336
+ }
337
+
306
338
  if (routePath) {
307
339
  console.log(` • ${routePath}/route.ts`);
308
340
  }