@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.
Files changed (229) hide show
  1. package/README.md +406 -71
  2. package/dist/149.js +1 -0
  3. package/dist/189.js +1 -0
  4. package/dist/261.js +1 -0
  5. package/dist/28.js +1 -0
  6. package/dist/295.js +1 -0
  7. package/dist/460.js +1 -0
  8. package/dist/570.js +1 -0
  9. package/dist/634.js +1 -0
  10. package/dist/647.js +1 -0
  11. package/dist/67.js +1 -0
  12. package/dist/739.js +1 -0
  13. package/dist/742.js +1 -0
  14. package/dist/904.js +1 -0
  15. package/dist/938.js +1 -0
  16. package/dist/auth/api-key.d.ts +16 -0
  17. package/dist/auth/api-key.js +82 -0
  18. package/dist/auth/jwt.d.ts +43 -0
  19. package/dist/auth/jwt.js +51 -0
  20. package/dist/auth/oauth/factory.d.ts +12 -0
  21. package/dist/auth/oauth/factory.js +36 -0
  22. package/dist/auth/oauth/index.d.ts +5 -0
  23. package/dist/auth/oauth/index.js +27 -0
  24. package/dist/auth/oauth/providers/proxy-provider.d.ts +13 -0
  25. package/dist/auth/oauth/providers/proxy-provider.js +159 -0
  26. package/dist/auth/oauth/router.d.ts +4 -0
  27. package/dist/auth/oauth/router.js +294 -0
  28. package/dist/auth/oauth/storage/memory-storage.d.ts +12 -0
  29. package/dist/auth/oauth/storage/memory-storage.js +40 -0
  30. package/dist/auth/oauth/types.d.ts +112 -0
  31. package/dist/auth/oauth/types.js +2 -0
  32. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.d.ts +4 -0
  33. package/dist/cache/__tests__/cloudflare-kv-nonce-cache.test.js +176 -0
  34. package/dist/cache/__tests__/concurrency.test.d.ts +5 -0
  35. package/dist/cache/__tests__/concurrency.test.js +300 -0
  36. package/dist/cache/__tests__/dynamodb-nonce-cache.test.d.ts +4 -0
  37. package/dist/cache/__tests__/dynamodb-nonce-cache.test.js +176 -0
  38. package/dist/cache/__tests__/memory-nonce-cache.test.d.ts +4 -0
  39. package/dist/cache/__tests__/memory-nonce-cache.test.js +132 -0
  40. package/dist/cache/__tests__/nonce-cache-factory-simple.test.d.ts +4 -0
  41. package/dist/cache/__tests__/nonce-cache-factory-simple.test.js +133 -0
  42. package/dist/cache/__tests__/nonce-cache-factory.test.d.ts +4 -0
  43. package/dist/cache/__tests__/nonce-cache-factory.test.js +252 -0
  44. package/dist/cache/__tests__/redis-nonce-cache.test.d.ts +4 -0
  45. package/dist/cache/__tests__/redis-nonce-cache.test.js +95 -0
  46. package/dist/cache/cloudflare-kv-nonce-cache.d.ts +14 -0
  47. package/dist/cache/cloudflare-kv-nonce-cache.js +93 -0
  48. package/dist/cache/dynamodb-nonce-cache.d.ts +15 -0
  49. package/dist/cache/dynamodb-nonce-cache.js +92 -0
  50. package/dist/cache/index.d.ts +16 -0
  51. package/dist/cache/index.js +32 -0
  52. package/dist/cache/memory-nonce-cache.d.ts +44 -0
  53. package/dist/cache/memory-nonce-cache.js +105 -0
  54. package/dist/cache/nonce-cache-factory.d.ts +20 -0
  55. package/dist/cache/nonce-cache-factory.js +208 -0
  56. package/dist/cache/redis-nonce-cache.d.ts +14 -0
  57. package/dist/cache/redis-nonce-cache.js +53 -0
  58. package/dist/compiler/compiler-context.d.ts +23 -0
  59. package/dist/compiler/compiler-context.js +24 -0
  60. package/dist/compiler/config/constants.d.ts +41 -0
  61. package/dist/compiler/config/constants.js +45 -0
  62. package/dist/compiler/config/index.d.ts +252 -0
  63. package/dist/compiler/config/index.js +15 -0
  64. package/dist/compiler/config/injection.d.ts +26 -0
  65. package/dist/compiler/config/injection.js +58 -0
  66. package/dist/compiler/config/schemas/experimental/index.d.ts +91 -0
  67. package/dist/compiler/config/schemas/experimental/index.js +16 -0
  68. package/dist/compiler/config/schemas/experimental/oauth.d.ts +74 -0
  69. package/dist/compiler/config/schemas/experimental/oauth.js +25 -0
  70. package/dist/compiler/config/schemas/index.d.ts +6 -0
  71. package/dist/compiler/config/schemas/index.js +17 -0
  72. package/dist/compiler/config/schemas/paths.d.ts +9 -0
  73. package/dist/compiler/config/schemas/paths.js +12 -0
  74. package/dist/compiler/config/schemas/transport/http.d.ts +82 -0
  75. package/dist/compiler/config/schemas/transport/http.js +33 -0
  76. package/dist/compiler/config/schemas/transport/stdio.d.ts +9 -0
  77. package/dist/compiler/config/schemas/transport/stdio.js +15 -0
  78. package/dist/compiler/config/schemas/webpack.d.ts +3 -0
  79. package/dist/compiler/config/schemas/webpack.js +15 -0
  80. package/dist/compiler/config/types.d.ts +1 -0
  81. package/dist/compiler/config/types.js +2 -0
  82. package/dist/compiler/config/utils.d.ts +20 -0
  83. package/dist/compiler/config/utils.js +36 -0
  84. package/dist/compiler/generate-env-code.d.ts +1 -0
  85. package/dist/compiler/generate-env-code.js +8 -0
  86. package/dist/compiler/generate-import-code.d.ts +1 -0
  87. package/dist/compiler/generate-import-code.js +24 -0
  88. package/dist/compiler/get-webpack-config/get-entries.d.ts +3 -0
  89. package/dist/compiler/get-webpack-config/get-entries.js +29 -0
  90. package/dist/compiler/get-webpack-config/get-externals.d.ts +7 -0
  91. package/dist/compiler/get-webpack-config/get-externals.js +88 -0
  92. package/dist/compiler/get-webpack-config/get-injected-variables.d.ts +8 -0
  93. package/dist/compiler/get-webpack-config/get-injected-variables.js +25 -0
  94. package/dist/compiler/get-webpack-config/index.d.ts +4 -0
  95. package/dist/compiler/get-webpack-config/index.js +101 -0
  96. package/dist/compiler/get-webpack-config/plugins.d.ts +8 -0
  97. package/dist/compiler/get-webpack-config/plugins.js +132 -0
  98. package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.d.ts +9 -0
  99. package/dist/compiler/get-webpack-config/resolve-tsconfig-paths.js +40 -0
  100. package/dist/compiler/index.d.ts +6 -0
  101. package/dist/compiler/index.js +194 -0
  102. package/dist/compiler/on-first-build.d.ts +3 -0
  103. package/dist/compiler/on-first-build.js +58 -0
  104. package/dist/compiler/parse-xmcp-config.d.ts +9 -0
  105. package/dist/compiler/parse-xmcp-config.js +155 -0
  106. package/dist/compiler/start-http-server.d.ts +1 -0
  107. package/dist/compiler/start-http-server.js +34 -0
  108. package/dist/index.d.ts +12 -54
  109. package/dist/index.js +22 -190
  110. package/dist/index.js.LICENSE.txt +49 -0
  111. package/dist/runtime/__tests__/audit.test.d.ts +4 -0
  112. package/dist/runtime/__tests__/audit.test.js +328 -0
  113. package/dist/runtime/__tests__/identity.test.d.ts +4 -0
  114. package/dist/runtime/__tests__/identity.test.js +164 -0
  115. package/dist/runtime/__tests__/mcpi-runtime.test.d.ts +4 -0
  116. package/dist/runtime/__tests__/mcpi-runtime.test.js +372 -0
  117. package/dist/runtime/__tests__/proof.test.d.ts +4 -0
  118. package/dist/runtime/__tests__/proof.test.js +302 -0
  119. package/dist/runtime/__tests__/session.test.d.ts +4 -0
  120. package/dist/runtime/__tests__/session.test.js +254 -0
  121. package/dist/runtime/__tests__/well-known.test.d.ts +4 -0
  122. package/dist/runtime/__tests__/well-known.test.js +312 -0
  123. package/dist/runtime/adapter-express.js +2 -0
  124. package/dist/runtime/adapter-express.js.LICENSE.txt +252 -0
  125. package/dist/runtime/adapter-nextjs.js +2 -0
  126. package/dist/runtime/adapter-nextjs.js.LICENSE.txt +53 -0
  127. package/dist/runtime/adapters/express/index.d.ts +2 -0
  128. package/dist/runtime/adapters/express/index.js +48 -0
  129. package/dist/runtime/adapters/nextjs/index.d.ts +8 -0
  130. package/dist/runtime/adapters/nextjs/index.js +18 -0
  131. package/dist/runtime/audit.d.ts +93 -0
  132. package/dist/runtime/audit.js +212 -0
  133. package/dist/runtime/debug.d.ts +118 -0
  134. package/dist/runtime/debug.js +612 -0
  135. package/dist/runtime/delegation-hooks.d.ts +85 -0
  136. package/dist/runtime/delegation-hooks.js +116 -0
  137. package/dist/runtime/demo.d.ts +71 -0
  138. package/dist/runtime/demo.js +135 -0
  139. package/dist/runtime/headers.d.ts +1 -0
  140. package/dist/runtime/headers.js +9 -0
  141. package/dist/runtime/http.js +2 -0
  142. package/dist/runtime/http.js.LICENSE.txt +252 -0
  143. package/dist/runtime/identity.d.ts +105 -0
  144. package/dist/runtime/identity.js +232 -0
  145. package/dist/runtime/index.d.ts +16 -0
  146. package/dist/runtime/index.js +56 -0
  147. package/dist/runtime/mcpi-runtime.d.ts +164 -0
  148. package/dist/runtime/mcpi-runtime.js +352 -0
  149. package/dist/runtime/proof.d.ts +87 -0
  150. package/dist/runtime/proof.js +223 -0
  151. package/dist/runtime/session.d.ts +88 -0
  152. package/dist/runtime/session.js +216 -0
  153. package/dist/runtime/stdio.js +2 -0
  154. package/dist/runtime/stdio.js.LICENSE.txt +1 -0
  155. package/dist/runtime/templates/home.d.ts +2 -0
  156. package/dist/runtime/templates/home.js +50 -0
  157. package/dist/runtime/transports/http/base-streamable-http.d.ts +25 -0
  158. package/dist/runtime/transports/http/base-streamable-http.js +16 -0
  159. package/dist/runtime/transports/http/http-context.d.ts +9 -0
  160. package/dist/runtime/transports/http/http-context.js +8 -0
  161. package/dist/runtime/transports/http/index.d.ts +1 -0
  162. package/dist/runtime/transports/http/index.js +55 -0
  163. package/dist/runtime/transports/http/setup-cors.d.ts +4 -0
  164. package/dist/runtime/transports/http/setup-cors.js +24 -0
  165. package/dist/runtime/transports/http/stateless-streamable-http.d.ts +39 -0
  166. package/dist/runtime/transports/http/stateless-streamable-http.js +331 -0
  167. package/dist/runtime/transports/stdio/index.d.ts +1 -0
  168. package/dist/runtime/transports/stdio/index.js +51 -0
  169. package/dist/runtime/utils/server.d.ts +42 -0
  170. package/dist/runtime/utils/server.js +39 -0
  171. package/dist/runtime/utils/tools.d.ts +8 -0
  172. package/dist/runtime/utils/tools.js +115 -0
  173. package/dist/runtime/verifier-middleware.d.ts +76 -0
  174. package/dist/runtime/verifier-middleware.js +322 -0
  175. package/dist/runtime/well-known.d.ts +151 -0
  176. package/dist/runtime/well-known.js +258 -0
  177. package/dist/storage/config.d.ts +28 -0
  178. package/dist/storage/config.js +79 -0
  179. package/dist/storage/delegation.d.ts +59 -0
  180. package/dist/storage/delegation.js +130 -0
  181. package/dist/storage/merkle-verifier.d.ts +84 -0
  182. package/dist/storage/merkle-verifier.js +261 -0
  183. package/dist/test/__tests__/nonce-cache-integration.test.d.ts +1 -0
  184. package/dist/test/__tests__/nonce-cache-integration.test.js +116 -0
  185. package/dist/test/__tests__/nonce-cache.test.d.ts +1 -0
  186. package/dist/test/__tests__/nonce-cache.test.js +122 -0
  187. package/dist/test/__tests__/runtime-integration.test.d.ts +4 -0
  188. package/dist/test/__tests__/runtime-integration.test.js +192 -0
  189. package/dist/test/__tests__/test-infrastructure.test.d.ts +4 -0
  190. package/dist/test/__tests__/test-infrastructure.test.js +178 -0
  191. package/dist/test/deterministic-keys.d.ts +31 -0
  192. package/dist/test/deterministic-keys.js +108 -0
  193. package/dist/test/examples/test-usage-example.d.ts +140 -0
  194. package/dist/test/examples/test-usage-example.js +175 -0
  195. package/dist/test/index.d.ts +11 -0
  196. package/dist/test/index.js +27 -0
  197. package/dist/test/local-verification.d.ts +28 -0
  198. package/dist/test/local-verification.js +342 -0
  199. package/dist/test/mock-identity-provider.d.ts +96 -0
  200. package/dist/test/mock-identity-provider.js +243 -0
  201. package/dist/test/runtime-integration.d.ts +63 -0
  202. package/dist/test/runtime-integration.js +140 -0
  203. package/dist/test/test-environment.d.ts +26 -0
  204. package/dist/test/test-environment.js +50 -0
  205. package/dist/types/declarations.d.ts +1 -0
  206. package/dist/types/declarations.js +6 -0
  207. package/dist/types/middleware.d.ts +2 -0
  208. package/dist/types/middleware.js +2 -0
  209. package/dist/types/tool.d.ts +80 -0
  210. package/dist/types/tool.js +2 -0
  211. package/dist/utils/cli-icons.d.ts +3 -0
  212. package/dist/utils/cli-icons.js +7 -0
  213. package/dist/utils/constants.d.ts +6 -0
  214. package/dist/utils/constants.js +13 -0
  215. package/dist/utils/context.d.ts +33 -0
  216. package/dist/utils/context.js +58 -0
  217. package/dist/utils/file-watcher.d.ts +19 -0
  218. package/dist/utils/file-watcher.js +49 -0
  219. package/dist/utils/fs-utils.d.ts +2 -0
  220. package/dist/utils/fs-utils.js +22 -0
  221. package/dist/utils/path-validation.d.ts +3 -0
  222. package/dist/utils/path-validation.js +56 -0
  223. package/dist/utils/spawn-process.d.ts +9 -0
  224. package/dist/utils/spawn-process.js +50 -0
  225. package/dist/utils/subscribable.d.ts +12 -0
  226. package/dist/utils/subscribable.js +44 -0
  227. package/package.json +99 -21
  228. package/dist/index.d.ts.map +0 -1
  229. package/dist/index.js.map +0 -1
