xmcp 0.7.0 → 0.7.1

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.
Files changed (155) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/package.json +2 -3
  4. package/src/auth/api-key.ts +0 -120
  5. package/src/auth/jwt.ts +0 -52
  6. package/src/cli/commands/create/__tests__/create.test.ts +0 -99
  7. package/src/cli/commands/create/index.ts +0 -74
  8. package/src/cli/commands/create/templates/index.ts +0 -4
  9. package/src/cli/commands/create/templates/prompt.ts +0 -30
  10. package/src/cli/commands/create/templates/resource.ts +0 -20
  11. package/src/cli/commands/create/templates/tool.ts +0 -34
  12. package/src/cli/commands/create/templates/widget.ts +0 -33
  13. package/src/cli/utils/naming.ts +0 -39
  14. package/src/cli.ts +0 -125
  15. package/src/client/headers.ts +0 -61
  16. package/src/client/index.ts +0 -180
  17. package/src/client/types.ts +0 -122
  18. package/src/client/utils.ts +0 -133
  19. package/src/cloudflare.ts +0 -6
  20. package/src/compiler/build-telemetry.ts +0 -88
  21. package/src/compiler/client/component-compiler.ts +0 -250
  22. package/src/compiler/client/transpile.ts +0 -21
  23. package/src/compiler/compiler-context.ts +0 -61
  24. package/src/compiler/config/__tests__/config.test.ts +0 -459
  25. package/src/compiler/config/index.ts +0 -62
  26. package/src/compiler/config/injection.ts +0 -210
  27. package/src/compiler/config/schemas/bundler.ts +0 -12
  28. package/src/compiler/config/schemas/experimental/index.ts +0 -22
  29. package/src/compiler/config/schemas/index.ts +0 -20
  30. package/src/compiler/config/schemas/paths.ts +0 -35
  31. package/src/compiler/config/schemas/template.ts +0 -80
  32. package/src/compiler/config/schemas/transport/http.ts +0 -116
  33. package/src/compiler/config/schemas/transport/stdio.ts +0 -31
  34. package/src/compiler/config/schemas/typescript.ts +0 -26
  35. package/src/compiler/config/utils.ts +0 -168
  36. package/src/compiler/generate-env-code.ts +0 -5
  37. package/src/compiler/generate-import-code.ts +0 -187
  38. package/src/compiler/generate-tools-code.ts +0 -174
  39. package/src/compiler/get-bundler-config/get-entries.ts +0 -44
  40. package/src/compiler/get-bundler-config/get-externals.ts +0 -114
  41. package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
  42. package/src/compiler/get-bundler-config/index.ts +0 -288
  43. package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
  44. package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
  45. package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
  46. package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
  47. package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
  48. package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
  49. package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
  50. package/src/compiler/index.ts +0 -484
  51. package/src/compiler/on-first-build.ts +0 -54
  52. package/src/compiler/parse-xmcp-config.ts +0 -200
  53. package/src/compiler/start-http-server.ts +0 -42
  54. package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
  55. package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
  56. package/src/compiler/utils/config-detection.ts +0 -34
  57. package/src/compiler/utils/path-utils.ts +0 -22
  58. package/src/compiler/watcher-recovery.ts +0 -72
  59. package/src/host-bridge.ts +0 -36
  60. package/src/index.ts +0 -94
  61. package/src/platforms/build-cloudflare-output.ts +0 -116
  62. package/src/platforms/build-vercel-output.ts +0 -131
  63. package/src/plugins/index.ts +0 -1
  64. package/src/plugins/x402/index.ts +0 -24
  65. package/src/runtime/adapters/express/index.ts +0 -75
  66. package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
  67. package/src/runtime/adapters/fastify/index.ts +0 -78
  68. package/src/runtime/adapters/nestjs/index.ts +0 -16
  69. package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
  70. package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
  71. package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
  72. package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
  73. package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
  74. package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
  75. package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
  76. package/src/runtime/adapters/nextjs/auth.ts +0 -265
  77. package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
  78. package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
  79. package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
  80. package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
  81. package/src/runtime/adapters/nextjs/index.ts +0 -121
  82. package/src/runtime/contexts/client-info-context.ts +0 -16
  83. package/src/runtime/contexts/http-request-context.ts +0 -21
  84. package/src/runtime/contexts/http-transport-context.ts +0 -18
  85. package/src/runtime/headers.ts +0 -42
  86. package/src/runtime/middlewares/utils.ts +0 -72
  87. package/src/runtime/platforms/cloudflare/cors.ts +0 -44
  88. package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
  89. package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
  90. package/src/runtime/platforms/cloudflare/types.ts +0 -23
  91. package/src/runtime/platforms/cloudflare/worker.ts +0 -270
  92. package/src/runtime/templates/home.ts +0 -746
  93. package/src/runtime/transports/http/base-streamable-http.ts +0 -46
  94. package/src/runtime/transports/http/cors/headers.ts +0 -58
  95. package/src/runtime/transports/http/cors/index.ts +0 -34
  96. package/src/runtime/transports/http/index.ts +0 -78
  97. package/src/runtime/transports/http/stateless-streamable-http.ts +0 -353
  98. package/src/runtime/transports/http/web-stateless-http.ts +0 -288
  99. package/src/runtime/transports/stdio/index.ts +0 -109
  100. package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
  101. package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
  102. package/src/runtime/utils/client-info.ts +0 -114
  103. package/src/runtime/utils/elicitation.ts +0 -396
  104. package/src/runtime/utils/ext-apps-registry.ts +0 -151
  105. package/src/runtime/utils/mcp-app-protocol.ts +0 -16
  106. package/src/runtime/utils/mcp-app-types.ts +0 -113
  107. package/src/runtime/utils/mcp-host-bridge.ts +0 -473
  108. package/src/runtime/utils/path-to-tool-name.ts +0 -69
  109. package/src/runtime/utils/prompt-loader.ts +0 -151
  110. package/src/runtime/utils/prompts.ts +0 -69
  111. package/src/runtime/utils/react/generate-html.ts +0 -69
  112. package/src/runtime/utils/react/index.ts +0 -6
  113. package/src/runtime/utils/request-tool-names.ts +0 -48
  114. package/src/runtime/utils/resource-loader.ts +0 -151
  115. package/src/runtime/utils/resources.ts +0 -331
  116. package/src/runtime/utils/server.ts +0 -107
  117. package/src/runtime/utils/tool-loader.ts +0 -149
  118. package/src/runtime/utils/tools.ts +0 -183
  119. package/src/runtime/utils/transformers/prompt.ts +0 -120
  120. package/src/runtime/utils/transformers/resource.ts +0 -196
  121. package/src/runtime/utils/transformers/tool.ts +0 -400
  122. package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
  123. package/src/runtime/utils/ui/flatten-meta.ts +0 -44
  124. package/src/runtime/utils/ui/split-meta.ts +0 -78
  125. package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
  126. package/src/runtime/utils/validators/index.ts +0 -138
  127. package/src/telemetry/ci-info.ts +0 -6
  128. package/src/telemetry/debug.ts +0 -8
  129. package/src/telemetry/events/definitions.ts +0 -52
  130. package/src/telemetry/events/detached-flush.ts +0 -83
  131. package/src/telemetry/events/post-payload.ts +0 -141
  132. package/src/telemetry/events/tracker.ts +0 -281
  133. package/src/telemetry/index.ts +0 -7
  134. package/src/telemetry/metadata.ts +0 -49
  135. package/src/telemetry/project-id.ts +0 -35
  136. package/src/telemetry/storage.ts +0 -218
  137. package/src/types/adapter.d.ts +0 -5
  138. package/src/types/client-info.ts +0 -20
  139. package/src/types/declarations.ts +0 -37
  140. package/src/types/injected.d.ts +0 -62
  141. package/src/types/middleware.ts +0 -19
  142. package/src/types/prompt.ts +0 -6
  143. package/src/types/resource.ts +0 -15
  144. package/src/types/tool.ts +0 -192
  145. package/src/types/ui-meta.ts +0 -42
  146. package/src/utils/cli-icons.ts +0 -5
  147. package/src/utils/constants.ts +0 -31
  148. package/src/utils/context.ts +0 -105
  149. package/src/utils/detect-package-manager.ts +0 -46
  150. package/src/utils/file-watcher.ts +0 -66
  151. package/src/utils/fs-utils.ts +0 -16
  152. package/src/utils/path-validation.ts +0 -66
  153. package/src/utils/port-utils.ts +0 -43
  154. package/src/utils/spawn-process.ts +0 -49
  155. package/src/utils/subscribable.ts +0 -62
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "xmcp",
3
3
  "description": "The MCP framework",
