@kya-os/mcp-i 1.2.7 → 1.2.9

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.
@@ -3,6 +3,8 @@ import { XmcpConfigOuputSchema } from "./config";
3
3
  interface CompilerContext {
4
4
  /** The mode of the compiler. */
5
5
  mode: CompilerMode;
6
+ /** The project root directory (absolute path). */
7
+ projectRoot: string;
6
8
  /** Whether the adapter is enabled. */
7
9
  adapter?: boolean;
8
10
  /** The platforms to build for. */
@@ -23,7 +23,7 @@ export declare function injectStdioVariables(stdioConfig: any): {
23
23
  STDIO_CONFIG: string;
24
24
  };
25
25
  export type StdioVariables = ReturnType<typeof injectStdioVariables>;
26
- export declare function injectIdentityVariables(identityConfig: any, mode: string): {
26
+ export declare function injectIdentityVariables(identityConfig: any, mode: string, projectRoot: string): {
27
27
  IDENTITY_CONFIG: string;
28
28
  };
29
29
  export type IdentityVariables = ReturnType<typeof injectIdentityVariables>;
@@ -11,67 +11,87 @@ function injectHttpVariables(httpConfig, mode) {
11
11
  const resolvedConfig = (0, utils_1.getResolvedHttpConfig)(httpConfig);
12
12
  if (!resolvedConfig)
13
13
  return {};
14
+ // Double-stringify for webpack DefinePlugin - it replaces the variable with the raw value,
15
+ // so we need to stringify twice to inject an actual string literal
14
16
  return {
15
- HTTP_CONFIG: JSON.stringify({
17
+ HTTP_CONFIG: JSON.stringify(JSON.stringify({
16
18
  port: resolvedConfig.port,
17
19
  host: resolvedConfig.host,
18
20
  bodySizeLimit: resolvedConfig.bodySizeLimit,
19
21
  endpoint: resolvedConfig.endpoint,
20
22
  stateless: true,
21
23
  debug: mode === "development",
22
- }),
24
+ })),
23
25
  };
24
26
  }
25
27
  function injectCorsVariables(httpConfig) {
26
28
  const corsConfig = (0, utils_1.getResolvedCorsConfig)(httpConfig);
29
+ // Double-stringify for webpack DefinePlugin
27
30
  return {
28
- HTTP_CORS_CONFIG: JSON.stringify({
31
+ HTTP_CORS_CONFIG: JSON.stringify(JSON.stringify({
29
32
  origin: corsConfig.origin ?? "",
30
33
  methods: corsConfig.methods ?? "",
31
34
  allowedHeaders: corsConfig.allowedHeaders ?? "",
32
35
  exposedHeaders: corsConfig.exposedHeaders ?? "",
33
36
  credentials: corsConfig.credentials ?? false,
34
37
  maxAge: corsConfig.maxAge ?? 0,
35
- }),
38
+ })),
36
39
  };
37
40
  }
38
41
  function injectOAuthVariables(userConfig) {
39
42
  const oauthConfig = (0, utils_1.getResolvedOAuthConfig)(userConfig);
43
+ // Double-stringify for webpack DefinePlugin
40
44
  return {
41
- OAUTH_CONFIG: JSON.stringify(oauthConfig),
45
+ OAUTH_CONFIG: JSON.stringify(JSON.stringify(oauthConfig)),
42
46
  };
43
47
  }
44
48
  function injectPathsVariables(userConfig) {
45
49
  const pathsConfig = (0, utils_1.getResolvedPathsConfig)(userConfig);
50
+ // Double-stringify for webpack DefinePlugin
46
51
  return {
47
- TOOLS_PATH: JSON.stringify(pathsConfig.tools),
52
+ TOOLS_PATH: JSON.stringify(JSON.stringify(pathsConfig.tools)),
48
53
  };
49
54
  }
50
55
  function injectStdioVariables(stdioConfig) {
51
56
  if (!stdioConfig)
52
57
  return {};
53
58
  const debug = typeof stdioConfig === "object" ? stdioConfig.debug : false;
59
+ // Double-stringify for webpack DefinePlugin
54
60
  return {
55
- STDIO_CONFIG: JSON.stringify({
61
+ STDIO_CONFIG: JSON.stringify(JSON.stringify({
56
62
  debug,
57
- }),
63
+ })),
58
64
  };
59
65
  }
60
- function injectIdentityVariables(identityConfig, mode) {
66
+ function injectIdentityVariables(identityConfig, mode, projectRoot) {
61
67
  if (!identityConfig || !identityConfig.enabled) {
68
+ // Double-stringify for webpack DefinePlugin
62
69
  return {
63
- IDENTITY_CONFIG: JSON.stringify({
70
+ IDENTITY_CONFIG: JSON.stringify(JSON.stringify({
64
71
  enabled: false,
65
- }),
72
+ })),
66
73
  };
67
74
  }
75
+ // Resolve devIdentityPath to absolute path at compile time
76
+ // This ensures the bundle can find the identity file regardless of CWD at runtime
77
+ const path = require("path");
78
+ const devIdentityPath = identityConfig.devIdentityPath || ".mcpi/identity.json";
79
+ const absoluteIdentityPath = path.isAbsolute(devIdentityPath)
80
+ ? devIdentityPath
81
+ : path.join(projectRoot, devIdentityPath);
82
+ // Debug: log the resolved path
83
+ console.log("[COMPILER] Identity path resolution:");
84
+ console.log(" projectRoot:", projectRoot);
85
+ console.log(" devIdentityPath:", devIdentityPath);
86
+ console.log(" absoluteIdentityPath:", absoluteIdentityPath);
87
+ // Double-stringify for webpack DefinePlugin
68
88
  return {
69
- IDENTITY_CONFIG: JSON.stringify({
89
+ IDENTITY_CONFIG: JSON.stringify(JSON.stringify({
70
90
  enabled: true,
71
91
  environment: identityConfig.environment || mode,
72
- devIdentityPath: identityConfig.devIdentityPath,
92
+ devIdentityPath: absoluteIdentityPath,
73
93
  privacyMode: identityConfig.privacyMode || false,
74
94
  debug: identityConfig.debug || mode === "development",
75
- }),
95
+ })),
76
96
  };
77
97
  }
@@ -9,13 +9,13 @@ const injection_1 = require("../config/injection");
9
9
  * This utility will define those variables based on the user's config.
10
10
  */
11
11
  function getInjectedVariables(xmcpConfig) {
12
- const { mode } = compiler_context_1.compilerContext.getContext();
12
+ const { mode, projectRoot } = compiler_context_1.compilerContext.getContext();
13
13
  const httpVariables = (0, injection_1.injectHttpVariables)(xmcpConfig.http, mode);
14
14
  const corsVariables = (0, injection_1.injectCorsVariables)(xmcpConfig.http);
15
15
  const oauthVariables = (0, injection_1.injectOAuthVariables)(xmcpConfig);
16
16
  const pathsVariables = (0, injection_1.injectPathsVariables)(xmcpConfig);
17
17
  const stdioVariables = (0, injection_1.injectStdioVariables)(xmcpConfig.stdio);
18
- const identityVariables = (0, injection_1.injectIdentityVariables)(xmcpConfig.identity, mode);
18
+ const identityVariables = (0, injection_1.injectIdentityVariables)(xmcpConfig.identity, mode, projectRoot);
19
19
  return {
20
20
  ...httpVariables,
21
21
  ...corsVariables,
@@ -51,9 +51,9 @@ const getDefaultRuntimeFiles = () => {
51
51
  }
52
52
  return runtimeFiles;
53
53
  };
54
- exports.runtimeFiles = (typeof RUNTIME_FILES !== "undefined"
55
- ? RUNTIME_FILES
56
- : getDefaultRuntimeFiles());
54
+ // IMPORTANT: Always use getDefaultRuntimeFiles() to ensure we get the latest runtime files
55
+ // DefinePlugin embedding was causing stale file issues
56
+ exports.runtimeFiles = getDefaultRuntimeFiles();
57
57
  class InjectRuntimePlugin {
58
58
  apply(compiler) {
59
59
  let hasRun = false;
@@ -47,6 +47,7 @@ async function compile({ onBuild } = {}) {
47
47
  return new Promise((resolve, reject) => {
48
48
  (0, compiler_context_1.compilerContextProvider)({
49
49
  mode,
50
+ projectRoot: process.cwd(),
50
51
  platforms: {},
51
52
  }, () => {
52
53
  compileInternal({ onBuild }).then(resolve).catch(reject);
@@ -175,7 +176,13 @@ async function compileInternal({ onBuild } = {}) {
175
176
  compiler.run(handleCompilation);
176
177
  }
177
178
  else {
178
- compiler.watch({}, handleCompilation);
179
+ const watching = compiler.watch({}, handleCompilation);
180
+ // Store watching instance for proper cleanup
181
+ process.on('SIGINT', () => {
182
+ watching.close(() => {
183
+ process.exit(0);
184
+ });
185
+ });
179
186
  }
180
187
  });
181
188
  });