@kya-os/mcp-i 0.1.0 → 1.2.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/README.md +406 -71
- package/dist/149.js +1 -0
- package/dist/189.js +1 -0
- package/dist/261.js +1 -0
- package/dist/28.js +1 -0
- package/dist/295.js +1 -0
- package/dist/460.js +1 -0
- package/dist/570.js +1 -0
- package/dist/634.js +1 -0
- package/dist/647.js +1 -0
- package/dist/67.js +1 -0
- package/dist/739.js +1 -0
- package/dist/742.js +1 -0
- package/dist/904.js +1 -0
- package/dist/938.js +1 -0
- package/dist/auth/api-key.d.ts +16 -0
- package/dist/auth/api-key.js +82 -0
- package/dist/auth/jwt.d.ts +43 -0
- package/dist/auth/jwt.js +51 -0
- package/dist/auth/oauth/factory.d.ts +12 -0
- package/dist/auth/oauth/factory.js +36 -0
- package/dist/auth/oauth/index.d.ts +5 -0
- package/dist/auth/oauth/index.js +27 -0
- package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
- package/dist/auth/oauth/providers/proxy-provider.js +159 -0
- package/dist/auth/oauth/router.d.ts +4 -0
- package/dist/auth/oauth/router.js +294 -0
- package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
- package/dist/auth/oauth/storage/memory-storage.js +40 -0
- package/dist/auth/oauth/types.d.ts +112 -0
- package/dist/auth/oauth/types.js +2 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
- package/dist/cache/__tests__/concurrency.test.js +300 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
- package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
- package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
- package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
- package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
- package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
- package/dist/cache/dynamodb-nonce-cache.js +92 -0
- package/dist/cache/index.d.ts +16 -0
- package/dist/cache/index.js +32 -0
- package/dist/cache/memory-nonce-cache.d.ts +44 -0
- package/dist/cache/memory-nonce-cache.js +105 -0
- package/dist/cache/nonce-cache-factory.d.ts +20 -0
- package/dist/cache/nonce-cache-factory.js +208 -0
- package/dist/cache/redis-nonce-cache.d.ts +14 -0
- package/dist/cache/redis-nonce-cache.js +53 -0
- package/dist/compiler/compiler-context.d.ts +23 -0
- package/dist/compiler/compiler-context.js +24 -0
- package/dist/compiler/config/constants.d.ts +41 -0
- package/dist/compiler/config/constants.js +45 -0
- package/dist/compiler/config/index.d.ts +252 -0
- package/dist/compiler/config/index.js +15 -0
- package/dist/compiler/config/injection.d.ts +26 -0
- package/dist/compiler/config/injection.js +58 -0
- package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
- package/dist/compiler/config/schemas/experimental/index.js +16 -0
- package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
- package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
- package/dist/compiler/config/schemas/index.d.ts +6 -0
- package/dist/compiler/config/schemas/index.js +17 -0
- package/dist/compiler/config/schemas/paths.d.ts +9 -0
- package/dist/compiler/config/schemas/paths.js +12 -0
- package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
- package/dist/compiler/config/schemas/transport/http.js +33 -0
- package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
- package/dist/compiler/config/schemas/transport/stdio.js +15 -0
- package/dist/compiler/config/schemas/webpack.d.ts +3 -0
- package/dist/compiler/config/schemas/webpack.js +15 -0
- package/dist/compiler/config/types.d.ts +1 -0
- package/dist/compiler/config/types.js +2 -0
- package/dist/compiler/config/utils.d.ts +20 -0
- package/dist/compiler/config/utils.js +36 -0
- package/dist/compiler/generate-env-code.d.ts +1 -0
- package/dist/compiler/generate-env-code.js +8 -0
- package/dist/compiler/generate-import-code.d.ts +1 -0
- package/dist/compiler/generate-import-code.js +24 -0
- package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
- package/dist/compiler/get-webpack-config/get-entries.js +29 -0
- package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
- package/dist/compiler/get-webpack-config/get-externals.js +88 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
- package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
- package/dist/compiler/get-webpack-config/index.d.ts +4 -0
- package/dist/compiler/get-webpack-config/index.js +101 -0
- package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
- package/dist/compiler/get-webpack-config/plugins.js +132 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
- package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
- package/dist/compiler/index.d.ts +6 -0
- package/dist/compiler/index.js +194 -0
- package/dist/compiler/on-first-build.d.ts +3 -0
- package/dist/compiler/on-first-build.js +58 -0
- package/dist/compiler/parse-xmcp-config.d.ts +9 -0
- package/dist/compiler/parse-xmcp-config.js +155 -0
- package/dist/compiler/start-http-server.d.ts +1 -0
- package/dist/compiler/start-http-server.js +34 -0
- package/dist/index.d.ts +12 -54
- package/dist/index.js +22 -190
- package/dist/index.js.LICENSE.txt +49 -0
- package/dist/runtime/__tests__/audit.test.d.ts +4 -0
- package/dist/runtime/__tests__/audit.test.js +328 -0
- package/dist/runtime/__tests__/identity.test.d.ts +4 -0
- package/dist/runtime/__tests__/identity.test.js +164 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
- package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
- package/dist/runtime/__tests__/proof.test.d.ts +4 -0
- package/dist/runtime/__tests__/proof.test.js +302 -0
- package/dist/runtime/__tests__/session.test.d.ts +4 -0
- package/dist/runtime/__tests__/session.test.js +254 -0
- package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
- package/dist/runtime/__tests__/well-known.test.js +312 -0
- package/dist/runtime/adapter-express.js +2 -0
- package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
- package/dist/runtime/adapter-nextjs.js +2 -0
- package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
- package/dist/runtime/adapters/express/index.d.ts +2 -0
- package/dist/runtime/adapters/express/index.js +48 -0
- package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
- package/dist/runtime/adapters/nextjs/index.js +18 -0
- package/dist/runtime/audit.d.ts +93 -0
- package/dist/runtime/audit.js +212 -0
- package/dist/runtime/debug.d.ts +118 -0
- package/dist/runtime/debug.js +612 -0
- package/dist/runtime/delegation-hooks.d.ts +85 -0
- package/dist/runtime/delegation-hooks.js +116 -0
- package/dist/runtime/demo.d.ts +71 -0
- package/dist/runtime/demo.js +135 -0
- package/dist/runtime/headers.d.ts +1 -0
- package/dist/runtime/headers.js +9 -0
- package/dist/runtime/http.js +2 -0
- package/dist/runtime/http.js.LICENSE.txt +252 -0
- package/dist/runtime/identity.d.ts +105 -0
- package/dist/runtime/identity.js +232 -0
- package/dist/runtime/index.d.ts +16 -0
- package/dist/runtime/index.js +56 -0
- package/dist/runtime/mcpi-runtime.d.ts +164 -0
- package/dist/runtime/mcpi-runtime.js +352 -0
- package/dist/runtime/proof.d.ts +87 -0
- package/dist/runtime/proof.js +223 -0
- package/dist/runtime/session.d.ts +88 -0
- package/dist/runtime/session.js +216 -0
- package/dist/runtime/stdio.js +2 -0
- package/dist/runtime/stdio.js.LICENSE.txt +1 -0
- package/dist/runtime/templates/home.d.ts +2 -0
- package/dist/runtime/templates/home.js +50 -0
- package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
- package/dist/runtime/transports/http/base-streamable-http.js +16 -0
- package/dist/runtime/transports/http/http-context.d.ts +9 -0
- package/dist/runtime/transports/http/http-context.js +8 -0
- package/dist/runtime/transports/http/index.d.ts +1 -0
- package/dist/runtime/transports/http/index.js +55 -0
- package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
- package/dist/runtime/transports/http/setup-cors.js +24 -0
- package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
- package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
- package/dist/runtime/transports/stdio/index.d.ts +1 -0
- package/dist/runtime/transports/stdio/index.js +51 -0
- package/dist/runtime/utils/server.d.ts +42 -0
- package/dist/runtime/utils/server.js +39 -0
- package/dist/runtime/utils/tools.d.ts +8 -0
- package/dist/runtime/utils/tools.js +115 -0
- package/dist/runtime/verifier-middleware.d.ts +76 -0
- package/dist/runtime/verifier-middleware.js +322 -0
- package/dist/runtime/well-known.d.ts +151 -0
- package/dist/runtime/well-known.js +258 -0
- package/dist/storage/config.d.ts +28 -0
- package/dist/storage/config.js +79 -0
- package/dist/storage/delegation.d.ts +59 -0
- package/dist/storage/delegation.js +130 -0
- package/dist/storage/merkle-verifier.d.ts +84 -0
- package/dist/storage/merkle-verifier.js +261 -0
- package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
- package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
- package/dist/test/__tests__/nonce-cache.test.js +122 -0
- package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
- package/dist/test/__tests__/runtime-integration.test.js +192 -0
- package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
- package/dist/test/__tests__/test-infrastructure.test.js +178 -0
- package/dist/test/deterministic-keys.d.ts +31 -0
- package/dist/test/deterministic-keys.js +108 -0
- package/dist/test/examples/test-usage-example.d.ts +140 -0
- package/dist/test/examples/test-usage-example.js +175 -0
- package/dist/test/index.d.ts +11 -0
- package/dist/test/index.js +27 -0
- package/dist/test/local-verification.d.ts +28 -0
- package/dist/test/local-verification.js +342 -0
- package/dist/test/mock-identity-provider.d.ts +96 -0
- package/dist/test/mock-identity-provider.js +243 -0
- package/dist/test/runtime-integration.d.ts +63 -0
- package/dist/test/runtime-integration.js +140 -0
- package/dist/test/test-environment.d.ts +26 -0
- package/dist/test/test-environment.js +50 -0
- package/dist/types/declarations.d.ts +1 -0
- package/dist/types/declarations.js +6 -0
- package/dist/types/middleware.d.ts +2 -0
- package/dist/types/middleware.js +2 -0
- package/dist/types/tool.d.ts +80 -0
- package/dist/types/tool.js +2 -0
- package/dist/utils/cli-icons.d.ts +3 -0
- package/dist/utils/cli-icons.js +7 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +13 -0
- package/dist/utils/context.d.ts +33 -0
- package/dist/utils/context.js +58 -0
- package/dist/utils/file-watcher.d.ts +19 -0
- package/dist/utils/file-watcher.js +49 -0
- package/dist/utils/fs-utils.d.ts +2 -0
- package/dist/utils/fs-utils.js +22 -0
- package/dist/utils/path-validation.d.ts +3 -0
- package/dist/utils/path-validation.js +56 -0
- package/dist/utils/spawn-process.d.ts +9 -0
- package/dist/utils/spawn-process.js +50 -0
- package/dist/utils/subscribable.d.ts +12 -0
- package/dist/utils/subscribable.js +44 -0
- package/package.json +99 -21
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getWebpackConfig = getWebpackConfig;
|
|
7
|
+
const webpack_1 = require("webpack");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const constants_1 = require("../../utils/constants");
|
|
10
|
+
const compiler_context_1 = require("../compiler-context");
|
|
11
|
+
const get_entries_1 = require("./get-entries");
|
|
12
|
+
const get_injected_variables_1 = require("./get-injected-variables");
|
|
13
|
+
const resolve_tsconfig_paths_1 = require("./resolve-tsconfig-paths");
|
|
14
|
+
const clean_webpack_plugin_1 = require("clean-webpack-plugin");
|
|
15
|
+
const plugins_1 = require("./plugins");
|
|
16
|
+
const get_externals_1 = require("./get-externals");
|
|
17
|
+
/** Creates the webpack configuration that xmcp will use to bundle the user's code */
|
|
18
|
+
function getWebpackConfig(xmcpConfig) {
|
|
19
|
+
const processFolder = process.cwd();
|
|
20
|
+
const { mode } = compiler_context_1.compilerContext.getContext();
|
|
21
|
+
const outputPath = xmcpConfig.experimental?.adapter
|
|
22
|
+
? constants_1.adapterOutputPath
|
|
23
|
+
: constants_1.distOutputPath;
|
|
24
|
+
const outputFilename = xmcpConfig.experimental?.adapter
|
|
25
|
+
? "index.js"
|
|
26
|
+
: "[name].js";
|
|
27
|
+
const config = {
|
|
28
|
+
mode,
|
|
29
|
+
watch: mode === "development",
|
|
30
|
+
devtool: mode === "development" ? "eval-cheap-module-source-map" : false,
|
|
31
|
+
output: {
|
|
32
|
+
filename: outputFilename,
|
|
33
|
+
path: outputPath,
|
|
34
|
+
libraryTarget: "commonjs2",
|
|
35
|
+
},
|
|
36
|
+
target: "node",
|
|
37
|
+
externals: (0, get_externals_1.getExternals)(),
|
|
38
|
+
resolve: {
|
|
39
|
+
fallback: {
|
|
40
|
+
process: false,
|
|
41
|
+
},
|
|
42
|
+
alias: {
|
|
43
|
+
"node:process": "process",
|
|
44
|
+
"xmcp/headers": path_1.default.resolve(processFolder, ".xmcp/headers.js"),
|
|
45
|
+
...(0, resolve_tsconfig_paths_1.resolveTsconfigPathsToAlias)(),
|
|
46
|
+
},
|
|
47
|
+
extensions: [".tsx", ".ts", ".jsx", ".js", ".json"],
|
|
48
|
+
},
|
|
49
|
+
plugins: [new plugins_1.InjectRuntimePlugin(), new plugins_1.CreateTypeDefinitionPlugin()],
|
|
50
|
+
module: {
|
|
51
|
+
rules: [
|
|
52
|
+
{
|
|
53
|
+
test: /\.ts$/,
|
|
54
|
+
use: "swc-loader",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
optimization: {
|
|
59
|
+
minimize: mode === "production",
|
|
60
|
+
splitChunks: false,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
// Do not watch the adapter output folder, avoid infinite loop
|
|
64
|
+
if (mode === "development" && !xmcpConfig.experimental?.adapter) {
|
|
65
|
+
config.watchOptions = {
|
|
66
|
+
ignored: [constants_1.adapterOutputPath],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const providedPackages = {
|
|
70
|
+
// connects the user exports with our runtime
|
|
71
|
+
INJECTED_TOOLS: [
|
|
72
|
+
path_1.default.resolve(processFolder, ".xmcp/import-map.js"),
|
|
73
|
+
"tools",
|
|
74
|
+
],
|
|
75
|
+
INJECTED_MIDDLEWARE: [
|
|
76
|
+
path_1.default.resolve(processFolder, ".xmcp/import-map.js"),
|
|
77
|
+
"middleware",
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
// add entry points based on config
|
|
81
|
+
config.entry = (0, get_entries_1.getEntries)(xmcpConfig);
|
|
82
|
+
// add injected variables to config
|
|
83
|
+
config.plugins.push(new webpack_1.ProvidePlugin(providedPackages));
|
|
84
|
+
// add defined variables to config
|
|
85
|
+
const definedVariables = (0, get_injected_variables_1.getInjectedVariables)(xmcpConfig);
|
|
86
|
+
config.plugins.push(new webpack_1.DefinePlugin(definedVariables));
|
|
87
|
+
// add clean plugin
|
|
88
|
+
if (!xmcpConfig.experimental?.adapter) {
|
|
89
|
+
// not needed in adapter mode since it only outputs one file
|
|
90
|
+
config.plugins.push(new clean_webpack_plugin_1.CleanWebpackPlugin());
|
|
91
|
+
}
|
|
92
|
+
// add shebang to CLI output on stdio mode
|
|
93
|
+
if (xmcpConfig.stdio) {
|
|
94
|
+
config.plugins.push(new webpack_1.BannerPlugin({
|
|
95
|
+
banner: "#!/usr/bin/env node",
|
|
96
|
+
raw: true,
|
|
97
|
+
include: /^stdio\.js$/,
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
return config;
|
|
101
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Compiler } from "webpack";
|
|
2
|
+
export declare const runtimeFiles: Record<string, string>;
|
|
3
|
+
export declare class InjectRuntimePlugin {
|
|
4
|
+
apply(compiler: Compiler): void;
|
|
5
|
+
}
|
|
6
|
+
export declare class CreateTypeDefinitionPlugin {
|
|
7
|
+
apply(compiler: Compiler): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CreateTypeDefinitionPlugin = exports.InjectRuntimePlugin = exports.runtimeFiles = void 0;
|
|
7
|
+
const constants_1 = require("../../utils/constants");
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const compiler_context_1 = require("../compiler-context");
|
|
11
|
+
// Fallback runtime files if RUNTIME_FILES is not defined
|
|
12
|
+
const getDefaultRuntimeFiles = () => {
|
|
13
|
+
const path = require("path");
|
|
14
|
+
const fs = require("fs");
|
|
15
|
+
console.log("getDefaultRuntimeFiles: Starting from __dirname:", __dirname);
|
|
16
|
+
// Try multiple possible locations for the mcp-i runtime dist directory
|
|
17
|
+
const possiblePaths = [
|
|
18
|
+
// When running from compiled dist
|
|
19
|
+
path.resolve(__dirname, "../../../dist/runtime"),
|
|
20
|
+
path.resolve(__dirname, "../../dist/runtime"),
|
|
21
|
+
path.resolve(__dirname, "../dist/runtime"),
|
|
22
|
+
path.resolve(__dirname, "../runtime"),
|
|
23
|
+
// When running from source
|
|
24
|
+
path.resolve(__dirname, "../../../packages/mcp-i/dist/runtime"),
|
|
25
|
+
path.resolve(__dirname, "../../packages/mcp-i/dist/runtime"),
|
|
26
|
+
path.resolve(__dirname, "../packages/mcp-i/dist/runtime"),
|
|
27
|
+
];
|
|
28
|
+
let mcpDistPath = "";
|
|
29
|
+
for (const possiblePath of possiblePaths) {
|
|
30
|
+
console.log("getDefaultRuntimeFiles: Checking path:", possiblePath);
|
|
31
|
+
if (fs.existsSync(possiblePath) &&
|
|
32
|
+
fs.existsSync(path.join(possiblePath, "http.js"))) {
|
|
33
|
+
mcpDistPath = possiblePath;
|
|
34
|
+
console.log("getDefaultRuntimeFiles: Found valid dist path:", mcpDistPath);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const runtimeFiles = {};
|
|
39
|
+
if (mcpDistPath) {
|
|
40
|
+
console.log("getDefaultRuntimeFiles: Loading runtime files from:", mcpDistPath);
|
|
41
|
+
// Add known runtime files
|
|
42
|
+
const knownFiles = [
|
|
43
|
+
"http.js",
|
|
44
|
+
"stdio.js",
|
|
45
|
+
"adapter-express.js",
|
|
46
|
+
"adapter-nextjs.js",
|
|
47
|
+
"headers.js",
|
|
48
|
+
];
|
|
49
|
+
for (const file of knownFiles) {
|
|
50
|
+
const filePath = path.join(mcpDistPath, file);
|
|
51
|
+
console.log("getDefaultRuntimeFiles: Checking for file:", filePath);
|
|
52
|
+
if (fs.existsSync(filePath)) {
|
|
53
|
+
console.log("getDefaultRuntimeFiles: Found file:", file);
|
|
54
|
+
runtimeFiles[file] = fs.readFileSync(filePath, "utf8");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log("getDefaultRuntimeFiles: No valid dist path found");
|
|
60
|
+
}
|
|
61
|
+
console.log("getDefaultRuntimeFiles: Final runtime files:", Object.keys(runtimeFiles));
|
|
62
|
+
return runtimeFiles;
|
|
63
|
+
};
|
|
64
|
+
exports.runtimeFiles = (typeof RUNTIME_FILES !== "undefined"
|
|
65
|
+
? RUNTIME_FILES
|
|
66
|
+
: getDefaultRuntimeFiles());
|
|
67
|
+
class InjectRuntimePlugin {
|
|
68
|
+
apply(compiler) {
|
|
69
|
+
let hasRun = false;
|
|
70
|
+
compiler.hooks.beforeCompile.tap("InjectRuntimePlugin", (_compilationParams) => {
|
|
71
|
+
if (hasRun)
|
|
72
|
+
return;
|
|
73
|
+
hasRun = true;
|
|
74
|
+
console.log("InjectRuntimePlugin: Found runtime files:", Object.keys(exports.runtimeFiles));
|
|
75
|
+
for (const [fileName, fileContent] of Object.entries(exports.runtimeFiles)) {
|
|
76
|
+
const targetPath = path_1.default.join(constants_1.runtimeFolderPath, fileName);
|
|
77
|
+
console.log(`InjectRuntimePlugin: Writing ${fileName} to ${targetPath}`);
|
|
78
|
+
fs_extra_1.default.writeFileSync(targetPath, fileContent);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.InjectRuntimePlugin = InjectRuntimePlugin;
|
|
84
|
+
const nextJsTypeDefinition = `
|
|
85
|
+
export const xmcpHandler: (req: Request) => Promise<Response>;
|
|
86
|
+
export const withAuth: (handler: (req: Request) => Promise<Response>, authConfig: AuthConfig) => (req: Request) => Promise<Response>;
|
|
87
|
+
export type VerifyToken = (req: Request, bearerToken?: string) => Promise<AuthInfo | undefined>;
|
|
88
|
+
export type Options = {
|
|
89
|
+
required?: boolean;
|
|
90
|
+
requiredScopes?: string[];
|
|
91
|
+
resourceMetadataPath?: string;
|
|
92
|
+
};
|
|
93
|
+
export type AuthConfig = {
|
|
94
|
+
verifyToken: VerifyToken;
|
|
95
|
+
options?: Options;
|
|
96
|
+
};
|
|
97
|
+
export type AuthInfo = {
|
|
98
|
+
token: string;
|
|
99
|
+
clientId: string;
|
|
100
|
+
scopes: string[];
|
|
101
|
+
expiresAt?: number;
|
|
102
|
+
resource?: URL;
|
|
103
|
+
extra?: Record<string, unknown>;
|
|
104
|
+
};
|
|
105
|
+
`;
|
|
106
|
+
const expressTypeDefinition = `
|
|
107
|
+
export const xmcpHandler: (req: Request, res: Response) => Promise<void>;
|
|
108
|
+
`;
|
|
109
|
+
class CreateTypeDefinitionPlugin {
|
|
110
|
+
apply(compiler) {
|
|
111
|
+
let hasRun = false;
|
|
112
|
+
compiler.hooks.afterEmit.tap("CreateTypeDefinitionPlugin", (_compilationParams) => {
|
|
113
|
+
if (hasRun)
|
|
114
|
+
return;
|
|
115
|
+
hasRun = true;
|
|
116
|
+
const xmcpConfig = (0, compiler_context_1.getXmcpConfig)();
|
|
117
|
+
// Manually type the .xmcp/adapter/index.js file using a .xmcp/adapter/index.d.ts file
|
|
118
|
+
// TO DO add withAuth to the type definition & AuthConfig
|
|
119
|
+
if (xmcpConfig.experimental?.adapter) {
|
|
120
|
+
let typeDefinitionContent = "";
|
|
121
|
+
if (xmcpConfig.experimental?.adapter == "nextjs") {
|
|
122
|
+
typeDefinitionContent = nextJsTypeDefinition;
|
|
123
|
+
}
|
|
124
|
+
else if (xmcpConfig.experimental?.adapter == "express") {
|
|
125
|
+
typeDefinitionContent = expressTypeDefinition;
|
|
126
|
+
}
|
|
127
|
+
fs_extra_1.default.writeFileSync(path_1.default.join(constants_1.adapterOutputPath, "index.d.ts"), typeDefinitionContent);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.CreateTypeDefinitionPlugin = CreateTypeDefinitionPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve tsconfig.json paths to Webpack aliases
|
|
3
|
+
* @param {string} tsconfigPath - Path to tsconfig
|
|
4
|
+
* @param {string} webpackConfigBasePath - Path from tsconfig to Webpack config to create absolute aliases
|
|
5
|
+
* @return {object} - Webpack alias config
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveTsconfigPathsToAlias({ tsconfigPath, }?: {
|
|
8
|
+
tsconfigPath?: string | undefined;
|
|
9
|
+
}): Record<string, string>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Based on https://gist.github.com/nerdyman/2f97b24ab826623bff9202750013f99e
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveTsconfigPathsToAlias = resolveTsconfigPathsToAlias;
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = require("fs");
|
|
10
|
+
const fs_utils_1 = require("../../utils/fs-utils");
|
|
11
|
+
/**
|
|
12
|
+
* Resolve tsconfig.json paths to Webpack aliases
|
|
13
|
+
* @param {string} tsconfigPath - Path to tsconfig
|
|
14
|
+
* @param {string} webpackConfigBasePath - Path from tsconfig to Webpack config to create absolute aliases
|
|
15
|
+
* @return {object} - Webpack alias config
|
|
16
|
+
*/
|
|
17
|
+
function resolveTsconfigPathsToAlias({ tsconfigPath = "./tsconfig.json", } = {}) {
|
|
18
|
+
if (!(0, fs_1.existsSync)(tsconfigPath)) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
const tsconfigContent = (0, fs_1.readFileSync)(tsconfigPath, "utf-8");
|
|
22
|
+
const [parsedTsconfig, parsingError] = (0, fs_utils_1.parseJson)(tsconfigContent);
|
|
23
|
+
if (parsingError) {
|
|
24
|
+
console.error(`Error parsing tsconfig.json: ${parsingError.message} at ${tsconfigPath}`);
|
|
25
|
+
console.log(tsconfigContent);
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
if (!parsedTsconfig.compilerOptions ||
|
|
29
|
+
!parsedTsconfig.compilerOptions.paths) {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
const paths = parsedTsconfig.compilerOptions.paths;
|
|
33
|
+
const aliases = {};
|
|
34
|
+
Object.keys(paths).forEach((item) => {
|
|
35
|
+
const key = item.replace("/*", "");
|
|
36
|
+
const value = path_1.default.resolve(paths[item][0].replace("/*", "").replace("*", ""));
|
|
37
|
+
aliases[key] = value;
|
|
38
|
+
});
|
|
39
|
+
return aliases;
|
|
40
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compile = compile;
|
|
7
|
+
const webpack_1 = require("webpack");
|
|
8
|
+
const get_webpack_config_1 = require("./get-webpack-config");
|
|
9
|
+
// Simplified - remove chalk styling for now
|
|
10
|
+
const chalk = {
|
|
11
|
+
bold: {
|
|
12
|
+
green: (text) => text,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
const parse_xmcp_config_1 = require("./parse-xmcp-config");
|
|
16
|
+
const generate_import_code_1 = require("./generate-import-code");
|
|
17
|
+
const fs_1 = __importDefault(require("fs"));
|
|
18
|
+
const constants_1 = require("../utils/constants");
|
|
19
|
+
const fs_utils_1 = require("../utils/fs-utils");
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
// Use fs.rmSync for cleanup (Node.js 14.14+)
|
|
22
|
+
const deleteSync = (path) => {
|
|
23
|
+
try {
|
|
24
|
+
if (fs_1.default.existsSync(path)) {
|
|
25
|
+
fs_1.default.rmSync(path, { recursive: true, force: true });
|
|
26
|
+
console.log(`Cleaned: ${path}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.log(`Could not clean ${path}:`, error instanceof Error ? error.message : String(error));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
34
|
+
const generate_env_code_1 = require("./generate-env-code");
|
|
35
|
+
const file_watcher_1 = require("../utils/file-watcher");
|
|
36
|
+
const on_first_build_1 = require("./on-first-build");
|
|
37
|
+
const cli_icons_1 = require("../utils/cli-icons");
|
|
38
|
+
const compiler_context_1 = require("./compiler-context");
|
|
39
|
+
const start_http_server_1 = require("./start-http-server");
|
|
40
|
+
const path_validation_1 = require("../utils/path-validation");
|
|
41
|
+
const utils_1 = require("./config/utils");
|
|
42
|
+
dotenv_1.default.config();
|
|
43
|
+
async function compile({ onBuild } = {}) {
|
|
44
|
+
// Initialize compiler context if not already set
|
|
45
|
+
const mode = process.env.NODE_ENV === "production" ? "production" : "development";
|
|
46
|
+
// Use compiler context provider to set up the context properly
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
(0, compiler_context_1.compilerContextProvider)({
|
|
49
|
+
mode,
|
|
50
|
+
platforms: {},
|
|
51
|
+
}, () => {
|
|
52
|
+
compileInternal({ onBuild }).then(resolve).catch(reject);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function compileInternal({ onBuild } = {}) {
|
|
57
|
+
const { mode } = compiler_context_1.compilerContext.getContext();
|
|
58
|
+
const { toolPaths } = compiler_context_1.compilerContext.getContext();
|
|
59
|
+
const startTime = Date.now();
|
|
60
|
+
let compilerStarted = false;
|
|
61
|
+
const xmpcConfig = await (0, parse_xmcp_config_1.getConfig)();
|
|
62
|
+
compiler_context_1.compilerContext.setContext({
|
|
63
|
+
xmcpConfig: xmpcConfig,
|
|
64
|
+
});
|
|
65
|
+
let webpackConfig = (0, get_webpack_config_1.getWebpackConfig)(xmpcConfig);
|
|
66
|
+
if (xmpcConfig.webpack) {
|
|
67
|
+
webpackConfig = xmpcConfig.webpack(webpackConfig);
|
|
68
|
+
}
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
const watcher = new file_watcher_1.Watcher({
|
|
71
|
+
// keep the watcher running on dev mode after "onReady"
|
|
72
|
+
persistent: mode === "development",
|
|
73
|
+
ignored: /(^|[\/\\])\../,
|
|
74
|
+
ignoreInitial: false,
|
|
75
|
+
});
|
|
76
|
+
let toolsPath = (0, path_validation_1.isValidPath)((0, utils_1.getResolvedPathsConfig)(xmpcConfig).tools, "tools");
|
|
77
|
+
// handle tools
|
|
78
|
+
watcher.watch(`${toolsPath}/**/*.ts`, {
|
|
79
|
+
onAdd: (path) => {
|
|
80
|
+
toolPaths.add(path);
|
|
81
|
+
if (compilerStarted) {
|
|
82
|
+
generateCode();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
onUnlink: (path) => {
|
|
86
|
+
toolPaths.delete(path);
|
|
87
|
+
if (compilerStarted) {
|
|
88
|
+
generateCode();
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
// if adapter is not enabled, handle middleware
|
|
93
|
+
if (!xmpcConfig.experimental?.adapter) {
|
|
94
|
+
// handle middleware
|
|
95
|
+
watcher.watch("./src/middleware.ts", {
|
|
96
|
+
onAdd: () => {
|
|
97
|
+
compiler_context_1.compilerContext.setContext({
|
|
98
|
+
hasMiddleware: true,
|
|
99
|
+
});
|
|
100
|
+
if (compilerStarted) {
|
|
101
|
+
generateCode();
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
onUnlink: () => {
|
|
105
|
+
compiler_context_1.compilerContext.setContext({
|
|
106
|
+
hasMiddleware: false,
|
|
107
|
+
});
|
|
108
|
+
if (compilerStarted) {
|
|
109
|
+
generateCode();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
// start compiler
|
|
115
|
+
watcher.onReady(() => {
|
|
116
|
+
let firstBuild = true;
|
|
117
|
+
compilerStarted = true;
|
|
118
|
+
// delete existing runtime folder
|
|
119
|
+
deleteSync(constants_1.runtimeFolderPath);
|
|
120
|
+
(0, fs_utils_1.createFolder)(constants_1.runtimeFolderPath);
|
|
121
|
+
generateCode();
|
|
122
|
+
const compiler = (0, webpack_1.webpack)(webpackConfig);
|
|
123
|
+
const handleCompilation = (err, stats) => {
|
|
124
|
+
if (err) {
|
|
125
|
+
console.error(err);
|
|
126
|
+
reject(err);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (stats?.hasErrors()) {
|
|
130
|
+
const errorMsg = stats.toString({
|
|
131
|
+
colors: true,
|
|
132
|
+
chunks: false,
|
|
133
|
+
});
|
|
134
|
+
console.error(errorMsg);
|
|
135
|
+
reject(new Error('Webpack compilation failed'));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (firstBuild) {
|
|
139
|
+
firstBuild = false;
|
|
140
|
+
const endTime = Date.now();
|
|
141
|
+
const duration = endTime - startTime;
|
|
142
|
+
console.log(`${cli_icons_1.greenCheck} Compiled in ${chalk.bold.green(`${duration}ms`)}`);
|
|
143
|
+
(0, on_first_build_1.onFirstBuild)(mode, xmpcConfig);
|
|
144
|
+
onBuild?.();
|
|
145
|
+
// In production mode, close watcher and compiler, then resolve
|
|
146
|
+
if (mode === "production") {
|
|
147
|
+
watcher.close().then(() => {
|
|
148
|
+
// Close webpack compiler to release all resources
|
|
149
|
+
compiler.close((compilerCloseErr) => {
|
|
150
|
+
if (compilerCloseErr) {
|
|
151
|
+
console.error('Error closing webpack compiler:', compilerCloseErr);
|
|
152
|
+
reject(compilerCloseErr);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
resolve();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}).catch((closeErr) => {
|
|
159
|
+
console.error('Error closing watcher:', closeErr);
|
|
160
|
+
reject(closeErr);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
// on dev mode, webpack will recompile the code, so we need to start the http server after the first one
|
|
166
|
+
if (mode === "development" &&
|
|
167
|
+
xmpcConfig["http"] &&
|
|
168
|
+
!xmpcConfig.experimental?.adapter) {
|
|
169
|
+
(0, start_http_server_1.startHttpServer)();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
// Use compiler.run() for production (single build) or compiler.watch() for development (continuous builds)
|
|
174
|
+
if (mode === "production") {
|
|
175
|
+
compiler.run(handleCompilation);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
compiler.watch({}, handleCompilation);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function generateCode() {
|
|
184
|
+
const fileContent = (0, generate_import_code_1.generateImportCode)();
|
|
185
|
+
fs_1.default.writeFileSync(path_1.default.join(constants_1.runtimeFolderPath, "import-map.js"), fileContent);
|
|
186
|
+
// Generate runtime exports for global access
|
|
187
|
+
const runtimeExportsCode = (0, generate_env_code_1.generateEnvCode)();
|
|
188
|
+
const envFilePath = path_1.default.join(constants_1.rootFolder, "xmcp-env.d.ts");
|
|
189
|
+
// Delete existing file if it exists
|
|
190
|
+
if (fs_1.default.existsSync(envFilePath)) {
|
|
191
|
+
fs_1.default.unlinkSync(envFilePath);
|
|
192
|
+
}
|
|
193
|
+
fs_1.default.writeFileSync(envFilePath, runtimeExportsCode);
|
|
194
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onFirstBuild = onFirstBuild;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const spawn_process_1 = require("../utils/spawn-process");
|
|
6
|
+
const cli_icons_1 = require("../utils/cli-icons");
|
|
7
|
+
function onFirstBuild(mode, xmcpConfig) {
|
|
8
|
+
if (mode === "development" && false) {
|
|
9
|
+
// disable inspector for now
|
|
10
|
+
console.log("🔍 Starting inspector...");
|
|
11
|
+
const inspectorArgs = ["@modelcontextprotocol/inspector@latest"];
|
|
12
|
+
if (xmcpConfig.stdio) {
|
|
13
|
+
inspectorArgs.push("node", "dist/stdio.js");
|
|
14
|
+
}
|
|
15
|
+
const inspectorProcess = (0, child_process_1.spawn)("npx", inspectorArgs, {
|
|
16
|
+
stdio: ["inherit", "pipe", "pipe"],
|
|
17
|
+
shell: true,
|
|
18
|
+
});
|
|
19
|
+
(0, spawn_process_1.watchdog)(inspectorProcess);
|
|
20
|
+
// Prefix inspector output with [Inspector]
|
|
21
|
+
inspectorProcess.stdout?.on("data", (data) => {
|
|
22
|
+
const lines = data.toString().split("\n");
|
|
23
|
+
lines.forEach((line) => {
|
|
24
|
+
if (line.trim()) {
|
|
25
|
+
if (line.includes("?MCP_PROXY_AUTH_TOKEN")) {
|
|
26
|
+
console.log(`🔍 Inspector started at ${line}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
inspectorProcess.stderr?.on("data", (data) => {
|
|
32
|
+
const lines = data.toString().split("\n");
|
|
33
|
+
lines.forEach((line) => {
|
|
34
|
+
if (line.trim()) {
|
|
35
|
+
console.error(`[Inspector] ${line}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
inspectorProcess.on("error", (err) => {
|
|
40
|
+
console.error("[Inspector] Failed to start inspector:", err);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const builtResults = [];
|
|
44
|
+
if (xmcpConfig.stdio) {
|
|
45
|
+
builtResults.push(`${cli_icons_1.greenCheck} Built STDIO server`);
|
|
46
|
+
}
|
|
47
|
+
if (xmcpConfig["http"]) {
|
|
48
|
+
if (xmcpConfig.experimental?.adapter) {
|
|
49
|
+
builtResults.push(`${cli_icons_1.greenCheck} Built Adapter`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
builtResults.push(`${cli_icons_1.greenCheck} Built HTTP server`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
builtResults.forEach((result) => {
|
|
56
|
+
console.log(result);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type XmcpConfigOuputSchema } from "./config";
|
|
2
|
+
/**
|
|
3
|
+
* Parse and validate xmcp config file
|
|
4
|
+
*/
|
|
5
|
+
export declare function getConfig(): Promise<XmcpConfigOuputSchema>;
|
|
6
|
+
/**
|
|
7
|
+
* Read config from file or return default
|
|
8
|
+
*/
|
|
9
|
+
export declare function readConfig(): Promise<XmcpConfigOuputSchema>;
|