@yinuo-ngm/mcp-server 0.1.1 → 0.1.3

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 (221) hide show
  1. package/README.md +225 -188
  2. package/lib/audit/audit-event.d.ts +14 -0
  3. package/lib/audit/audit-event.js +2 -0
  4. package/lib/audit/audit-log.service.d.ts +7 -0
  5. package/lib/audit/audit-log.service.js +187 -0
  6. package/lib/audit/redact.d.ts +3 -0
  7. package/lib/audit/redact.js +28 -0
  8. package/lib/catalog/capabilities/blocked-local-actions.d.ts +1 -0
  9. package/lib/catalog/capabilities/blocked-local-actions.js +18 -0
  10. package/lib/catalog/capabilities/frontend-standard.d.ts +2 -0
  11. package/lib/catalog/capabilities/frontend-standard.js +36 -0
  12. package/lib/catalog/capabilities/hub-v2.d.ts +2 -0
  13. package/lib/catalog/capabilities/hub-v2.js +34 -0
  14. package/lib/catalog/capabilities/nginx.d.ts +2 -0
  15. package/lib/catalog/capabilities/nginx.js +23 -0
  16. package/lib/catalog/capabilities/project.d.ts +2 -0
  17. package/lib/catalog/capabilities/project.js +23 -0
  18. package/lib/catalog/capabilities/router.d.ts +2 -0
  19. package/lib/catalog/capabilities/router.js +11 -0
  20. package/lib/catalog/capabilities/runtime.d.ts +2 -0
  21. package/lib/catalog/capabilities/runtime.js +17 -0
  22. package/lib/catalog/capabilities/workspace.d.ts +2 -0
  23. package/lib/catalog/capabilities/workspace.js +23 -0
  24. package/lib/catalog/helpers.d.ts +3 -0
  25. package/lib/catalog/helpers.js +42 -0
  26. package/lib/catalog/index.d.ts +4 -0
  27. package/lib/catalog/index.js +23 -0
  28. package/lib/catalog/tools/frontend-standard.d.ts +2 -0
  29. package/lib/catalog/tools/frontend-standard.js +166 -0
  30. package/lib/catalog/tools/hub-v2-api.d.ts +2 -0
  31. package/lib/catalog/tools/hub-v2-api.js +124 -0
  32. package/lib/catalog/tools/hub-v2-docs.d.ts +2 -0
  33. package/lib/catalog/tools/hub-v2-docs.js +40 -0
  34. package/lib/catalog/tools/nginx.d.ts +2 -0
  35. package/lib/catalog/tools/nginx.js +96 -0
  36. package/lib/catalog/tools/project.d.ts +2 -0
  37. package/lib/catalog/tools/project.js +138 -0
  38. package/lib/catalog/tools/router.d.ts +2 -0
  39. package/lib/catalog/tools/router.js +26 -0
  40. package/lib/catalog/tools/runtime.d.ts +2 -0
  41. package/lib/catalog/tools/runtime.js +47 -0
  42. package/lib/catalog/tools/workspace.d.ts +2 -0
  43. package/lib/catalog/tools/workspace.js +75 -0
  44. package/lib/catalog/types.d.ts +15 -0
  45. package/lib/catalog/types.js +2 -0
  46. package/lib/context/create-tool-context.js +11 -10
  47. package/lib/context/local-server-client.d.ts +2 -0
  48. package/lib/context/local-server-client.js +174 -0
  49. package/lib/context/tool-context.d.ts +36 -0
  50. package/lib/doctor.d.ts +8 -0
  51. package/lib/doctor.js +221 -0
  52. package/lib/errors/error-codes.d.ts +12 -0
  53. package/lib/errors/error-codes.js +14 -0
  54. package/lib/errors/mcp-tool-error.d.ts +8 -0
  55. package/lib/errors/mcp-tool-error.js +14 -0
  56. package/lib/filesystem/project-files.d.ts +18 -0
  57. package/lib/filesystem/project-files.js +112 -0
  58. package/lib/git/local-git-read-service.d.ts +2 -0
  59. package/lib/git/local-git-read-service.js +96 -0
  60. package/lib/index.d.ts +1 -0
  61. package/lib/index.js +4 -0
  62. package/lib/policy/assert-tool-policy.js +10 -1
  63. package/lib/register-tools.js +70 -9
  64. package/lib/registry/tool-names.d.ts +95 -0
  65. package/lib/registry/tool-names.js +97 -0
  66. package/lib/services/path-guard.service.d.ts +4 -0
  67. package/lib/services/path-guard.service.js +75 -0
  68. package/lib/services/permission.service.d.ts +5 -0
  69. package/lib/services/permission.service.js +38 -0
  70. package/lib/services/project-resolver.service.d.ts +32 -0
  71. package/lib/services/project-resolver.service.js +95 -0
  72. package/lib/standard/frontend-standard.default.d.ts +2 -0
  73. package/lib/standard/frontend-standard.default.js +51 -0
  74. package/lib/standard/frontend-standard.schema.d.ts +196 -0
  75. package/lib/standard/frontend-standard.schema.js +61 -0
  76. package/lib/standard/frontend-standard.service.d.ts +79 -0
  77. package/lib/standard/frontend-standard.service.js +115 -0
  78. package/lib/standard/project-scan.d.ts +9 -0
  79. package/lib/standard/project-scan.js +91 -0
  80. package/lib/standard/validators/angular-structure.validator.d.ts +4 -0
  81. package/lib/standard/validators/angular-structure.validator.js +75 -0
  82. package/lib/standard/validators/component.validator.d.ts +4 -0
  83. package/lib/standard/validators/component.validator.js +94 -0
  84. package/lib/standard/validators/git.validator.d.ts +8 -0
  85. package/lib/standard/validators/git.validator.js +32 -0
  86. package/lib/standard/validators/review.validator.d.ts +15 -0
  87. package/lib/standard/validators/review.validator.js +67 -0
  88. package/lib/standard/validators/test.validator.d.ts +19 -0
  89. package/lib/standard/validators/test.validator.js +89 -0
  90. package/lib/tool-catalog.d.ts +2 -0
  91. package/lib/tool-catalog.js +6 -0
  92. package/lib/tools/angular/angular-standard.tools.d.ts +2 -0
  93. package/lib/tools/angular/angular-standard.tools.js +53 -0
  94. package/lib/tools/angular/index.d.ts +1 -0
  95. package/lib/tools/angular/index.js +5 -0
  96. package/lib/tools/capability.tools.d.ts +2 -0
  97. package/lib/tools/capability.tools.js +205 -0
  98. package/lib/tools/controlled/index.d.ts +2 -0
  99. package/lib/tools/controlled/index.js +13 -0
  100. package/lib/tools/controlled/local-server.d.ts +6 -0
  101. package/lib/tools/controlled/local-server.js +17 -0
  102. package/lib/tools/controlled/operation-policy.d.ts +22 -0
  103. package/lib/tools/controlled/operation-policy.js +50 -0
  104. package/lib/tools/controlled/operation-result.d.ts +30 -0
  105. package/lib/tools/controlled/operation-result.js +33 -0
  106. package/lib/tools/controlled/schemas.d.ts +159 -0
  107. package/lib/tools/controlled/schemas.js +49 -0
  108. package/lib/tools/controlled.tools.d.ts +1 -0
  109. package/lib/tools/controlled.tools.js +5 -0
  110. package/lib/tools/file-write.tools.d.ts +2 -0
  111. package/lib/tools/file-write.tools.js +70 -0
  112. package/lib/tools/git.tools.js +109 -8
  113. package/lib/tools/hub-v2/client.d.ts +20 -0
  114. package/lib/tools/hub-v2/client.js +112 -0
  115. package/lib/tools/hub-v2/config/config-paths.d.ts +2 -0
  116. package/lib/tools/hub-v2/config/config-paths.js +17 -0
  117. package/lib/tools/hub-v2/config/env.d.ts +1 -0
  118. package/lib/tools/hub-v2/config/env.js +12 -0
  119. package/lib/tools/hub-v2/config/index.d.ts +8 -0
  120. package/lib/tools/hub-v2/config/index.js +18 -0
  121. package/lib/tools/hub-v2/config/jsonc.d.ts +5 -0
  122. package/lib/tools/hub-v2/config/jsonc.js +86 -0
  123. package/lib/tools/hub-v2/config/load-config.d.ts +18 -0
  124. package/lib/tools/hub-v2/config/load-config.js +93 -0
  125. package/lib/tools/hub-v2/config/project-selector.d.ts +5 -0
  126. package/lib/tools/hub-v2/config/project-selector.js +92 -0
  127. package/lib/tools/hub-v2/config/resolve-context.d.ts +13 -0
  128. package/lib/tools/hub-v2/config/resolve-context.js +33 -0
  129. package/lib/tools/hub-v2/docs.tools.d.ts +2 -0
  130. package/lib/tools/hub-v2/docs.tools.js +215 -0
  131. package/lib/tools/hub-v2/errors.d.ts +8 -0
  132. package/lib/tools/hub-v2/errors.js +27 -0
  133. package/lib/tools/hub-v2/index.d.ts +2 -0
  134. package/lib/tools/hub-v2/index.js +19 -0
  135. package/lib/tools/hub-v2/issues-workflow.tools.d.ts +2 -0
  136. package/lib/tools/hub-v2/issues-workflow.tools.js +199 -0
  137. package/lib/tools/hub-v2/issues.tools.d.ts +2 -0
  138. package/lib/tools/hub-v2/issues.tools.js +244 -0
  139. package/lib/tools/hub-v2/projects.tools.d.ts +2 -0
  140. package/lib/tools/hub-v2/projects.tools.js +41 -0
  141. package/lib/tools/hub-v2/raw.d.ts +8 -0
  142. package/lib/tools/hub-v2/raw.js +33 -0
  143. package/lib/tools/hub-v2/rd.tools.d.ts +2 -0
  144. package/lib/tools/hub-v2/rd.tools.js +361 -0
  145. package/lib/tools/hub-v2/schemas.d.ts +1182 -0
  146. package/lib/tools/hub-v2/schemas.js +318 -0
  147. package/lib/tools/hub-v2/upload.tools.d.ts +2 -0
  148. package/lib/tools/hub-v2/upload.tools.js +198 -0
  149. package/lib/tools/index.d.ts +3 -0
  150. package/lib/tools/index.js +24 -0
  151. package/lib/tools/log.tools.js +33 -6
  152. package/lib/tools/nginx/index.d.ts +1 -0
  153. package/lib/tools/nginx/index.js +5 -0
  154. package/lib/tools/nginx/nginx-control.tools.d.ts +2 -0
  155. package/lib/tools/nginx/nginx-control.tools.js +133 -0
  156. package/lib/tools/nginx/nginx-proxy.d.ts +24 -0
  157. package/lib/tools/nginx/nginx-proxy.js +154 -0
  158. package/lib/tools/nginx.tools.d.ts +2 -0
  159. package/lib/tools/nginx.tools.js +111 -0
  160. package/lib/tools/project/index.d.ts +2 -0
  161. package/lib/tools/project/index.js +7 -0
  162. package/lib/tools/project/launch-status.d.ts +10 -0
  163. package/lib/tools/project/launch-status.js +78 -0
  164. package/lib/tools/project/local-diagnostics.d.ts +19 -0
  165. package/lib/tools/project/local-diagnostics.js +97 -0
  166. package/lib/tools/project/observe-redaction.d.ts +3 -0
  167. package/lib/tools/project/observe-redaction.js +25 -0
  168. package/lib/tools/project/observe-runtime.d.ts +72 -0
  169. package/lib/tools/project/observe-runtime.js +147 -0
  170. package/lib/tools/project/project-control.tools.d.ts +2 -0
  171. package/lib/tools/project/project-control.tools.js +216 -0
  172. package/lib/tools/project/project-observe.tools.d.ts +2 -0
  173. package/lib/tools/project/project-observe.tools.js +191 -0
  174. package/lib/tools/project/runtime-config.d.ts +7 -0
  175. package/lib/tools/project/runtime-config.js +50 -0
  176. package/lib/tools/project-observe.tools.d.ts +1 -0
  177. package/lib/tools/project-observe.tools.js +5 -0
  178. package/lib/tools/project.tools.d.ts +8 -0
  179. package/lib/tools/project.tools.js +97 -6
  180. package/lib/tools/proxy.tools.js +4 -4
  181. package/lib/tools/review/index.d.ts +1 -0
  182. package/lib/tools/review/index.js +5 -0
  183. package/lib/tools/review/review.tools.d.ts +2 -0
  184. package/lib/tools/review/review.tools.js +152 -0
  185. package/lib/tools/runtime/index.d.ts +1 -0
  186. package/lib/tools/runtime/index.js +5 -0
  187. package/lib/tools/runtime/runtime-control.tools.d.ts +2 -0
  188. package/lib/tools/runtime/runtime-control.tools.js +89 -0
  189. package/lib/tools/runtime.tools.js +41 -4
  190. package/lib/tools/standard/index.d.ts +1 -0
  191. package/lib/tools/standard/index.js +5 -0
  192. package/lib/tools/standard/standard.tools.d.ts +2 -0
  193. package/lib/tools/standard/standard.tools.js +91 -0
  194. package/lib/tools/task.tools.js +44 -9
  195. package/lib/tools/test/index.d.ts +1 -0
  196. package/lib/tools/test/index.js +5 -0
  197. package/lib/tools/test/test-standard.tools.d.ts +2 -0
  198. package/lib/tools/test/test-standard.tools.js +51 -0
  199. package/lib/tools/tool-catalog.d.ts +2 -0
  200. package/lib/tools/tool-catalog.js +7 -0
  201. package/lib/tools/workflow/frontend-workflow.tools.d.ts +2 -0
  202. package/lib/tools/workflow/frontend-workflow.tools.js +364 -0
  203. package/lib/tools/workflow/index.d.ts +1 -0
  204. package/lib/tools/workflow/index.js +5 -0
  205. package/lib/tools/workspace-package.d.ts +22 -0
  206. package/lib/tools/workspace-package.js +130 -0
  207. package/lib/tools/workspace.tools.d.ts +7 -0
  208. package/lib/tools/workspace.tools.js +336 -0
  209. package/lib/utils/errors.d.ts +5 -0
  210. package/lib/utils/errors.js +17 -0
  211. package/lib/utils/result.d.ts +20 -2
  212. package/lib/utils/result.js +108 -3
  213. package/lib/workflow/frontend-task.schema.d.ts +83 -0
  214. package/lib/workflow/frontend-task.schema.js +25 -0
  215. package/lib/workflow/frontend-task.service.d.ts +57 -0
  216. package/lib/workflow/frontend-task.service.js +195 -0
  217. package/lib/workflow/workflow-status.d.ts +2 -0
  218. package/lib/workflow/workflow-status.js +14 -0
  219. package/lib/workflow/workflow-transition.d.ts +9 -0
  220. package/lib/workflow/workflow-transition.js +38 -0
  221. package/package.json +10 -4
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HubV2Client = void 0;
4
+ exports.compact = compact;
5
+ exports.compactUndefined = compactUndefined;
6
+ const errors_1 = require("./errors");
7
+ class HubV2Client {
8
+ constructor(context) {
9
+ this.context = context;
10
+ }
11
+ tokenUrl(suffix, query) {
12
+ return this.queryUrl("api/token", suffix, query);
13
+ }
14
+ personalUrl(suffix, query) {
15
+ return this.queryUrl("api/personal", suffix, query);
16
+ }
17
+ async request(method, url, body, options = {}) {
18
+ const headers = { Authorization: `Bearer ${this.context.token}` };
19
+ const init = { method, headers };
20
+ if (body !== undefined) {
21
+ headers["Content-Type"] = "application/json";
22
+ init.body = JSON.stringify(options.preserveNull ? compactUndefined(body) : compact(body));
23
+ }
24
+ const response = await fetch(url, init);
25
+ const text = await response.text();
26
+ const parsed = parseResponseBody(text);
27
+ if (!response.ok) {
28
+ throw (0, errors_1.toHubV2HttpError)(response.status, response.statusText, parsed);
29
+ }
30
+ return (parsed ?? { code: "OK", data: null });
31
+ }
32
+ async multipart(method, url, body) {
33
+ const response = await fetch(url, {
34
+ method,
35
+ headers: { Authorization: `Bearer ${this.context.token}` },
36
+ body,
37
+ });
38
+ const text = await response.text();
39
+ const parsed = parseResponseBody(text);
40
+ if (!response.ok) {
41
+ throw (0, errors_1.toHubV2HttpError)(response.status, response.statusText, parsed);
42
+ }
43
+ return (parsed ?? { code: "OK", data: null });
44
+ }
45
+ async raw(method, url) {
46
+ const response = await fetch(url, {
47
+ method,
48
+ headers: { Authorization: `Bearer ${this.context.token}` },
49
+ });
50
+ if (!response.ok) {
51
+ const text = await response.text();
52
+ throw (0, errors_1.toHubV2HttpError)(response.status, response.statusText, parseResponseBody(text));
53
+ }
54
+ return {
55
+ content: Buffer.from(await response.arrayBuffer()),
56
+ contentType: response.headers.get("content-type") ?? "application/octet-stream",
57
+ contentDisposition: response.headers.get("content-disposition"),
58
+ };
59
+ }
60
+ queryUrl(prefix, suffix, query) {
61
+ let url = `${this.context.baseUrl}/${prefix}/projects/${encodeURIComponent(this.context.projectKey)}${suffix}`;
62
+ const queryString = toQueryString(query ?? {});
63
+ if (queryString) {
64
+ url += `?${queryString}`;
65
+ }
66
+ return url;
67
+ }
68
+ }
69
+ exports.HubV2Client = HubV2Client;
70
+ function compact(values) {
71
+ const result = {};
72
+ for (const [key, value] of Object.entries(values)) {
73
+ if (value !== undefined && value !== null && !(Array.isArray(value) && value.length === 0)) {
74
+ result[key] = value;
75
+ }
76
+ }
77
+ return result;
78
+ }
79
+ function compactUndefined(values) {
80
+ const result = {};
81
+ for (const [key, value] of Object.entries(values)) {
82
+ if (value !== undefined && !(Array.isArray(value) && value.length === 0)) {
83
+ result[key] = value;
84
+ }
85
+ }
86
+ return result;
87
+ }
88
+ function toQueryString(values) {
89
+ const params = new URLSearchParams();
90
+ for (const [key, value] of Object.entries(compact(values))) {
91
+ if (Array.isArray(value)) {
92
+ for (const item of value) {
93
+ params.append(key, String(item));
94
+ }
95
+ }
96
+ else {
97
+ params.set(key, String(value));
98
+ }
99
+ }
100
+ return params.toString();
101
+ }
102
+ function parseResponseBody(text) {
103
+ if (!text.trim()) {
104
+ return undefined;
105
+ }
106
+ try {
107
+ return JSON.parse(text);
108
+ }
109
+ catch {
110
+ return text;
111
+ }
112
+ }
@@ -0,0 +1,2 @@
1
+ export declare function resolveAgentConnectionsPath(): string;
2
+ export declare function configSearchPaths(pathValue?: string): string[];
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveAgentConnectionsPath = resolveAgentConnectionsPath;
4
+ exports.configSearchPaths = configSearchPaths;
5
+ const os_1 = require("os");
6
+ const path_1 = require("path");
7
+ const env_1 = require("./env");
8
+ function resolveAgentConnectionsPath() {
9
+ const envConfig = (0, env_1.envValue)("HUB_V2_CONFIG");
10
+ if (envConfig) {
11
+ return (0, path_1.resolve)(envConfig);
12
+ }
13
+ return (0, path_1.join)((0, os_1.homedir)(), ".ng-manager", "agent-connections.json");
14
+ }
15
+ function configSearchPaths(pathValue) {
16
+ return pathValue ? [(0, path_1.resolve)(pathValue)] : [resolveAgentConnectionsPath()];
17
+ }
@@ -0,0 +1 @@
1
+ export declare function envValue(...names: string[]): string | undefined;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.envValue = envValue;
4
+ function envValue(...names) {
5
+ for (const name of names) {
6
+ const value = process.env[name];
7
+ if (value !== undefined && value !== null && String(value).trim()) {
8
+ return String(value).trim();
9
+ }
10
+ }
11
+ return undefined;
12
+ }
@@ -0,0 +1,8 @@
1
+ export { resolveAgentConnectionsPath } from "./config-paths";
2
+ export { envValue } from "./env";
3
+ export { loadConfig, normalizeConfig } from "./load-config";
4
+ export type { HubV2Config, HubV2ProjectConfig } from "./load-config";
5
+ export { loadJsonFile, parseJsonObject } from "./jsonc";
6
+ export { getConfiguredProject, listConfiguredProjects } from "./project-selector";
7
+ export { resolveHubV2Context } from "./resolve-context";
8
+ export type { HubV2ResolvedContext, HubV2ResolveOptions } from "./resolve-context";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveHubV2Context = exports.listConfiguredProjects = exports.getConfiguredProject = exports.parseJsonObject = exports.loadJsonFile = exports.normalizeConfig = exports.loadConfig = exports.envValue = exports.resolveAgentConnectionsPath = void 0;
4
+ var config_paths_1 = require("./config-paths");
5
+ Object.defineProperty(exports, "resolveAgentConnectionsPath", { enumerable: true, get: function () { return config_paths_1.resolveAgentConnectionsPath; } });
6
+ var env_1 = require("./env");
7
+ Object.defineProperty(exports, "envValue", { enumerable: true, get: function () { return env_1.envValue; } });
8
+ var load_config_1 = require("./load-config");
9
+ Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return load_config_1.loadConfig; } });
10
+ Object.defineProperty(exports, "normalizeConfig", { enumerable: true, get: function () { return load_config_1.normalizeConfig; } });
11
+ var jsonc_1 = require("./jsonc");
12
+ Object.defineProperty(exports, "loadJsonFile", { enumerable: true, get: function () { return jsonc_1.loadJsonFile; } });
13
+ Object.defineProperty(exports, "parseJsonObject", { enumerable: true, get: function () { return jsonc_1.parseJsonObject; } });
14
+ var project_selector_1 = require("./project-selector");
15
+ Object.defineProperty(exports, "getConfiguredProject", { enumerable: true, get: function () { return project_selector_1.getConfiguredProject; } });
16
+ Object.defineProperty(exports, "listConfiguredProjects", { enumerable: true, get: function () { return project_selector_1.listConfiguredProjects; } });
17
+ var resolve_context_1 = require("./resolve-context");
18
+ Object.defineProperty(exports, "resolveHubV2Context", { enumerable: true, get: function () { return resolve_context_1.resolveHubV2Context; } });
@@ -0,0 +1,5 @@
1
+ export declare function asRecord(value: unknown): Record<string, unknown>;
2
+ export declare function getString(record: Record<string, unknown>, ...keys: string[]): string | undefined;
3
+ export declare function putIfValue(target: Record<string, unknown>, key: string, value: unknown): void;
4
+ export declare function parseJsonObject(content: string): Record<string, unknown>;
5
+ export declare function loadJsonFile(path: string): Record<string, unknown>;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.asRecord = asRecord;
4
+ exports.getString = getString;
5
+ exports.putIfValue = putIfValue;
6
+ exports.parseJsonObject = parseJsonObject;
7
+ exports.loadJsonFile = loadJsonFile;
8
+ const fs_1 = require("fs");
9
+ function asRecord(value) {
10
+ return value && typeof value === "object" && !Array.isArray(value)
11
+ ? value
12
+ : {};
13
+ }
14
+ function getString(record, ...keys) {
15
+ for (const key of keys) {
16
+ const value = record[key];
17
+ if (value !== undefined && value !== null && String(value).trim()) {
18
+ return String(value).trim();
19
+ }
20
+ }
21
+ return undefined;
22
+ }
23
+ function putIfValue(target, key, value) {
24
+ if (value !== undefined && value !== null && String(value).trim()) {
25
+ target[key] = String(value).trim();
26
+ }
27
+ }
28
+ function stripJsonComments(input) {
29
+ let output = "";
30
+ let inString = false;
31
+ let stringQuote = "";
32
+ let escaped = false;
33
+ for (let index = 0; index < input.length; index += 1) {
34
+ const char = input[index];
35
+ const next = input[index + 1];
36
+ if (inString) {
37
+ output += char;
38
+ if (escaped) {
39
+ escaped = false;
40
+ }
41
+ else if (char === "\\") {
42
+ escaped = true;
43
+ }
44
+ else if (char === stringQuote) {
45
+ inString = false;
46
+ }
47
+ continue;
48
+ }
49
+ if (char === '"' || char === "'") {
50
+ inString = true;
51
+ stringQuote = char;
52
+ output += char;
53
+ continue;
54
+ }
55
+ if (char === "/" && next === "/") {
56
+ while (index < input.length && input[index] !== "\n") {
57
+ index += 1;
58
+ }
59
+ output += "\n";
60
+ continue;
61
+ }
62
+ if (char === "/" && next === "*") {
63
+ index += 2;
64
+ while (index < input.length && !(input[index] === "*" && input[index + 1] === "/")) {
65
+ index += 1;
66
+ }
67
+ index += 1;
68
+ continue;
69
+ }
70
+ output += char;
71
+ }
72
+ return output;
73
+ }
74
+ function parseJsonObject(content) {
75
+ if (!content.trim()) {
76
+ return {};
77
+ }
78
+ const parsed = JSON.parse(stripJsonComments(content));
79
+ return asRecord(parsed);
80
+ }
81
+ function loadJsonFile(path) {
82
+ if (!(0, fs_1.existsSync)(path)) {
83
+ return {};
84
+ }
85
+ return parseJsonObject((0, fs_1.readFileSync)(path, "utf8"));
86
+ }
@@ -0,0 +1,18 @@
1
+ export type HubV2ProjectConfig = {
2
+ name?: string;
3
+ alias?: string;
4
+ id?: string;
5
+ base_url?: string;
6
+ project_key?: string;
7
+ project_name?: string;
8
+ project_token?: string;
9
+ personal_token?: string;
10
+ source?: string;
11
+ };
12
+ export type HubV2Config = HubV2ProjectConfig & {
13
+ default_project?: string;
14
+ projects?: Record<string, HubV2ProjectConfig>;
15
+ };
16
+ export declare function normalizeConfig(rawValue: unknown): HubV2Config;
17
+ export declare function loadConfig(pathValue?: string): HubV2Config;
18
+ export declare function configEnvValue(name: string): string | undefined;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeConfig = normalizeConfig;
4
+ exports.loadConfig = loadConfig;
5
+ exports.configEnvValue = configEnvValue;
6
+ const config_paths_1 = require("./config-paths");
7
+ const env_1 = require("./env");
8
+ const jsonc_1 = require("./jsonc");
9
+ function mergeHubObject(target, value) {
10
+ const source = (0, jsonc_1.asRecord)(value);
11
+ (0, jsonc_1.putIfValue)(target, "base_url", (0, jsonc_1.getString)(source, "base_url", "baseUrl"));
12
+ (0, jsonc_1.putIfValue)(target, "project_key", (0, jsonc_1.getString)(source, "project_key", "projectKey"));
13
+ (0, jsonc_1.putIfValue)(target, "project_name", (0, jsonc_1.getString)(source, "project_name", "projectName"));
14
+ (0, jsonc_1.putIfValue)(target, "project_token", (0, jsonc_1.getString)(source, "project_token", "projectToken", "token"));
15
+ (0, jsonc_1.putIfValue)(target, "personal_token", (0, jsonc_1.getString)(source, "personal_token", "personalToken"));
16
+ (0, jsonc_1.putIfValue)(target, "source", (0, jsonc_1.getString)(source, "source"));
17
+ (0, jsonc_1.putIfValue)(target, "default_project", (0, jsonc_1.getString)(source, "default_project", "defaultProject", "project"));
18
+ }
19
+ function mergeEnvObject(target, value) {
20
+ const env = (0, jsonc_1.asRecord)(value);
21
+ (0, jsonc_1.putIfValue)(target, "base_url", (0, jsonc_1.getString)(env, "HUB_V2_BASE_URL"));
22
+ (0, jsonc_1.putIfValue)(target, "project_key", (0, jsonc_1.getString)(env, "HUB_V2_PROJECT_KEY"));
23
+ (0, jsonc_1.putIfValue)(target, "project_token", (0, jsonc_1.getString)(env, "HUB_V2_PROJECT_TOKEN"));
24
+ (0, jsonc_1.putIfValue)(target, "personal_token", (0, jsonc_1.getString)(env, "HUB_V2_PERSONAL_TOKEN"));
25
+ (0, jsonc_1.putIfValue)(target, "source", (0, jsonc_1.getString)(env, "HUB_V2_SOURCE"));
26
+ (0, jsonc_1.putIfValue)(target, "default_project", (0, jsonc_1.getString)(env, "HUB_V2_PROJECT"));
27
+ }
28
+ function normalizeProject(raw) {
29
+ const config = normalizeConfig(raw);
30
+ const record = (0, jsonc_1.asRecord)(raw);
31
+ (0, jsonc_1.putIfValue)(config, "name", record.name);
32
+ (0, jsonc_1.putIfValue)(config, "alias", record.alias);
33
+ (0, jsonc_1.putIfValue)(config, "id", record.id);
34
+ delete config.projects;
35
+ delete config.default_project;
36
+ return config;
37
+ }
38
+ function normalizeProjects(raw) {
39
+ const value = raw.projects;
40
+ const projects = {};
41
+ if (value && typeof value === "object" && !Array.isArray(value)) {
42
+ for (const [name, projectValue] of Object.entries(value)) {
43
+ const project = normalizeProject(projectValue);
44
+ const projectName = project.name ?? project.alias ?? name.trim();
45
+ if (projectName) {
46
+ projects[projectName] = project;
47
+ }
48
+ }
49
+ }
50
+ if (Array.isArray(value)) {
51
+ for (const projectValue of value) {
52
+ const project = normalizeProject(projectValue);
53
+ const projectName = project.name ?? project.alias ?? project.id;
54
+ if (projectName) {
55
+ projects[projectName] = project;
56
+ }
57
+ }
58
+ }
59
+ return projects;
60
+ }
61
+ function mergeProjects(...maps) {
62
+ const merged = {};
63
+ for (const map of maps) {
64
+ for (const [name, project] of Object.entries(map)) {
65
+ merged[name] = { ...(merged[name] ?? {}), ...project };
66
+ }
67
+ }
68
+ return merged;
69
+ }
70
+ function normalizeConfig(rawValue) {
71
+ const raw = (0, jsonc_1.asRecord)(rawValue);
72
+ const normalized = {};
73
+ mergeHubObject(normalized, raw);
74
+ mergeHubObject(normalized, raw.hubV2);
75
+ mergeEnvObject(normalized, raw.env);
76
+ const projects = mergeProjects(normalizeProjects(raw), normalizeProjects((0, jsonc_1.asRecord)(raw.hubV2)));
77
+ if (Object.keys(projects).length) {
78
+ normalized.projects = projects;
79
+ }
80
+ return normalized;
81
+ }
82
+ function loadConfig(pathValue) {
83
+ for (const path of (0, config_paths_1.configSearchPaths)(pathValue)) {
84
+ const config = normalizeConfig((0, jsonc_1.loadJsonFile)(path));
85
+ if (Object.keys(config).length) {
86
+ return config;
87
+ }
88
+ }
89
+ return {};
90
+ }
91
+ function configEnvValue(name) {
92
+ return (0, env_1.envValue)(name);
93
+ }
@@ -0,0 +1,5 @@
1
+ import type { HubV2Config, HubV2ProjectConfig, HubV2ResolveOptions } from "./resolve-context";
2
+ export declare function selectedProjectConfig(config: HubV2Config, options: HubV2ResolveOptions): HubV2ProjectConfig;
3
+ export declare function configValue(config: HubV2Config, projectConfig: HubV2ProjectConfig, key: keyof HubV2ProjectConfig): string | undefined;
4
+ export declare function listConfiguredProjects(project?: string, pathValue?: string): Record<string, unknown>;
5
+ export declare function getConfiguredProject(options: HubV2ResolveOptions, pathValue?: string): Record<string, unknown>;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.selectedProjectConfig = selectedProjectConfig;
4
+ exports.configValue = configValue;
5
+ exports.listConfiguredProjects = listConfiguredProjects;
6
+ exports.getConfiguredProject = getConfiguredProject;
7
+ const env_1 = require("./env");
8
+ const load_config_1 = require("./load-config");
9
+ function selectedProjectConfig(config, options) {
10
+ const projects = config.projects ?? {};
11
+ const entries = Object.entries(projects);
12
+ if (!entries.length) {
13
+ return {};
14
+ }
15
+ const selected = options.project ?? (0, env_1.envValue)("HUB_V2_PROJECT") ?? config.default_project;
16
+ if (selected) {
17
+ const project = projects[selected];
18
+ if (!project) {
19
+ throw new Error(`project config not found: ${selected}. Available projects: ${entries.map(([name]) => name).sort().join(", ")}`);
20
+ }
21
+ return project;
22
+ }
23
+ if (entries.length === 1) {
24
+ return entries[0][1];
25
+ }
26
+ throw new Error(`multiple projects configured; pass project. Available projects: ${entries.map(([name]) => name).sort().join(", ")}`);
27
+ }
28
+ function configValue(config, projectConfig, key) {
29
+ return projectConfig[key] ?? config[key];
30
+ }
31
+ function projectSummary(name, config, project) {
32
+ return {
33
+ name,
34
+ projectName: project.project_name,
35
+ projectKey: project.project_key,
36
+ baseUrl: project.base_url ?? config.base_url,
37
+ hasProjectToken: Boolean(project.project_token ?? config.project_token),
38
+ hasPersonalToken: Boolean(project.personal_token ?? config.personal_token),
39
+ isDefault: name === config.default_project,
40
+ };
41
+ }
42
+ function listConfiguredProjects(project, pathValue) {
43
+ const config = (0, load_config_1.loadConfig)(pathValue);
44
+ const envProjectKey = (0, env_1.envValue)("HUB_V2_PROJECT_KEY") ?? config.project_key;
45
+ let items;
46
+ if (envProjectKey) {
47
+ items = [
48
+ {
49
+ name: (0, env_1.envValue)("HUB_V2_PROJECT") ?? config.default_project ?? "default",
50
+ projectName: config.project_name,
51
+ projectKey: envProjectKey,
52
+ baseUrl: (0, env_1.envValue)("HUB_V2_BASE_URL") ?? config.base_url,
53
+ hasProjectToken: Boolean((0, env_1.envValue)("HUB_V2_PROJECT_TOKEN") ?? config.project_token),
54
+ hasPersonalToken: Boolean((0, env_1.envValue)("HUB_V2_PERSONAL_TOKEN") ?? config.personal_token),
55
+ isDefault: true,
56
+ },
57
+ ];
58
+ }
59
+ else {
60
+ const projects = config.projects ?? {};
61
+ items = Object.entries(projects).map(([name, item]) => projectSummary(name, config, item));
62
+ }
63
+ const filtered = project
64
+ ? items.filter((item) => item.name === project || item.projectName === project || item.projectKey === project)
65
+ : items;
66
+ return {
67
+ items: filtered,
68
+ total: filtered.length,
69
+ };
70
+ }
71
+ function getConfiguredProject(options, pathValue) {
72
+ const config = (0, load_config_1.loadConfig)(pathValue);
73
+ const selected = options.project ?? options.projectKey ?? (0, env_1.envValue)("HUB_V2_PROJECT") ?? config.default_project;
74
+ if (selected) {
75
+ const projects = listConfiguredProjects(selected, pathValue).items;
76
+ if (projects.length === 1) {
77
+ return projects[0];
78
+ }
79
+ if (!projects.length) {
80
+ throw new Error("Hub V2 project config not found");
81
+ }
82
+ throw new Error("multiple Hub V2 project configs matched");
83
+ }
84
+ const projects = listConfiguredProjects(options.project ?? options.projectKey, pathValue).items;
85
+ if (projects.length === 1) {
86
+ return projects[0];
87
+ }
88
+ if (!projects.length) {
89
+ throw new Error("Hub V2 project config not found");
90
+ }
91
+ throw new Error("multiple Hub V2 project configs matched");
92
+ }
@@ -0,0 +1,13 @@
1
+ export type { HubV2Config, HubV2ProjectConfig } from "./load-config";
2
+ export type HubV2ResolveOptions = {
3
+ project?: string;
4
+ projectKey?: string;
5
+ };
6
+ export type HubV2ResolvedContext = {
7
+ baseUrl: string;
8
+ projectKey: string;
9
+ token: string;
10
+ source: string;
11
+ };
12
+ type TokenKind = "project" | "personal";
13
+ export declare function resolveHubV2Context(options: HubV2ResolveOptions, tokenKind: TokenKind, pathValue?: string): HubV2ResolvedContext;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveHubV2Context = resolveHubV2Context;
4
+ const env_1 = require("./env");
5
+ const load_config_1 = require("./load-config");
6
+ const project_selector_1 = require("./project-selector");
7
+ function resolveHubV2Context(options, tokenKind, pathValue) {
8
+ const config = (0, load_config_1.loadConfig)(pathValue);
9
+ const projectConfig = (0, project_selector_1.selectedProjectConfig)(config, options);
10
+ const baseUrl = ((0, env_1.envValue)("HUB_V2_BASE_URL") ??
11
+ (0, project_selector_1.configValue)(config, projectConfig, "base_url"))?.replace(/\/+$/, "");
12
+ const projectKey = options.projectKey ??
13
+ (0, env_1.envValue)("HUB_V2_PROJECT_KEY") ??
14
+ (0, project_selector_1.configValue)(config, projectConfig, "project_key");
15
+ const projectToken = (0, env_1.envValue)("HUB_V2_PROJECT_TOKEN") ??
16
+ (0, project_selector_1.configValue)(config, projectConfig, "project_token");
17
+ const personalToken = (0, env_1.envValue)("HUB_V2_PERSONAL_TOKEN") ??
18
+ (0, project_selector_1.configValue)(config, projectConfig, "personal_token");
19
+ const source = (0, env_1.envValue)("HUB_V2_SOURCE") ??
20
+ (0, project_selector_1.configValue)(config, projectConfig, "source") ??
21
+ "ngm-mcp";
22
+ if (!baseUrl) {
23
+ throw new Error("HUB_V2_BASE_URL is required");
24
+ }
25
+ if (!projectKey) {
26
+ throw new Error("HUB_V2_PROJECT_KEY is required");
27
+ }
28
+ const token = tokenKind === "project" ? projectToken : personalToken;
29
+ if (!token) {
30
+ throw new Error(tokenKind === "project" ? "HUB_V2_PROJECT_TOKEN is required" : "HUB_V2_PERSONAL_TOKEN is required");
31
+ }
32
+ return { baseUrl, projectKey, token, source };
33
+ }
@@ -0,0 +1,2 @@
1
+ import type { McpToolDefinition } from "../index";
2
+ export declare function hubV2DocsTools(): McpToolDefinition[];