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.
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -3
- package/src/auth/api-key.ts +0 -120
- package/src/auth/jwt.ts +0 -52
- package/src/cli/commands/create/__tests__/create.test.ts +0 -99
- package/src/cli/commands/create/index.ts +0 -74
- package/src/cli/commands/create/templates/index.ts +0 -4
- package/src/cli/commands/create/templates/prompt.ts +0 -30
- package/src/cli/commands/create/templates/resource.ts +0 -20
- package/src/cli/commands/create/templates/tool.ts +0 -34
- package/src/cli/commands/create/templates/widget.ts +0 -33
- package/src/cli/utils/naming.ts +0 -39
- package/src/cli.ts +0 -125
- package/src/client/headers.ts +0 -61
- package/src/client/index.ts +0 -180
- package/src/client/types.ts +0 -122
- package/src/client/utils.ts +0 -133
- package/src/cloudflare.ts +0 -6
- package/src/compiler/build-telemetry.ts +0 -88
- package/src/compiler/client/component-compiler.ts +0 -250
- package/src/compiler/client/transpile.ts +0 -21
- package/src/compiler/compiler-context.ts +0 -61
- package/src/compiler/config/__tests__/config.test.ts +0 -459
- package/src/compiler/config/index.ts +0 -62
- package/src/compiler/config/injection.ts +0 -210
- package/src/compiler/config/schemas/bundler.ts +0 -12
- package/src/compiler/config/schemas/experimental/index.ts +0 -22
- package/src/compiler/config/schemas/index.ts +0 -20
- package/src/compiler/config/schemas/paths.ts +0 -35
- package/src/compiler/config/schemas/template.ts +0 -80
- package/src/compiler/config/schemas/transport/http.ts +0 -116
- package/src/compiler/config/schemas/transport/stdio.ts +0 -31
- package/src/compiler/config/schemas/typescript.ts +0 -26
- package/src/compiler/config/utils.ts +0 -168
- package/src/compiler/generate-env-code.ts +0 -5
- package/src/compiler/generate-import-code.ts +0 -187
- package/src/compiler/generate-tools-code.ts +0 -174
- package/src/compiler/get-bundler-config/get-entries.ts +0 -44
- package/src/compiler/get-bundler-config/get-externals.ts +0 -114
- package/src/compiler/get-bundler-config/get-injected-variables.ts +0 -46
- package/src/compiler/get-bundler-config/index.ts +0 -288
- package/src/compiler/get-bundler-config/plugins/index.ts +0 -140
- package/src/compiler/get-bundler-config/plugins/types/express.ts +0 -3
- package/src/compiler/get-bundler-config/plugins/types/fastify.ts +0 -4
- package/src/compiler/get-bundler-config/plugins/types/index.ts +0 -5
- package/src/compiler/get-bundler-config/plugins/types/nest.ts +0 -65
- package/src/compiler/get-bundler-config/plugins/types/next.ts +0 -52
- package/src/compiler/get-bundler-config/resolve-tsconfig-paths.ts +0 -51
- package/src/compiler/index.ts +0 -484
- package/src/compiler/on-first-build.ts +0 -54
- package/src/compiler/parse-xmcp-config.ts +0 -200
- package/src/compiler/start-http-server.ts +0 -42
- package/src/compiler/utils/__tests__/config-detection.test.ts +0 -307
- package/src/compiler/utils/__tests__/path-utils.test.ts +0 -137
- package/src/compiler/utils/config-detection.ts +0 -34
- package/src/compiler/utils/path-utils.ts +0 -22
- package/src/compiler/watcher-recovery.ts +0 -72
- package/src/host-bridge.ts +0 -36
- package/src/index.ts +0 -94
- package/src/platforms/build-cloudflare-output.ts +0 -116
- package/src/platforms/build-vercel-output.ts +0 -131
- package/src/plugins/index.ts +0 -1
- package/src/plugins/x402/index.ts +0 -24
- package/src/runtime/adapters/express/index.ts +0 -75
- package/src/runtime/adapters/fastify/__tests__/fastify.test.ts +0 -115
- package/src/runtime/adapters/fastify/index.ts +0 -78
- package/src/runtime/adapters/nestjs/index.ts +0 -16
- package/src/runtime/adapters/nestjs/xmcp.controller.ts +0 -34
- package/src/runtime/adapters/nestjs/xmcp.guard.ts +0 -101
- package/src/runtime/adapters/nestjs/xmcp.oauth.controller.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.oauth.module.ts +0 -21
- package/src/runtime/adapters/nestjs/xmcp.oauth.service.ts +0 -36
- package/src/runtime/adapters/nestjs/xmcp.service.ts +0 -96
- package/src/runtime/adapters/nestjs/xmcp.utils.ts +0 -11
- package/src/runtime/adapters/nextjs/auth.ts +0 -265
- package/src/runtime/adapters/nextjs/handler/error-handler.ts +0 -67
- package/src/runtime/adapters/nextjs/handler/node-to-web-adapter.ts +0 -143
- package/src/runtime/adapters/nextjs/handler/request-converter.ts +0 -74
- package/src/runtime/adapters/nextjs/handler/server-lifecycle.ts +0 -69
- package/src/runtime/adapters/nextjs/index.ts +0 -121
- package/src/runtime/contexts/client-info-context.ts +0 -16
- package/src/runtime/contexts/http-request-context.ts +0 -21
- package/src/runtime/contexts/http-transport-context.ts +0 -18
- package/src/runtime/headers.ts +0 -42
- package/src/runtime/middlewares/utils.ts +0 -72
- package/src/runtime/platforms/cloudflare/cors.ts +0 -44
- package/src/runtime/platforms/cloudflare/middlewares/api-key.ts +0 -102
- package/src/runtime/platforms/cloudflare/middlewares/jwt.ts +0 -127
- package/src/runtime/platforms/cloudflare/types.ts +0 -23
- package/src/runtime/platforms/cloudflare/worker.ts +0 -270
- package/src/runtime/templates/home.ts +0 -746
- package/src/runtime/transports/http/base-streamable-http.ts +0 -46
- package/src/runtime/transports/http/cors/headers.ts +0 -58
- package/src/runtime/transports/http/cors/index.ts +0 -34
- package/src/runtime/transports/http/index.ts +0 -78
- package/src/runtime/transports/http/stateless-streamable-http.ts +0 -353
- package/src/runtime/transports/http/web-stateless-http.ts +0 -288
- package/src/runtime/transports/stdio/index.ts +0 -109
- package/src/runtime/utils/__tests__/client-info.test.ts +0 -146
- package/src/runtime/utils/__tests__/tool-extra.test.ts +0 -239
- package/src/runtime/utils/client-info.ts +0 -114
- package/src/runtime/utils/elicitation.ts +0 -396
- package/src/runtime/utils/ext-apps-registry.ts +0 -151
- package/src/runtime/utils/mcp-app-protocol.ts +0 -16
- package/src/runtime/utils/mcp-app-types.ts +0 -113
- package/src/runtime/utils/mcp-host-bridge.ts +0 -473
- package/src/runtime/utils/path-to-tool-name.ts +0 -69
- package/src/runtime/utils/prompt-loader.ts +0 -151
- package/src/runtime/utils/prompts.ts +0 -69
- package/src/runtime/utils/react/generate-html.ts +0 -69
- package/src/runtime/utils/react/index.ts +0 -6
- package/src/runtime/utils/request-tool-names.ts +0 -48
- package/src/runtime/utils/resource-loader.ts +0 -151
- package/src/runtime/utils/resources.ts +0 -331
- package/src/runtime/utils/server.ts +0 -107
- package/src/runtime/utils/tool-loader.ts +0 -149
- package/src/runtime/utils/tools.ts +0 -183
- package/src/runtime/utils/transformers/prompt.ts +0 -120
- package/src/runtime/utils/transformers/resource.ts +0 -196
- package/src/runtime/utils/transformers/tool.ts +0 -400
- package/src/runtime/utils/ui/__tests__/split-meta.test.ts +0 -803
- package/src/runtime/utils/ui/flatten-meta.ts +0 -44
- package/src/runtime/utils/ui/split-meta.ts +0 -78
- package/src/runtime/utils/utils/resource-uri-composer.ts +0 -204
- package/src/runtime/utils/validators/index.ts +0 -138
- package/src/telemetry/ci-info.ts +0 -6
- package/src/telemetry/debug.ts +0 -8
- package/src/telemetry/events/definitions.ts +0 -52
- package/src/telemetry/events/detached-flush.ts +0 -83
- package/src/telemetry/events/post-payload.ts +0 -141
- package/src/telemetry/events/tracker.ts +0 -281
- package/src/telemetry/index.ts +0 -7
- package/src/telemetry/metadata.ts +0 -49
- package/src/telemetry/project-id.ts +0 -35
- package/src/telemetry/storage.ts +0 -218
- package/src/types/adapter.d.ts +0 -5
- package/src/types/client-info.ts +0 -20
- package/src/types/declarations.ts +0 -37
- package/src/types/injected.d.ts +0 -62
- package/src/types/middleware.ts +0 -19
- package/src/types/prompt.ts +0 -6
- package/src/types/resource.ts +0 -15
- package/src/types/tool.ts +0 -192
- package/src/types/ui-meta.ts +0 -42
- package/src/utils/cli-icons.ts +0 -5
- package/src/utils/constants.ts +0 -31
- package/src/utils/context.ts +0 -105
- package/src/utils/detect-package-manager.ts +0 -46
- package/src/utils/file-watcher.ts +0 -66
- package/src/utils/fs-utils.ts +0 -16
- package/src/utils/path-validation.ts +0 -66
- package/src/utils/port-utils.ts +0 -43
- package/src/utils/spawn-process.ts +0 -49
- package/src/utils/subscribable.ts +0 -62
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from "fs";
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import {
|
|
4
|
-
getResolvedHttpConfig,
|
|
5
|
-
getResolvedCorsConfig,
|
|
6
|
-
getResolvedPathsConfig,
|
|
7
|
-
getResolvedTemplateConfig,
|
|
8
|
-
getResolvedExperimentalConfig,
|
|
9
|
-
getResolvedTypescriptConfig,
|
|
10
|
-
} from "./utils";
|
|
11
|
-
import type { ResolvedHttpConfig, XmcpConfigOutputSchema } from "./index";
|
|
12
|
-
import type { HttpTransportConfig } from "./schemas/transport/http";
|
|
13
|
-
|
|
14
|
-
export function injectHttpVariables(
|
|
15
|
-
httpConfig: HttpTransportConfig | boolean | undefined,
|
|
16
|
-
mode: string
|
|
17
|
-
) {
|
|
18
|
-
const resolvedConfig = getResolvedHttpConfig(httpConfig);
|
|
19
|
-
if (!resolvedConfig) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
HTTP_CONFIG: JSON.stringify({
|
|
25
|
-
port: resolvedConfig.port,
|
|
26
|
-
host: resolvedConfig.host,
|
|
27
|
-
bodySizeLimit: resolvedConfig.bodySizeLimit,
|
|
28
|
-
endpoint: resolvedConfig.endpoint,
|
|
29
|
-
debug: mode === "development",
|
|
30
|
-
}),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type HttpVariables = ReturnType<typeof injectHttpVariables>;
|
|
35
|
-
|
|
36
|
-
export function injectCorsVariables(httpConfig: ResolvedHttpConfig) {
|
|
37
|
-
const corsConfig = getResolvedCorsConfig(httpConfig);
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
HTTP_CORS_CONFIG: JSON.stringify({
|
|
41
|
-
origin: corsConfig.origin ?? "",
|
|
42
|
-
methods: corsConfig.methods ?? "",
|
|
43
|
-
allowedHeaders: corsConfig.allowedHeaders ?? "",
|
|
44
|
-
exposedHeaders: corsConfig.exposedHeaders ?? "",
|
|
45
|
-
credentials: corsConfig.credentials ?? false,
|
|
46
|
-
maxAge: corsConfig.maxAge ?? 0,
|
|
47
|
-
}),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type CorsVariables = ReturnType<typeof injectCorsVariables>;
|
|
52
|
-
|
|
53
|
-
export function injectPathsVariables(userConfig: XmcpConfigOutputSchema) {
|
|
54
|
-
const pathsConfig = getResolvedPathsConfig(userConfig);
|
|
55
|
-
|
|
56
|
-
// Only inject paths that are not null
|
|
57
|
-
const variables: Record<string, string> = {};
|
|
58
|
-
|
|
59
|
-
if (pathsConfig.tools !== null) {
|
|
60
|
-
variables.TOOLS_PATH = JSON.stringify(pathsConfig.tools);
|
|
61
|
-
}
|
|
62
|
-
if (pathsConfig.prompts !== null) {
|
|
63
|
-
variables.PROMPTS_PATH = JSON.stringify(pathsConfig.prompts);
|
|
64
|
-
}
|
|
65
|
-
if (pathsConfig.resources !== null) {
|
|
66
|
-
variables.RESOURCES_PATH = JSON.stringify(pathsConfig.resources);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return variables;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export type PathsVariables = ReturnType<typeof injectPathsVariables>;
|
|
73
|
-
|
|
74
|
-
export function injectStdioVariables(
|
|
75
|
-
stdioConfig: XmcpConfigOutputSchema["stdio"]
|
|
76
|
-
) {
|
|
77
|
-
if (!stdioConfig) return {};
|
|
78
|
-
|
|
79
|
-
const debug = typeof stdioConfig === "object" ? stdioConfig.debug : false;
|
|
80
|
-
const silent = typeof stdioConfig === "object" ? stdioConfig.silent : false;
|
|
81
|
-
|
|
82
|
-
return {
|
|
83
|
-
STDIO_CONFIG: JSON.stringify({
|
|
84
|
-
debug,
|
|
85
|
-
silent,
|
|
86
|
-
}),
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type StdioVariables = ReturnType<typeof injectStdioVariables>;
|
|
91
|
-
|
|
92
|
-
export function injectTemplateVariables(userConfig: XmcpConfigOutputSchema) {
|
|
93
|
-
const resolvedConfig = getResolvedTemplateConfig(userConfig);
|
|
94
|
-
|
|
95
|
-
let homePage = resolvedConfig.homePage;
|
|
96
|
-
|
|
97
|
-
if (homePage && homePage.endsWith(".html")) {
|
|
98
|
-
const filePath = resolve(process.cwd(), homePage);
|
|
99
|
-
if (existsSync(filePath)) {
|
|
100
|
-
homePage = readFileSync(filePath, "utf-8");
|
|
101
|
-
} else {
|
|
102
|
-
console.warn(`[xmcp] homePage file not found: ${filePath}`);
|
|
103
|
-
homePage = undefined;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const { icons: _, ...templateConfigWithoutIcons } = resolvedConfig;
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
TEMPLATE_CONFIG: JSON.stringify({
|
|
111
|
-
...templateConfigWithoutIcons,
|
|
112
|
-
homePage,
|
|
113
|
-
}),
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export type TemplateVariables = ReturnType<typeof injectTemplateVariables>;
|
|
118
|
-
|
|
119
|
-
const MIME_BY_EXT: Record<string, string> = {
|
|
120
|
-
".svg": "image/svg+xml",
|
|
121
|
-
".png": "image/png",
|
|
122
|
-
".jpg": "image/jpeg",
|
|
123
|
-
".jpeg": "image/jpeg",
|
|
124
|
-
".webp": "image/webp",
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
function resolveIconSrc(icon: {
|
|
128
|
-
src: string;
|
|
129
|
-
mimeType?: string;
|
|
130
|
-
sizes?: string[];
|
|
131
|
-
theme?: string;
|
|
132
|
-
}) {
|
|
133
|
-
if (/^https?:\/\/|^data:/.test(icon.src)) return icon;
|
|
134
|
-
|
|
135
|
-
const filePath = resolve(process.cwd(), icon.src);
|
|
136
|
-
if (!existsSync(filePath)) {
|
|
137
|
-
console.warn(`[xmcp] icon file not found: ${filePath}`);
|
|
138
|
-
return icon;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const ext = icon.src.substring(icon.src.lastIndexOf(".")).toLowerCase();
|
|
142
|
-
const mime = icon.mimeType ?? MIME_BY_EXT[ext] ?? "application/octet-stream";
|
|
143
|
-
const data = readFileSync(filePath);
|
|
144
|
-
return { ...icon, src: `data:${mime};base64,${data.toString("base64")}` };
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export function injectServerInfoVariables(userConfig: XmcpConfigOutputSchema) {
|
|
148
|
-
const templateConfig = getResolvedTemplateConfig(userConfig);
|
|
149
|
-
|
|
150
|
-
let version = "0.0.1";
|
|
151
|
-
try {
|
|
152
|
-
const pkg = JSON.parse(
|
|
153
|
-
readFileSync(resolve(process.cwd(), "package.json"), "utf-8")
|
|
154
|
-
);
|
|
155
|
-
if (pkg.version) version = pkg.version;
|
|
156
|
-
} catch (err) {
|
|
157
|
-
console.warn(`[xmcp] Could not read version from package.json:`, err);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const icons = (templateConfig.icons ?? []).map(resolveIconSrc);
|
|
161
|
-
|
|
162
|
-
const serverInfo: Record<string, unknown> = {
|
|
163
|
-
name: templateConfig.name,
|
|
164
|
-
version,
|
|
165
|
-
description: templateConfig.description,
|
|
166
|
-
icons,
|
|
167
|
-
instructions: templateConfig.instructions,
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
return {
|
|
171
|
-
SERVER_INFO: JSON.stringify(serverInfo),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export type ServerInfoVariables = ReturnType<typeof injectServerInfoVariables>;
|
|
176
|
-
|
|
177
|
-
export function injectAdapterVariables(userConfig: XmcpConfigOutputSchema) {
|
|
178
|
-
const experimentalConfig = getResolvedExperimentalConfig(userConfig);
|
|
179
|
-
|
|
180
|
-
// Only inject if adapter is defined
|
|
181
|
-
if (!experimentalConfig.adapter) {
|
|
182
|
-
return {};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return {
|
|
186
|
-
ADAPTER_CONFIG: JSON.stringify(experimentalConfig.adapter),
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export type AdapterVariables = ReturnType<typeof injectAdapterVariables>;
|
|
191
|
-
|
|
192
|
-
export function injectTypescriptVariables(userConfig: XmcpConfigOutputSchema) {
|
|
193
|
-
const typescriptConfig = getResolvedTypescriptConfig(userConfig);
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
TYPESCRIPT_CONFIG: JSON.stringify(typescriptConfig),
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export type TypescriptVariables = ReturnType<typeof injectTypescriptVariables>;
|
|
201
|
-
|
|
202
|
-
export type InjectedVariables =
|
|
203
|
-
| HttpVariables
|
|
204
|
-
| CorsVariables
|
|
205
|
-
| PathsVariables
|
|
206
|
-
| StdioVariables
|
|
207
|
-
| TemplateVariables
|
|
208
|
-
| ServerInfoVariables
|
|
209
|
-
| AdapterVariables
|
|
210
|
-
| TypescriptVariables;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import z from "zod/v3";
|
|
2
|
-
|
|
3
|
-
// ------------------------------------------------------------
|
|
4
|
-
// Bundler config schema - currently supports Rspack
|
|
5
|
-
// ------------------------------------------------------------
|
|
6
|
-
export const bundlerConfigSchema = z
|
|
7
|
-
.function()
|
|
8
|
-
.args(z.any())
|
|
9
|
-
.returns(z.any())
|
|
10
|
-
.optional();
|
|
11
|
-
|
|
12
|
-
export type BundlerConfig = z.infer<typeof bundlerConfigSchema>;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
|
|
3
|
-
// ------------------------------------------------------------
|
|
4
|
-
// Adapter config schema (perhaps a separate file but it's small yet)
|
|
5
|
-
// ------------------------------------------------------------
|
|
6
|
-
export const adapterConfigSchema = z.enum([
|
|
7
|
-
"express",
|
|
8
|
-
"nextjs",
|
|
9
|
-
"nestjs",
|
|
10
|
-
"fastify",
|
|
11
|
-
]);
|
|
12
|
-
|
|
13
|
-
export type AdapterConfig = z.infer<typeof adapterConfigSchema>;
|
|
14
|
-
|
|
15
|
-
// ------------------------------------------------------------
|
|
16
|
-
// Experimental features schema
|
|
17
|
-
// ------------------------------------------------------------
|
|
18
|
-
export const experimentalConfigSchema = z.object({
|
|
19
|
-
adapter: adapterConfigSchema.optional(),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
export type ExperimentalConfig = z.infer<typeof experimentalConfigSchema>;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// re export
|
|
2
|
-
export {
|
|
3
|
-
httpTransportConfigSchema,
|
|
4
|
-
corsConfigSchema,
|
|
5
|
-
type HttpTransportConfig,
|
|
6
|
-
type CorsConfig,
|
|
7
|
-
} from "./transport/http";
|
|
8
|
-
export {
|
|
9
|
-
stdioTransportConfigSchema,
|
|
10
|
-
type StdioTransportConfig,
|
|
11
|
-
} from "./transport/stdio";
|
|
12
|
-
export {
|
|
13
|
-
experimentalConfigSchema,
|
|
14
|
-
type ExperimentalConfig,
|
|
15
|
-
type AdapterConfig,
|
|
16
|
-
} from "./experimental";
|
|
17
|
-
export { pathsConfigSchema, type PathsConfig, DEFAULT_PATHS } from "./paths";
|
|
18
|
-
export { bundlerConfigSchema, type BundlerConfig } from "./bundler";
|
|
19
|
-
export { templateConfigSchema, type TemplateConfig } from "./template";
|
|
20
|
-
export { typescriptConfigSchema, type TypescriptConfig } from "./typescript";
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
|
|
3
|
-
// ------------------------------------------------------------
|
|
4
|
-
// Paths config schema
|
|
5
|
-
// ------------------------------------------------------------
|
|
6
|
-
// Base schema with defaults - used for parsing with defaults applied
|
|
7
|
-
const pathsConfigBaseSchema = z.object({
|
|
8
|
-
tools: z.union([z.boolean(), z.string()]).default(true),
|
|
9
|
-
prompts: z.union([z.boolean(), z.string()]).default(true),
|
|
10
|
-
resources: z.union([z.boolean(), z.string()]).default(true),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
// Input schema - all fields optional for partial configs
|
|
14
|
-
export const pathsConfigSchema = pathsConfigBaseSchema
|
|
15
|
-
.partial()
|
|
16
|
-
.transform((val) => {
|
|
17
|
-
// Merge provided values with defaults, filtering out undefined values
|
|
18
|
-
const defaults = pathsConfigBaseSchema.parse({});
|
|
19
|
-
const provided = Object.fromEntries(
|
|
20
|
-
Object.entries(val).filter(([_, v]) => v !== undefined)
|
|
21
|
-
);
|
|
22
|
-
return {
|
|
23
|
-
...defaults,
|
|
24
|
-
...provided,
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export type PathsConfig = z.infer<typeof pathsConfigSchema>;
|
|
29
|
-
|
|
30
|
-
// Default path values (used for resolution when boolean is true)
|
|
31
|
-
export const DEFAULT_PATHS = {
|
|
32
|
-
tools: "src/tools",
|
|
33
|
-
prompts: "src/prompts",
|
|
34
|
-
resources: "src/resources",
|
|
35
|
-
} as const;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
|
|
3
|
-
// ------------------------------------------------------------
|
|
4
|
-
// Template config schema
|
|
5
|
-
// ------------------------------------------------------------
|
|
6
|
-
|
|
7
|
-
// Base schema with defaults - used for parsing with defaults applied
|
|
8
|
-
const templateConfigBaseSchema = z.object({
|
|
9
|
-
/** The display name of the MCP server shown on the home page */
|
|
10
|
-
name: z.string().default("xmcp server"),
|
|
11
|
-
/** A description of the MCP server shown on the home page */
|
|
12
|
-
description: z
|
|
13
|
-
.string()
|
|
14
|
-
.default("This MCP server was bootstrapped with xmcp."),
|
|
15
|
-
/**
|
|
16
|
-
* Icons for the MCP server, matching the MCP spec's `serverInfo.icons` format.
|
|
17
|
-
* When not provided, defaults to the xmcp logo.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* icons: [{ src: "https://example.com/icon.png", mimeType: "image/png" }]
|
|
21
|
-
*/
|
|
22
|
-
icons: z
|
|
23
|
-
.array(
|
|
24
|
-
z.object({
|
|
25
|
-
src: z.string(),
|
|
26
|
-
mimeType: z.string().optional(),
|
|
27
|
-
sizes: z.array(z.string()).optional(),
|
|
28
|
-
theme: z.enum(["light", "dark"]).optional(),
|
|
29
|
-
})
|
|
30
|
-
)
|
|
31
|
-
.optional(),
|
|
32
|
-
/**
|
|
33
|
-
* Instructions describing how to use the server and its features.
|
|
34
|
-
*
|
|
35
|
-
* This is sent in the MCP `initialize` response and can be used by clients
|
|
36
|
-
* to improve the LLM's understanding of available tools, resources, etc.
|
|
37
|
-
*
|
|
38
|
-
* Instructions should focus on cross-tool relationships, workflow patterns,
|
|
39
|
-
* and constraints, but should not duplicate information already in tool descriptions.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* instructions: "Use tool-a before tool-b. Always check resources first."
|
|
43
|
-
*/
|
|
44
|
-
instructions: z.string().optional(),
|
|
45
|
-
/**
|
|
46
|
-
* Custom home page content for the `/` endpoint.
|
|
47
|
-
*
|
|
48
|
-
* Can be either:
|
|
49
|
-
* - A static HTML string
|
|
50
|
-
* - A path to an HTML file (must end with `.html`, relative to project root)
|
|
51
|
-
*
|
|
52
|
-
* When not provided, the default xmcp home page template is used.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* // Inline HTML
|
|
56
|
-
* homePage: "<html><body><h1>Welcome!</h1></body></html>"
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* // File path
|
|
60
|
-
* homePage: "src/home.html"
|
|
61
|
-
*/
|
|
62
|
-
homePage: z.string().optional(),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
// Input schema - all fields optional for partial configs
|
|
66
|
-
export const templateConfigSchema = templateConfigBaseSchema
|
|
67
|
-
.partial()
|
|
68
|
-
.transform((val) => {
|
|
69
|
-
// Merge provided values with defaults, filtering out undefined values
|
|
70
|
-
const defaults = templateConfigBaseSchema.parse({});
|
|
71
|
-
const provided = Object.fromEntries(
|
|
72
|
-
Object.entries(val).filter(([_, v]) => v !== undefined)
|
|
73
|
-
);
|
|
74
|
-
return {
|
|
75
|
-
...defaults,
|
|
76
|
-
...provided,
|
|
77
|
-
};
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
export type TemplateConfig = z.infer<typeof templateConfigSchema>;
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
import { CLIENT_INFO_HEADER_NAMES } from "@/types/client-info";
|
|
3
|
-
|
|
4
|
-
// ------------------------------------------------------------
|
|
5
|
-
// Cors config schema
|
|
6
|
-
// ------------------------------------------------------------
|
|
7
|
-
// Base schema with defaults - used for parsing with defaults applied
|
|
8
|
-
const corsConfigBaseSchema = z.object({
|
|
9
|
-
origin: z.union([z.string(), z.array(z.string()), z.boolean()]).default("*"),
|
|
10
|
-
methods: z.union([z.string(), z.array(z.string())]).default(["GET", "POST"]),
|
|
11
|
-
allowedHeaders: z
|
|
12
|
-
.union([z.string(), z.array(z.string())])
|
|
13
|
-
.default([
|
|
14
|
-
"Content-Type",
|
|
15
|
-
"Authorization",
|
|
16
|
-
"mcp-session-id",
|
|
17
|
-
"mcp-protocol-version",
|
|
18
|
-
...CLIENT_INFO_HEADER_NAMES,
|
|
19
|
-
]),
|
|
20
|
-
exposedHeaders: z
|
|
21
|
-
.union([z.string(), z.array(z.string())])
|
|
22
|
-
.default(["Content-Type", "Authorization", "mcp-session-id"]),
|
|
23
|
-
credentials: z.boolean().default(false),
|
|
24
|
-
maxAge: z.number().default(86400),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const defaultCorsConfig = corsConfigBaseSchema.parse({});
|
|
28
|
-
|
|
29
|
-
// Input schema - all fields optional for partial configs
|
|
30
|
-
export const corsConfigSchema = corsConfigBaseSchema
|
|
31
|
-
.partial()
|
|
32
|
-
.transform((val) => {
|
|
33
|
-
const provided = Object.fromEntries(
|
|
34
|
-
Object.entries(val).filter(([_, v]) => v !== undefined)
|
|
35
|
-
);
|
|
36
|
-
const result = {
|
|
37
|
-
...defaultCorsConfig,
|
|
38
|
-
...provided,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
if (Array.isArray(result.allowedHeaders)) {
|
|
42
|
-
const headers = new Set(result.allowedHeaders);
|
|
43
|
-
headers.add("mcp-session-id");
|
|
44
|
-
headers.add("mcp-protocol-version");
|
|
45
|
-
for (const clientInfoHeaderName of CLIENT_INFO_HEADER_NAMES) {
|
|
46
|
-
headers.add(clientInfoHeaderName);
|
|
47
|
-
}
|
|
48
|
-
result.allowedHeaders = Array.from(headers);
|
|
49
|
-
}
|
|
50
|
-
if (Array.isArray(result.exposedHeaders)) {
|
|
51
|
-
const headers = new Set(result.exposedHeaders);
|
|
52
|
-
headers.add("mcp-session-id");
|
|
53
|
-
result.exposedHeaders = Array.from(headers);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return result;
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export type CorsConfig = z.infer<typeof corsConfigSchema>;
|
|
60
|
-
|
|
61
|
-
// ------------------------------------------------------------
|
|
62
|
-
// HTTP Transport config schema
|
|
63
|
-
// ------------------------------------------------------------
|
|
64
|
-
// Base schema with defaults - used for parsing with defaults applied
|
|
65
|
-
const httpTransportObjectBaseSchema = z.object({
|
|
66
|
-
port: z.number().default(3001),
|
|
67
|
-
host: z.string().default("127.0.0.1"),
|
|
68
|
-
bodySizeLimit: z.number().default(1024 * 1024 * 10), // 10MB
|
|
69
|
-
debug: z.boolean().default(false),
|
|
70
|
-
endpoint: z.string().default("/mcp"),
|
|
71
|
-
cors: corsConfigSchema,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Input schema - all fields optional for partial configs
|
|
75
|
-
const httpTransportObjectSchema = httpTransportObjectBaseSchema
|
|
76
|
-
.partial()
|
|
77
|
-
.transform((val) => {
|
|
78
|
-
// Merge provided values with defaults, filtering out undefined values
|
|
79
|
-
const defaults = httpTransportObjectBaseSchema.parse({
|
|
80
|
-
cors: {},
|
|
81
|
-
});
|
|
82
|
-
const provided = Object.fromEntries(
|
|
83
|
-
Object.entries(val).filter(([_, v]) => v !== undefined)
|
|
84
|
-
);
|
|
85
|
-
return {
|
|
86
|
-
...defaults,
|
|
87
|
-
...provided,
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Input schema: accepts boolean or object
|
|
92
|
-
export const httpTransportConfigSchema = z.union([
|
|
93
|
-
z.boolean(),
|
|
94
|
-
httpTransportObjectSchema,
|
|
95
|
-
]);
|
|
96
|
-
|
|
97
|
-
// Output schema: transforms boolean → object | null, ensures cors is always present
|
|
98
|
-
export const resolvedHttpTransportConfigSchema = httpTransportConfigSchema
|
|
99
|
-
.transform((val) => {
|
|
100
|
-
if (typeof val === "boolean") {
|
|
101
|
-
return val ? {} : null; // false → null, true → will be handled below
|
|
102
|
-
}
|
|
103
|
-
return val;
|
|
104
|
-
})
|
|
105
|
-
.pipe(
|
|
106
|
-
z.union([
|
|
107
|
-
z.literal(null),
|
|
108
|
-
// httpTransportObjectSchema already handles merging defaults in its transform
|
|
109
|
-
httpTransportObjectSchema,
|
|
110
|
-
])
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
export type HttpTransportConfig = z.input<typeof httpTransportConfigSchema>;
|
|
114
|
-
export type ResolvedHttpConfig = z.output<
|
|
115
|
-
typeof resolvedHttpTransportConfigSchema
|
|
116
|
-
>;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
|
|
3
|
-
// ------------------------------------------------------------
|
|
4
|
-
// stdio transport config schema
|
|
5
|
-
// ------------------------------------------------------------
|
|
6
|
-
// Base schema with defaults - used for parsing with defaults applied
|
|
7
|
-
const stdioTransportObjectBaseSchema = z.object({
|
|
8
|
-
debug: z.boolean().default(false),
|
|
9
|
-
silent: z.boolean().default(false),
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
// Input schema - all fields optional for partial configs
|
|
13
|
-
const stdioTransportObjectSchema = stdioTransportObjectBaseSchema
|
|
14
|
-
.partial()
|
|
15
|
-
.transform((val) => {
|
|
16
|
-
// Merge provided values with defaults, filtering out undefined values
|
|
17
|
-
const defaults = stdioTransportObjectBaseSchema.parse({});
|
|
18
|
-
const provided = Object.fromEntries(
|
|
19
|
-
Object.entries(val).filter(([_, v]) => v !== undefined)
|
|
20
|
-
);
|
|
21
|
-
return {
|
|
22
|
-
...defaults,
|
|
23
|
-
...provided,
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
export const stdioTransportConfigSchema = z
|
|
28
|
-
.union([z.boolean(), stdioTransportObjectSchema])
|
|
29
|
-
.optional();
|
|
30
|
-
|
|
31
|
-
export type StdioTransportConfig = z.infer<typeof stdioTransportConfigSchema>;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
|
|
3
|
-
// ------------------------------------------------------------
|
|
4
|
-
// TypeScript config schema
|
|
5
|
-
// ------------------------------------------------------------
|
|
6
|
-
// Base schema with defaults - used for parsing with defaults applied
|
|
7
|
-
const typescriptConfigBaseSchema = z.object({
|
|
8
|
-
skipTypeCheck: z.boolean().default(false),
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
// Input schema - all fields optional for partial configs
|
|
12
|
-
export const typescriptConfigSchema = typescriptConfigBaseSchema
|
|
13
|
-
.partial()
|
|
14
|
-
.transform((val) => {
|
|
15
|
-
// Merge provided values with defaults, filtering out undefined values
|
|
16
|
-
const defaults = typescriptConfigBaseSchema.parse({});
|
|
17
|
-
const provided = Object.fromEntries(
|
|
18
|
-
Object.entries(val).filter(([_, v]) => v !== undefined)
|
|
19
|
-
);
|
|
20
|
-
return {
|
|
21
|
-
...defaults,
|
|
22
|
-
...provided,
|
|
23
|
-
};
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export type TypescriptConfig = z.infer<typeof typescriptConfigSchema>;
|