@@ -0,0 +1,155 @@
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.getConfig = getConfig;
7
+ exports.readConfig = readConfig;
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const webpack_1 = require("webpack");
11
+ const memfs_1 = require("memfs");
12
+ const compiler_context_1 = require("./compiler-context");
13
+ const config_1 = require("./config");
14
+ const constants_1 = require("./config/constants");
15
+ function validateConfig(config) {
16
+ return config_1.configSchema.parse(config);
17
+ }
18
+ // read if exists
19
+ function readConfigFile(pathToConfig) {
20
+ const configPath = path_1.default.resolve(process.cwd(), pathToConfig);
21
+ if (!fs_1.default.existsSync(configPath)) {
22
+ return null;
23
+ }
24
+ return fs_1.default.readFileSync(configPath, "utf8");
25
+ }
26
+ const configPaths = {
27
+ ts: "xmcp.config.ts",
28
+ json: "xmcp.config.json",
29
+ };
30
+ /**
31
+ * Parse and validate xmcp config file
32
+ */
33
+ async function getConfig() {
34
+ const config = await readConfig();
35
+ const { platforms } = compiler_context_1.compilerContext.getContext();
36
+ if (platforms.vercel) {
37
+ // Remove stdio to deploy on vercel
38
+ delete config.stdio;
39
+ }
40
+ return config;
41
+ }
42
+ /**
43
+ * Read config from file or return default
44
+ */
45
+ async function readConfig() {
46
+ // Simple json config
47
+ const jsonFile = readConfigFile(configPaths.json);
48
+ if (jsonFile) {
49
+ return validateConfig(JSON.parse(jsonFile));
50
+ }
51
+ // TypeScript config, compile it
52
+ const tsFile = readConfigFile(configPaths.ts);
53
+ if (tsFile) {
54
+ try {
55
+ return await compileConfig();
56
+ }
57
+ catch (error) {
58
+ throw new Error(`Failed to compile xmcp.config.ts:\n${error}`);
59
+ }
60
+ }
61
+ // Default config
62
+ return {
63
+ stdio: true,
64
+ http: true,
65
+ paths: constants_1.DEFAULT_PATHS_CONFIG,
66
+ };
67
+ }
68
+ /**
69
+ * If the user is using a typescript config file,
70
+ * we need to bundle it, run it and return its copiled code
71
+ * */
72
+ async function compileConfig() {
73
+ const configPath = path_1.default.resolve(process.cwd(), configPaths.ts);
74
+ // Create memory filesystem
75
+ const memoryFs = (0, memfs_1.createFsFromVolume)(new memfs_1.Volume());
76
+ // Webpack configuration
77
+ const webpackConfig = {
78
+ mode: "production",
79
+ entry: configPath,
80
+ target: "node",
81
+ output: {
82
+ path: "/",
83
+ filename: "config.js",
84
+ library: {
85
+ type: "commonjs2",
86
+ },
87
+ },
88
+ resolve: {
89
+ extensions: [".ts", ".js"],
90
+ },
91
+ module: {
92
+ rules: [
93
+ {
94
+ test: /\.ts$/,
95
+ use: {
96
+ loader: "swc-loader",
97
+ options: {
98
+ jsc: {
99
+ parser: {
100
+ syntax: "typescript",
101
+ },
102
+ target: "es2020",
103
+ },
104
+ module: {
105
+ type: "commonjs",
106
+ },
107
+ },
108
+ },
109
+ exclude: /node_modules/,
110
+ },
111
+ ],
112
+ },
113
+ externals: {
114
+ webpack: "commonjs2 webpack",
115
+ },
116
+ };
117
+ return new Promise((resolve, reject) => {
118
+ const compiler = (0, webpack_1.webpack)(webpackConfig);
119
+ // Use memory filesystem for output
120
+ compiler.outputFileSystem = memoryFs;
121
+ compiler.run((err, stats) => {
122
+ if (err) {
123
+ reject(err);
124
+ return;
125
+ }
126
+ if (stats?.hasErrors()) {
127
+ reject(new Error(stats.toString({ colors: false, errors: true })));
128
+ return;
129
+ }
130
+ try {
131
+ // Read the bundled code from memory
132
+ const bundledCode = memoryFs.readFileSync("/config.js", "utf8");
133
+ // Create a temporary module to evaluate the bundled code
134
+ const module = { exports: {} };
135
+ const require = (id) => {
136
+ // Handle webpack require
137
+ if (id === "webpack") {
138
+ return webpack_1.webpack;
139
+ }
140
+ throw new Error(`Cannot resolve module: ${id}`);
141
+ };
142
+ // Evaluate the bundled code
143
+ const func = new Function("module", "exports", "require", "__filename", "__dirname", bundledCode);
144
+ func(module, module.exports, require, configPath, path_1.default.dirname(configPath));
145
+ // Extract the config - it could be default export or direct export
146
+ const configExport = module.exports.default || module.exports;
147
+ const config = typeof configExport === "function" ? configExport() : configExport;
148
+ resolve(validateConfig(config));
149
+ }
150
+ catch (evalError) {
151
+ reject(evalError);
152
+ }
153
+ });
154
+ });
155
+ }
@@ -0,0 +1 @@
1
+ export declare function startHttpServer(): Promise<void>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.startHttpServer = startHttpServer;
4
+ const cli_icons_1 = require("../utils/cli-icons");
5
+ const spawn_process_1 = require("../utils/spawn-process");
6
+ const child_process_1 = require("child_process");
7
+ let httpServerProcess = null;
8
+ function spawnHttpServer() {
9
+ const process = (0, child_process_1.spawn)("node", ["dist/http.js"], {
10
+ stdio: "inherit",
11
+ shell: true,
12
+ });
13
+ (0, spawn_process_1.watchdog)(process);
14
+ return process;
15
+ }
16
+ async function killProcess(process) {
17
+ process.kill("SIGKILL");
18
+ await new Promise((resolve) => {
19
+ process.on("exit", resolve);
20
+ });
21
+ }
22
+ async function startHttpServer() {
23
+ if (!httpServerProcess) {
24
+ console.log(`${cli_icons_1.yellowArrow} Starting http server`);
25
+ // first time starting the server
26
+ httpServerProcess = spawnHttpServer();
27
+ }
28
+ else {
29
+ console.log(`${cli_icons_1.yellowArrow} Restarting http server`);
30
+ // restart the server
31
+ await killProcess(httpServerProcess);
32
+ httpServerProcess = spawnHttpServer();
33
+ }
34
+ }
package/dist/index.d.ts CHANGED
@@ -1,54 +1,12 @@
1
- /**
2
- * @kya-os/mcp-i - Ultra-light MCP Identity auto-registration
3
- *
4
- * Enable any MCP server to get a verifiable identity with just 2 lines of code:
5
- *
6
- * ```typescript
7
- * import { MCPIdentity } from "@kya-os/mcp-i";
8
- * const identity = await MCPIdentity.init();
9
- * ```
10
- *
11
- * Zero dependencies on other @kya-os packages - completely standalone!
12
- */
13
- interface MCPIdentityOptions {
14
- name?: string;
15
- description?: string;
16
- repository?: string;
17
- apiEndpoint?: string;
18
- persistencePath?: string;
19
- }
20
- export declare class MCPIdentity {
21
- readonly did: string;
22
- readonly publicKey: string;
23
- private privateKey;
24
- private constructor();
25
- /**
26
- * Initialize MCP Identity - the main entry point
27
- *
28
- * @example
29
- * ```typescript
30
- * import { MCPIdentity } from "@kya-os/mcp-i";
31
- * const identity = await MCPIdentity.init();
32
- * ```
33
- */
34
- static init(options?: MCPIdentityOptions): Promise<MCPIdentity>;
35
- /**
36
- * Sign a message with the agent's private key
37
- */
38
- sign(message: string): Promise<string>;
39
- /**
40
- * Get MCP-I capabilities
41
- */
42
- getCapabilities(): {
43
- version: string;
44
- did: string;
45
- publicKey: string;
46
- conformanceLevel: number;
47
- };
48
- /**
49
- * Sign an MCP response
50
- */
51
- signResponse(response: any): any;
52
- }
53
- export {};
54
- //# sourceMappingURL=index.d.ts.map
1
+ export { type Middleware } from "./types/middleware";
2
+ export type { ToolMetadata, ToolSchema, ToolExtraArguments, InferSchema, } from "./types/tool";
3
+ export type { XmcpConfigOuputSchema as XmcpConfig } from "./compiler/config";
4
+ export { apiKeyAuthMiddleware } from "./auth/api-key";
5
+ export { jwtAuthMiddleware } from "./auth/jwt";
6
+ export type { OAuthConfigOptions } from "./auth/oauth";
7
+ import "./types/declarations";
8
+ export * from "./test/index";
9
+ export * from "./cache/index";
10
+ export * from "./runtime/identity";
11
+ export * from "./runtime/index";
12
+ export { compile } from "./compiler/index";
package/dist/index.js CHANGED
@@ -1,16 +1,4 @@
1
1
  "use strict";