4
- "version": "0.7.0",
4
+ "version": "0.7.1",
5
5
  "author": {
6
6
  "name": "xmcp",
7
7
  "email": "support@xmcp.dev",
@@ -77,8 +77,7 @@
77
77
  }
78
78
  },
79
79
  "files": [
80
- "dist",
81
- "src"
80
+ "dist"
82
81
  ],
83
82
  "dependencies": {
84
83
  "@modelcontextprotocol/sdk": "^1.26.0",
@@ -1,120 +0,0 @@
1
- import { Request, Response, NextFunction, RequestHandler } from "express";
2
- import { z } from "zod/v3";
3
-
4
- const apiKeyAuthMiddlewareConfigSchema = z
5
- .object({
6
- apiKey: z.string().optional(),
7
- headerName: z.string().optional(),
8
- validateApiKey: z
9
- .function()
10
- .args(z.string())
11
- .returns(z.promise(z.boolean()))
12
- .optional(),
13
- })
14
- .strict()
15
- .refine(
16
- (config) =>
17
- config.apiKey !== undefined || config.validateApiKey !== undefined,
18
- {
19
- message: "Either 'apiKey' or 'validateApiKey' must be provided",
20
- }
21
- )
22
- .refine(
23
- (config) =>
24
- !(config.apiKey !== undefined && config.validateApiKey !== undefined),
25
- {
26
- message:
27
- "'apiKey' and 'validateApiKey' are mutually exclusive - provide only one",
28
- }
29
- );
30
-
31
- const errorMessage = "Unauthorized: Missing or invalid API key";
32
-
33
- type StaticApiKeyConfig = {
34
- /** The static API key to validate against */
35
- apiKey: string;
36
- /** Optional header name to read the API key from. Defaults to 'x-api-key' */
37
- headerName?: string;
38
- };
39
-
40
- type CustomValidationConfig = {
41
- /** Optional header name to read the API key from. Defaults to 'x-api-key' */
42
- headerName?: string;
43
- /** Custom validation function that receives the API key and returns a Promise<boolean> */
44
- validateApiKey: (key: string) => Promise<boolean>;
45
- };
46
-
47
- export function apiKeyAuthMiddleware(
48
- config: StaticApiKeyConfig
49
- ): RequestHandler;
50
-
51
- export function apiKeyAuthMiddleware(
52
- config: CustomValidationConfig
53
- ): RequestHandler;
54
-
55
- /**
56
- * Middleware to authenticate requests using an API key.
57
- * @param config - Configuration object containing either a static API key or a function to validate the API key.
58
- * @returns Express middleware function.
59
- *
60
- * @example
61
- * ```ts
62
- * const middleware = apiKeyAuthMiddleware({
63
- * apiKey: process.env.API_KEY!,
64
- * });
65
- * ```
66
- *
67
- * @example
68
- * ```ts
69
- * const middleware = apiKeyAuthMiddleware({
70
- * validateApiKey: async (key) => {
71
- * return key === process.env.API_KEY!;
72
- * },
73
- * });
74
- * ```
75
- */
76
- export function apiKeyAuthMiddleware(
77
- config: StaticApiKeyConfig | CustomValidationConfig
78
- ): RequestHandler {
79
- // To do, we can maybe work on better error handling here, like typing the error messages etc
80
- const response = apiKeyAuthMiddlewareConfigSchema.safeParse(config);
81
- if (!response.success) {
82
- const hasApiKey = "apiKey" in config;
83
- const hasValidateApiKey = "validateApiKey" in config;
84
-
85
- if (hasApiKey && hasValidateApiKey) {
86
- throw new Error(
87
- "'apiKey' and 'validateApiKey' are mutually exclusive - provide only one"
88
- );
89
- } else if (!hasApiKey && !hasValidateApiKey) {
90
- throw new Error("Either 'apiKey' or 'validateApiKey' must be provided");
91
- } else {
92
- throw new Error(`Invalid configuration: ${response.error.message}`);
93
- }
94
- }
95
-
96
- const headerName = config.headerName ?? "x-api-key";
97
- const apiKey = "apiKey" in config ? config.apiKey : undefined;
98
- const validateApiKey =
99
- "validateApiKey" in config ? config.validateApiKey : undefined;
100
-
101
- return async (req: Request, res: Response, next: NextFunction) => {
102
- const apiKeyHeader = req.header(headerName);
103
- if (!apiKeyHeader) {
104
- res.status(401).json({ error: errorMessage });
105
- return;
106
- }
107
- if ("apiKey" in config && apiKeyHeader !== apiKey) {
108
- res.status(401).json({ error: errorMessage });
109
- return;
110
- }
111
- if (validateApiKey) {
112
- const isValid = await validateApiKey(apiKeyHeader);
113
- if (!isValid) {
114
- res.status(401).json({ error: errorMessage });
115
- return;
116
- }
117
- }
118
- next();
119
- };
120
- }
package/src/auth/jwt.ts DELETED
@@ -1,52 +0,0 @@
1
- import { Request, Response, NextFunction, RequestHandler } from "express";
2
- import jwt, { JwtPayload, VerifyOptions } from "jsonwebtoken";
3
-
4
- export interface JWTAuthMiddlewareConfig extends VerifyOptions {
5
- secret: string;
6
- }
7
-
8
- /**
9
- * Middleware to authenticate requests using a JWT.
10
- * @param config - Configuration object containing the JWT secret and verify options.
11
- * @returns Express middleware function.
12
- *
13
- * @example
14
- * ```ts
15
- * const middleware = jwtAuthMiddleware({
16
- * secret: process.env.JWT_SECRET!,
17
- * algorithms: ["HS256"],
18
- * issuer: "https://example.com",
19
- * audience: "https://example.com",
20
- * subject: "user-id",
21
- * expiresIn: "1h",
22
- * notBefore: "1h",
23
- * clockTolerance: 30,
24
- * });
25
- * ```
26
- */
27
- export function jwtAuthMiddleware(
28
- config: JWTAuthMiddlewareConfig
29
- ): RequestHandler {
30
- return (req: Request, res: Response, next: NextFunction) => {
31
- const authHeader = req.header("Authorization");
32
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
33
- res.status(401).json({
34
- error: "Unauthorized: Missing or malformed Authorization header",
35
- });
36
- return;
37
- }
38
- const token = authHeader.slice("Bearer ".length).trim();
39
- if (!token) {
40
- res.status(401).json({ error: "Unauthorized: Missing access token" });
41
- return;
42
- }
43
- try {
44
- const { secret, ...verifyOptions } = config;
45
- const decoded = jwt.verify(token, secret, verifyOptions) as JwtPayload;
46
- (req as any).user = decoded;
47
- next();
48
- } catch (err) {
49
- res.status(401).json({ error: "Unauthorized: Invalid or expired token" });
50
- }
51
- };
52
- }
@@ -1,99 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import fs from "node:fs";
3
- import path from "node:path";
4
- import os from "node:os";
5
- import { beforeEach, afterEach, describe, it } from "node:test";
6
- import { runCreate, type CreateType } from "../index";
7
-
8
- function readCreatedFile(dir: string, relativePath: string) {
9
- const filePath = path.join(dir, relativePath);
10
- return fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf8") : "";
11
- }
12
-
13
- describe("xmcp create command", () => {
14
- let tempDir: string;
15
- let originalCwd: string;
16
-
17
- beforeEach(() => {
18
- tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "xmcp-create-"));
19
- originalCwd = process.cwd();
20
- process.chdir(tempDir);
21
- });
22
-
23
- afterEach(() => {
24
- process.chdir(originalCwd);
25
- fs.rmSync(tempDir, { recursive: true, force: true });
26
- });
27
-
28
- it("creates a tool in default directory", async () => {
29
- await runCreate({ type: "tool", name: "my-tool" });
30
-
31
- const content = readCreatedFile(tempDir, "src/tools/my-tool.ts");
32
- assert.match(content, /export const metadata: ToolMetadata/);
33
- assert.match(content, /name: "my-tool"/);
34
- assert.match(content, /export default function myTool/);
35
- });
36
-
37
- it("creates a resource in default directory", async () => {
38
- await runCreate({ type: "resource", name: "user-data" });
39
-
40
- const content = readCreatedFile(tempDir, "src/resources/user-data.ts");
41
- assert.match(content, /export const metadata: ResourceMetadata/);
42
- assert.match(content, /name: "user-data"/);
43
- assert.match(content, /export default function userData/);
44
- });
45
-
46
- it("creates a prompt in default directory", async () => {
47
- await runCreate({ type: "prompt", name: "code-review" });
48
-
49
- const content = readCreatedFile(tempDir, "src/prompts/code-review.ts");
50
- assert.match(content, /export const metadata: PromptMetadata/);
51
- assert.match(content, /name: "code-review"/);
52
- assert.match(content, /export default function codeReview/);
53
- });
54
-
55
- it("creates a widget with .tsx extension", async () => {
56
- await runCreate({ type: "widget", name: "dashboard" });
57
-
58
- const content = readCreatedFile(tempDir, "src/tools/dashboard.tsx");
59
- assert.match(content, /import.*useState.*from "react"/);
60
- assert.match(content, /export const metadata: ToolMetadata/);
61
- assert.match(content, /export default function dashboard/);
62
- });
63
-
64
- it("creates in custom directory with dir option", async () => {
65
- await runCreate({
66
- type: "tool",
67
- name: "custom",
68
- directory: "lib/custom-tools",
69
- });
70
-
71
- const content = readCreatedFile(tempDir, "lib/custom-tools/custom.ts");
72
- assert.match(content, /export const metadata: ToolMetadata/);
73
- });
74
-
75
- it("creates in nested path from name", async () => {
76
- await runCreate({ type: "tool", name: "api/users/get-user" });
77
-
78
- const content = readCreatedFile(tempDir, "src/tools/api/users/get-user.ts");
79
- assert.match(content, /name: "get-user"/);
80
- assert.match(content, /export default function getUser/);
81
- });
82
-
83
- it("errors when file already exists", async () => {
84
- await runCreate({ type: "tool", name: "existing" });
85
-
86
- await assert.rejects(
87
- async () => runCreate({ type: "tool", name: "existing" }),
88
- /File already exists/
89
- );
90
- });
91
-
92
- it("converts camelCase names to kebab-case files", async () => {
93
- await runCreate({ type: "tool", name: "myAwesomeTool" });
94
-
95
- const content = readCreatedFile(tempDir, "src/tools/my-awesome-tool.ts");
96
- assert.match(content, /name: "my-awesome-tool"/);
97
- assert.match(content, /export default function myAwesomeTool/);
98
- });
99
- });
@@ -1,74 +0,0 @@
1
- import fs from "node:fs";
2
- import path from "node:path";
3
- import { toKebabCase } from "../../utils/naming";
4
- import {
5
- generateToolTemplate,
6
- generateResourceTemplate,
7
- generatePromptTemplate,
8
- generateWidgetTemplate,
9
- } from "./templates";
10
-
11
- export type CreateType = "tool" | "resource" | "prompt" | "widget";
12
-
13
- export interface CreateOptions {
14
- type: CreateType;
15
- name: string;
16
- directory?: string;
17
- }
18
-
19
- const DEFAULT_DIRECTORIES: Record<CreateType, string> = {
20
- tool: "src/tools",
21
- resource: "src/resources",
22
- prompt: "src/prompts",
23
- widget: "src/tools",
24
- };
25
-
26
- const FILE_EXTENSIONS: Record<CreateType, string> = {
27
- tool: ".ts",
28
- resource: ".ts",
29
- prompt: ".ts",
30
- widget: ".tsx",
31
- };
32
-
33
- const TEMPLATE_GENERATORS: Record<CreateType, (name: string) => string> = {
34
- tool: generateToolTemplate,
35
- resource: generateResourceTemplate,
36
- prompt: generatePromptTemplate,
37
- widget: generateWidgetTemplate,
38
- };
39
-
40
- export async function runCreate(options: CreateOptions): Promise<string> {
41
- const { type, name, directory } = options;
42
-
43
- const baseDir = directory ?? DEFAULT_DIRECTORIES[type];
44
- const resolvedDir = path.resolve(process.cwd(), baseDir);
45
-
46
- // Parse the name for nested paths (e.g., "api/users" -> creates in api/users/)
47
- const nameParts = name.split("/");
48
- const fileName = nameParts.pop()!;
49
- const subPath = nameParts.join("/");
50
-
51
- const targetDir = subPath ? path.join(resolvedDir, subPath) : resolvedDir;
52
-
53
- // Create directory if it doesn't exist
54
- fs.mkdirSync(targetDir, { recursive: true });
55
-
56
- const extension = FILE_EXTENSIONS[type];
57
- const outputPath = path.join(
58
- targetDir,
59
- `${toKebabCase(fileName)}${extension}`
60
- );
61
-
62
- // Check if file already exists
63
- if (fs.existsSync(outputPath)) {
64
- throw new Error(
65
- `File already exists: ${path.relative(process.cwd(), outputPath)}`
66
- );
67
- }
68
-
69
- const generateTemplate = TEMPLATE_GENERATORS[type];
70
- const content = generateTemplate(fileName);
71
- fs.writeFileSync(outputPath, content);
72
-
73
- return path.relative(process.cwd(), outputPath);
74
- }
@@ -1,4 +0,0 @@
1
- export { generateToolTemplate } from "./tool";
2
- export { generateResourceTemplate } from "./resource";
3
- export { generatePromptTemplate } from "./prompt";
4
- export { generateWidgetTemplate } from "./widget";
@@ -1,30 +0,0 @@
1
- import { pascalCase, toCamelCase, toKebabCase } from "../../../utils/naming";
2
-
3
- export function generatePromptTemplate(name: string): string {
4
- const functionName = toCamelCase(name);
5
- const kebabName = toKebabCase(name);
6
-
7
- return `import { z } from "zod";
8
- import { type InferSchema, type PromptMetadata } from "xmcp";
9
-
10
- // Define the schema for prompt parameters
11
- export const schema = {
12
- // Add your parameters here
13
- // example: z.string().describe("Description of the parameter"),
14
- };
15
-
16
- // Define prompt metadata
17
- export const metadata: PromptMetadata = {
18
- name: "${kebabName}",
19
- title: "${pascalCase(name)}",
20
- description: "TODO: Add description",
21
- role: "user",
22
- };
23
-
24
- // Prompt implementation
25
- export default function ${functionName}(params: InferSchema<typeof schema>) {
26
- // TODO: Implement your prompt logic here
27
- return \`Your prompt content here\`;
28
- }
29
- `;
30
- }
@@ -1,20 +0,0 @@
1
- import { pascalCase, toCamelCase, toKebabCase } from "../../../utils/naming";
2
-
3
- export function generateResourceTemplate(name: string): string {
4
- const functionName = toCamelCase(name);
5
- const kebabName = toKebabCase(name);
6
-
7
- return `import { type ResourceMetadata } from "xmcp";
8
-
9
- export const metadata: ResourceMetadata = {
10
- name: "${kebabName}",
11
- title: "${pascalCase(name)}",
12
- description: "TODO: Add description",
13
- };
14
-
15
- export default function ${functionName}() {
16
- // TODO: Implement your resource logic here
17
- return "Resource data for ${name}";
18
- }
19
- `;
20
- }
@@ -1,34 +0,0 @@
1
- import { pascalCase, toCamelCase, toKebabCase } from "../../../utils/naming";
2
-
3
- export function generateToolTemplate(name: string): string {
4
- const functionName = toCamelCase(name);
5
- const kebabName = toKebabCase(name);
6
-
7
- return `import { z } from "zod";
8
- import { type ToolMetadata, type InferSchema } from "xmcp";
9
-
10
- // Define the schema for tool parameters
11
- export const schema = {
12
- // Add your parameters here
13
- // example: z.string().describe("Description of the parameter"),
14
- };
15
-
16
- // Define tool metadata
17
- export const metadata: ToolMetadata = {
18
- name: "${kebabName}",
19
- description: "TODO: Add description",
20
- annotations: {
21
- title: "${pascalCase(name)}",
22
- readOnlyHint: true,
23
- destructiveHint: false,
24
- idempotentHint: true,
25
- },
26
- };
27
-
28
- // Tool implementation
29
- export default function ${functionName}(params: InferSchema<typeof schema>) {
30
- // TODO: Implement your tool logic here
31
- return "Hello from ${name}!";
32
- }
33
- `;
34
- }
@@ -1,33 +0,0 @@
1
- import { pascalCase, toCamelCase, toKebabCase } from "../../../utils/naming";
2
-
3
- export function generateWidgetTemplate(name: string): string {
4
- const functionName = toCamelCase(name);
5
- const kebabName = toKebabCase(name);
6
-
7
- return `import { type ToolMetadata } from "xmcp";
8
- import { useState } from "react";
9
-
10
- export const metadata: ToolMetadata = {
11
- name: "${kebabName}",
12
- description: "${pascalCase(name)} Widget",
13
- _meta: {
14
- ui: {
15
- csp: {
16
- connectDomains: [],
17
- },
18
- },
19
- },
20
- };
21
-
22
- export default function ${functionName}() {
23
- const [state, setState] = useState<string | null>(null);
24
-
25
- return (
26
- <div>
27
- <h1>${pascalCase(name)}</h1>
28
- <p>TODO: Implement your widget UI here</p>
29
- </div>
30
- );
31
- }
32
- `;
33
- }
@@ -1,39 +0,0 @@
1
- export function pascalCase(value: string): string {
2
- return value
3
- .split(/[^a-zA-Z0-9]+/)
4
- .filter(Boolean)
5
- .map((chunk) => chunk[0].toUpperCase() + chunk.slice(1))
6
- .join("");
7
- }
8
-
9
- export function toCamelCase(value: string): string {
10
- // First, split camelCase/PascalCase into words, then handle kebab/snake case
11
- const normalized = value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
12
-
13
- const segments = normalized
14
- .split(/[^a-zA-Z0-9]+/)
15
- .filter(Boolean)
16
- .map((segment, index) => {
17
- if (index === 0) {
18
- return segment.toLowerCase();
19
- }
20
- return segment[0].toUpperCase() + segment.slice(1).toLowerCase();
21
- })
22
- .join("");
23
-
24
- if (!segments) {
25
- return "item";
26
- }
27
-
28
- return /^[0-9]/.test(segments) ? `_${segments}` : segments;
29
- }
30
-
31
- export function toKebabCase(value: string): string {
32
- return (
33
- value
34
- .replace(/([a-z])([A-Z])/g, "$1-$2")
35
- .replace(/[^a-zA-Z0-9]+/g, "-")
36
- .replace(/^-+|-+$/g, "")
37
- .toLowerCase() || "item"
38
- );
39
- }
package/src/cli.ts DELETED
@@ -1,125 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import { compile } from "./compiler";
4
- import { buildVercelOutput } from "./platforms/build-vercel-output";
5
- import { buildCloudflareOutput } from "./platforms/build-cloudflare-output";
6
- import chalk from "chalk";
7
- import { xmcpLogo } from "./utils/cli-icons";
8
- import {
9
- compilerContext,
10
- compilerContextProvider,
11
- } from "./compiler/compiler-context";
12
- import { runCreate, type CreateType } from "./cli/commands/create";
13
-
14
- const program = new Command();
15
-
16
- program.name("xmcp").description("The MCP framework CLI").version("0.0.1");
17
-
18
- program
19
- .command("dev")
20
- .description("Start development mode")
21
- .option("--cf", "Enable Cloudflare Workers output in development")
22
- .action(async (options) => {
23
- console.log(`${xmcpLogo} Starting development mode...`);
24
- const isCloudflareDev = options.cf || process.env.CF_PAGES === "1";
25
- await compilerContextProvider(
26
- {
27
- mode: "development",
28
- platforms: {
29
- cloudflare: isCloudflareDev,
30
- },
31
- },
32
- async () => {
33
- await compile();
34
- }
35
- );
36
- });
37
-
38
- program
39
- .command("build")
40
- .description("Build for production")
41
- .option("--vercel", "Build for Vercel deployment")
42
- .option("--cf", "Build for Cloudflare Workers deployment")
43
- .action(async (options) => {
44
- console.log(`${xmcpLogo} Building for production...`);
45
- const isVercelBuild = options.vercel || process.env.VERCEL === "1";
46
- const isCloudflareBuild = options.cf || process.env.CF_PAGES === "1";
47
-
48
- await compilerContextProvider(
49
- {
50
- mode: "production",
51
- platforms: {
52
- vercel: isVercelBuild,
53
- cloudflare: isCloudflareBuild,
54
- },
55
- },
56
- async () => {
57
- await compile({
58
- onBuild: async () => {
59
- const { xmcpConfig } = compilerContext.getContext();
60
- const isUsingAdapter = !!xmcpConfig?.experimental?.adapter;
61
-
62
- if (isVercelBuild && !isUsingAdapter) {
63
- console.log(`${xmcpLogo} Building for Vercel...`);
64
- try {
65
- await buildVercelOutput();
66
- } catch (error) {
67
- console.error(
68
- chalk.red("❌ Failed to create Vercel output structure:"),
69
- error
70
- );
71
- }
72
- }
73
- if (isCloudflareBuild) {
74
- console.log(`${xmcpLogo} Building for Cloudflare Workers...`);
75
- try {
76
- await buildCloudflareOutput();
77
- } catch (error) {
78
- console.error(
79
- chalk.red(
80
- "❌ Failed to create Cloudflare output structure:"
81
- ),
82
- error
83
- );
84
- }
85
- }
86
- },
87
- });
88
- }
89
- );
90
- });
91
-
92
- const VALID_CREATE_TYPES: CreateType[] = [
93
- "tool",
94
- "resource",
95
- "prompt",
96
- "widget",
97
- ];
98
-
99
- program
100
- .command("create <type> <name>")
101
- .description("Scaffold a new tool, resource, prompt, or widget")
102
- .option("-d, --dir <path>", "Custom output directory")
103
- .action(async (type: string, name: string, options: { dir?: string }) => {
104
- if (!VALID_CREATE_TYPES.includes(type as CreateType)) {
105
- console.error(chalk.red(`Invalid type "${type}".`));
106
- console.error(`Valid types: ${VALID_CREATE_TYPES.join(", ")}`);
107
- process.exit(1);
108
- }
109
-
110
- try {
111
- const outputPath = await runCreate({
112
- type: type as CreateType,
113
- name,
114
- directory: options.dir,
115
- });
116
- console.log(`${xmcpLogo} Created ${type} "${name}" -> ${outputPath}`);
117
- } catch (error) {
118
- console.error(
119
- chalk.red(error instanceof Error ? error.message : String(error))
120
- );
121
- process.exit(1);
122
- }
123
- });
124
-
125
- program.parse();