2
- /**
3
- * @kya-os/mcp-i - Ultra-light MCP Identity auto-registration
4
- *
5
- * Enable any MCP server to get a verifiable identity with just 2 lines of code:
6
- *
7
- * ```typescript
8
- * import { MCPIdentity } from "@kya-os/mcp-i";
9
- * const identity = await MCPIdentity.init();
10
- * ```
11
- *
12
- * Zero dependencies on other @kya-os packages - completely standalone!
13
- */
14
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
3
  if (k2 === undefined) k2 = k;
16
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -22,185 +10,29 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
22
10
  if (k2 === undefined) k2 = k;
23
11
  o[k2] = m[k];
24
12
  }));
25
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
- Object.defineProperty(o, "default", { enumerable: true, value: v });
27
- }) : function(o, v) {
28
- o["default"] = v;
29
- });
30
- var __importStar = (this && this.__importStar) || (function () {
31
- var ownKeys = function(o) {
32
- ownKeys = Object.getOwnPropertyNames || function (o) {
33
- var ar = [];
34
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
- return ar;
36
- };
37
- return ownKeys(o);
38
- };
39
- return function (mod) {
40
- if (mod && mod.__esModule) return mod;
41
- var result = {};
42
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
- __setModuleDefault(result, mod);
44
- return result;
45
- };
46
- })();
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
47
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
48
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
18
  };
50
19
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.MCPIdentity = void 0;
52
- const axios_1 = __importDefault(require("axios"));
53
- const fs = __importStar(require("fs"));
54
- const path = __importStar(require("path"));
55
- class MCPIdentity {
56
- constructor(identity) {
57
- this.did = identity.did;
58
- this.publicKey = identity.publicKey;
59
- this.privateKey = identity.privateKey;
60
- }
61
- /**
62
- * Initialize MCP Identity - the main entry point
63
- *
64
- * @example
65
- * ```typescript
66
- * import { MCPIdentity } from "@kya-os/mcp-i";
67
- * const identity = await MCPIdentity.init();
68
- * ```
69
- */
70
- static async init(options) {
71
- // Try to load existing identity
72
- let identity = await loadIdentity(options?.persistencePath);
73
- // Auto-register if needed
74
- if (!identity) {
75
- console.log('[MCP-I] No existing identity found, auto-registering...');
76
- const response = await autoRegister({
77
- name: options?.name || process.env.MCP_SERVER_NAME || 'Unnamed MCP Server',
78
- description: options?.description,
79
- repository: options?.repository,
80
- apiEndpoint: options?.apiEndpoint || 'https://knowthat.ai'
81
- });
82
- // Create persisted identity
83
- identity = {
84
- did: response.did,
85
- publicKey: response.keys.publicKey,
86
- privateKey: response.keys.privateKey || '',
87
- agentId: response.agent.id,
88
- agentSlug: response.agent.slug,
89
- registeredAt: new Date().toISOString(),
90
- };
91
- // Save for future use
92
- await saveIdentity(identity, options?.persistencePath);
93
- console.log('[MCP-I] ✅ Success! Your agent has been registered.');
94
- console.log(`[MCP-I] DID: ${response.did}`);
95
- console.log(`[MCP-I] Profile: ${response.agent.url}`);
96
- }
97
- return new MCPIdentity(identity);
98
- }
99
- /**
100
- * Sign a message with the agent's private key
101
- */
102
- async sign(message) {
103
- // Simple signature for demo - in production use proper crypto
104
- return Buffer.from(`${this.privateKey}:${message}`).toString('base64');
105
- }
106
- /**
107
- * Get MCP-I capabilities
108
- */
109
- getCapabilities() {
110
- return {
111
- version: '1.0',
112
- did: this.did,
113
- publicKey: this.publicKey,
114
- conformanceLevel: 1
115
- };
116
- }
117
- /**
118
- * Sign an MCP response
119
- */
120
- signResponse(response) {
121
- return {
122
- ...response,
123
- _mcp_identity: {
124
- did: this.did,
125
- signature: this.sign(JSON.stringify(response)),
126
- timestamp: new Date().toISOString()
127
- }
128
- };
129
- }
130
- }
131
- exports.MCPIdentity = MCPIdentity;
132
- // Helper functions (inline to keep package standalone)
133
- async function loadIdentity(customPath) {
134
- // Check environment variables first
135
- if (process.env.AGENT_DID && process.env.AGENT_PUBLIC_KEY && process.env.AGENT_PRIVATE_KEY) {
136
- return {
137
- did: process.env.AGENT_DID,
138
- publicKey: process.env.AGENT_PUBLIC_KEY,
139
- privateKey: process.env.AGENT_PRIVATE_KEY,
140
- agentId: process.env.AGENT_ID || '',
141
- agentSlug: process.env.AGENT_SLUG || '',
142
- registeredAt: new Date().toISOString()
143
- };
144
- }
145
- // Check file
146
- const filePath = customPath || path.join(process.cwd(), '.mcp-identity.json');
147
- try {
148
- if (fs.existsSync(filePath)) {
149
- const content = fs.readFileSync(filePath, 'utf-8');
150
- return JSON.parse(content);
151
- }
152
- }
153
- catch {
154
- // Ignore errors
155
- }
156
- return null;
157
- }
158
- async function saveIdentity(identity, customPath) {
159
- // Save to .env.local
160
- const envContent = `
161
- # MCP-I Identity (auto-generated)
162
- AGENT_DID="${identity.did}"
163
- AGENT_PUBLIC_KEY="${identity.publicKey}"
164
- AGENT_PRIVATE_KEY="${identity.privateKey}"
165
- AGENT_ID="${identity.agentId}"
166
- AGENT_SLUG="${identity.agentSlug}"
167
- `;
168
- const envPath = path.join(process.cwd(), '.env.local');
169
- fs.writeFileSync(envPath, envContent.trim());
170
- // Also save as JSON
171
- const filePath = customPath || path.join(process.cwd(), '.mcp-identity.json');
172
- fs.writeFileSync(filePath, JSON.stringify(identity, null, 2));
173
- }
174
- async function autoRegister(options) {
175
- try {
176
- const response = await axios_1.default.post(`${options.apiEndpoint}/api/agents/auto-register`, {
177
- metadata: {
178
- name: options.name,
179
- description: options.description,
180
- repository: options.repository,
181
- version: '1.0.0'
182
- },
183
- clientInfo: {
184
- sdkVersion: '0.1.0',
185
- language: 'typescript',
186
- platform: 'node' // Always node for MCP servers
187
- }
188
- }, {
189
- timeout: 30000,
190
- headers: {
191
- 'Content-Type': 'application/json',
192
- 'User-Agent': '@kya-os/mcp-i/0.1.0'
193
- }
194
- });
195
- return response.data;
196
- }
197
- catch (error) {
198
- if (error.response?.status === 429) {
199
- throw new Error('Rate limit exceeded. Please try again later.');
200
- }
201
- throw new Error(error.response?.data?.message ||
202
- error.message ||
203
- 'Failed to auto-register agent');
204
- }
205
- }
206
- //# sourceMappingURL=index.js.map
20
+ exports.compile = exports.jwtAuthMiddleware = exports.apiKeyAuthMiddleware = void 0;
21
+ const dotenv_1 = __importDefault(require("dotenv"));
22
+ dotenv_1.default.config();
23
+ var api_key_1 = require("./auth/api-key");
24
+ Object.defineProperty(exports, "apiKeyAuthMiddleware", { enumerable: true, get: function () { return api_key_1.apiKeyAuthMiddleware; } });
25
+ var jwt_1 = require("./auth/jwt");
26
+ Object.defineProperty(exports, "jwtAuthMiddleware", { enumerable: true, get: function () { return jwt_1.jwtAuthMiddleware; } });
27
+ require("./types/declarations");
28
+ // Test infrastructure (only available when XMCP_ENV=test)
29
+ __exportStar(require("./test/index"), exports);
30
+ // Nonce cache for replay prevention
31
+ __exportStar(require("./cache/index"), exports);
32
+ // Identity management for CLI and runtime
33
+ __exportStar(require("./runtime/identity"), exports);
34
+ // Runtime creation and management
35
+ __exportStar(require("./runtime/index"), exports);
36
+ // Compiler for CLI usage
37
+ var index_1 = require("./compiler/index");
38
+ Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return index_1.compile; } });
@@ -0,0 +1,49 @@
1
+ /*
2
+ object-assign
3
+ (c) Sindre Sorhus
4
+ @license MIT
5
+ */
6
+
7
+ /*!
8
+ * fill-range <https://github.com/jonschlinkert/fill-range>
9
+ *
10
+ * Copyright (c) 2014-present, Jon Schlinkert.
11
+ * Licensed under the MIT License.
12
+ */
13
+
14
+ /*!
15
+ * is-extglob <https://github.com/jonschlinkert/is-extglob>
16
+ *
17
+ * Copyright (c) 2014-2016, Jon Schlinkert.
18
+ * Licensed under the MIT License.
19
+ */
20
+
21
+ /*!
22
+ * is-glob <https://github.com/jonschlinkert/is-glob>
23
+ *
24
+ * Copyright (c) 2014-2017, Jon Schlinkert.
25
+ * Released under the MIT License.
26
+ */
27
+
28
+ /*!
29
+ * is-number <https://github.com/jonschlinkert/is-number>
30
+ *
31
+ * Copyright (c) 2014-present, Jon Schlinkert.
32
+ * Released under the MIT License.
33
+ */
34
+
35
+ /*!
36
+ * normalize-path <https://github.com/jonschlinkert/normalize-path>
37
+ *
38
+ * Copyright (c) 2014-2018, Jon Schlinkert.
39
+ * Released under the MIT License.
40
+ */
41
+
42
+ /*!
43
+ * to-regex-range <https://github.com/micromatch/to-regex-range>
44
+ *
45
+ * Copyright (c) 2015-present, Jon Schlinkert.
46
+ * Released under the MIT License.
47
+ */
48
+
49
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Tests for Audit Logging System
3
+ */
4
+ export {};