kubeview-mcp 1.2.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.md +81 -181
  3. package/TODO.md +1 -1
  4. package/bin/kubeview-mcp-code-mode.js +60 -0
  5. package/bin/kubeview-mcp.js +4 -1
  6. package/bin/setup.js +4 -3
  7. package/dist/src/agent/bridge/MCPBridge.d.ts +41 -0
  8. package/dist/src/agent/bridge/MCPBridge.d.ts.map +1 -0
  9. package/dist/src/agent/bridge/MCPBridge.js +127 -0
  10. package/dist/src/agent/bridge/MCPBridge.js.map +1 -0
  11. package/dist/src/agent/codegen/CodegenManager.d.ts +26 -0
  12. package/dist/src/agent/codegen/CodegenManager.d.ts.map +1 -0
  13. package/dist/src/agent/codegen/CodegenManager.js +222 -0
  14. package/dist/src/agent/codegen/CodegenManager.js.map +1 -0
  15. package/dist/src/agent/codegen/SchemaToTypeScriptMapper.d.ts +13 -0
  16. package/dist/src/agent/codegen/SchemaToTypeScriptMapper.d.ts.map +1 -0
  17. package/dist/src/agent/codegen/SchemaToTypeScriptMapper.js +54 -0
  18. package/dist/src/agent/codegen/SchemaToTypeScriptMapper.js.map +1 -0
  19. package/dist/src/agent/codegen/ToolDescriptionBuilder.d.ts +66 -0
  20. package/dist/src/agent/codegen/ToolDescriptionBuilder.d.ts.map +1 -0
  21. package/dist/src/agent/codegen/ToolDescriptionBuilder.js +203 -0
  22. package/dist/src/agent/codegen/ToolDescriptionBuilder.js.map +1 -0
  23. package/dist/src/agent/codegen/ToolSchemaIntrospector.d.ts +10 -0
  24. package/dist/src/agent/codegen/ToolSchemaIntrospector.d.ts.map +1 -0
  25. package/dist/src/agent/codegen/ToolSchemaIntrospector.js +72 -0
  26. package/dist/src/agent/codegen/ToolSchemaIntrospector.js.map +1 -0
  27. package/dist/src/agent/codegen/types.d.ts +31 -0
  28. package/dist/src/agent/codegen/types.d.ts.map +1 -0
  29. package/dist/src/agent/codegen/types.js +2 -0
  30. package/dist/src/agent/codegen/types.js.map +1 -0
  31. package/dist/src/agent/config/CodeModeConfig.d.ts +67 -0
  32. package/dist/src/agent/config/CodeModeConfig.d.ts.map +1 -0
  33. package/dist/src/agent/config/CodeModeConfig.js +41 -0
  34. package/dist/src/agent/config/CodeModeConfig.js.map +1 -0
  35. package/dist/src/agent/runtime/code-executor/CodeExecutor.d.ts +25 -0
  36. package/dist/src/agent/runtime/code-executor/CodeExecutor.d.ts.map +1 -0
  37. package/dist/src/agent/runtime/code-executor/CodeExecutor.js +95 -0
  38. package/dist/src/agent/runtime/code-executor/CodeExecutor.js.map +1 -0
  39. package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.d.ts +21 -0
  40. package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.d.ts.map +1 -0
  41. package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.js +89 -0
  42. package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.js.map +1 -0
  43. package/dist/src/agent/runtime/createSandboxManager.d.ts +4 -0
  44. package/dist/src/agent/runtime/createSandboxManager.d.ts.map +1 -0
  45. package/dist/src/agent/runtime/createSandboxManager.js +28 -0
  46. package/dist/src/agent/runtime/createSandboxManager.js.map +1 -0
  47. package/dist/src/agent/runtime/ivm/IVMSandboxManager.d.ts +24 -0
  48. package/dist/src/agent/runtime/ivm/IVMSandboxManager.d.ts.map +1 -0
  49. package/dist/src/agent/runtime/ivm/IVMSandboxManager.js +320 -0
  50. package/dist/src/agent/runtime/ivm/IVMSandboxManager.js.map +1 -0
  51. package/dist/src/agent/runtime/types.d.ts +12 -0
  52. package/dist/src/agent/runtime/types.d.ts.map +1 -0
  53. package/dist/src/agent/runtime/types.js +2 -0
  54. package/dist/src/agent/runtime/types.js.map +1 -0
  55. package/dist/src/agent/runtime/vm/VmSandboxManager.d.ts +23 -0
  56. package/dist/src/agent/runtime/vm/VmSandboxManager.d.ts.map +1 -0
  57. package/dist/src/agent/runtime/vm/VmSandboxManager.js +226 -0
  58. package/dist/src/agent/runtime/vm/VmSandboxManager.js.map +1 -0
  59. package/dist/src/agent/security/PIITokenizer.d.ts +15 -0
  60. package/dist/src/agent/security/PIITokenizer.d.ts.map +1 -0
  61. package/dist/src/agent/security/PIITokenizer.js +54 -0
  62. package/dist/src/agent/security/PIITokenizer.js.map +1 -0
  63. package/dist/src/cli/code-mode.d.ts +3 -0
  64. package/dist/src/cli/code-mode.d.ts.map +1 -0
  65. package/dist/src/cli/code-mode.js +214 -0
  66. package/dist/src/cli/code-mode.js.map +1 -0
  67. package/dist/src/index.d.ts +7 -1
  68. package/dist/src/index.d.ts.map +1 -1
  69. package/dist/src/index.js +160 -20
  70. package/dist/src/index.js.map +1 -1
  71. package/dist/src/plugins/ArgoCDToolsPlugin.d.ts +0 -1
  72. package/dist/src/plugins/ArgoCDToolsPlugin.d.ts.map +1 -1
  73. package/dist/src/plugins/ArgoCDToolsPlugin.js +0 -1
  74. package/dist/src/plugins/ArgoCDToolsPlugin.js.map +1 -1
  75. package/dist/src/plugins/ArgoToolsPlugin.d.ts +0 -1
  76. package/dist/src/plugins/ArgoToolsPlugin.d.ts.map +1 -1
  77. package/dist/src/plugins/ArgoToolsPlugin.js +0 -1
  78. package/dist/src/plugins/ArgoToolsPlugin.js.map +1 -1
  79. package/dist/src/plugins/BaseToolsPlugin.d.ts +0 -1
  80. package/dist/src/plugins/BaseToolsPlugin.d.ts.map +1 -1
  81. package/dist/src/plugins/BaseToolsPlugin.js.map +1 -1
  82. package/dist/src/plugins/HelmToolsPlugin.d.ts +0 -1
  83. package/dist/src/plugins/HelmToolsPlugin.d.ts.map +1 -1
  84. package/dist/src/plugins/HelmToolsPlugin.js +0 -1
  85. package/dist/src/plugins/HelmToolsPlugin.js.map +1 -1
  86. package/dist/src/plugins/KubernetesToolsPlugin.d.ts +0 -1
  87. package/dist/src/plugins/KubernetesToolsPlugin.d.ts.map +1 -1
  88. package/dist/src/plugins/KubernetesToolsPlugin.js +0 -1
  89. package/dist/src/plugins/KubernetesToolsPlugin.js.map +1 -1
  90. package/dist/src/plugins/SamplePlugin.d.ts +0 -1
  91. package/dist/src/plugins/SamplePlugin.d.ts.map +1 -1
  92. package/dist/src/plugins/SamplePlugin.js +1 -2
  93. package/dist/src/plugins/SamplePlugin.js.map +1 -1
  94. package/dist/src/server/MCPServer.d.ts +40 -1
  95. package/dist/src/server/MCPServer.d.ts.map +1 -1
  96. package/dist/src/server/MCPServer.js +245 -33
  97. package/dist/src/server/MCPServer.js.map +1 -1
  98. package/dist/src/tools/RunCodeTool.d.ts +75 -0
  99. package/dist/src/tools/RunCodeTool.d.ts.map +1 -0
  100. package/dist/src/tools/RunCodeTool.js +638 -0
  101. package/dist/src/tools/RunCodeTool.js.map +1 -0
  102. package/dist/src/tools/kubernetes/GetContainerLogsTool.d.ts.map +1 -1
  103. package/dist/src/tools/kubernetes/GetContainerLogsTool.js +11 -1
  104. package/dist/src/tools/kubernetes/GetContainerLogsTool.js.map +1 -1
  105. package/dist/src/tools/kubernetes/KubeListTool.d.ts.map +1 -1
  106. package/dist/src/tools/kubernetes/KubeListTool.js +47 -29
  107. package/dist/src/tools/kubernetes/KubeListTool.js.map +1 -1
  108. package/dist/src/tools/kubernetes/KubeLogTool.d.ts.map +1 -1
  109. package/dist/src/tools/kubernetes/KubeLogTool.js +142 -26
  110. package/dist/src/tools/kubernetes/KubeLogTool.js.map +1 -1
  111. package/dist/src/utils/CodeModeConfig.d.ts +65 -0
  112. package/dist/src/utils/CodeModeConfig.d.ts.map +1 -0
  113. package/dist/src/utils/CodeModeConfig.js +41 -0
  114. package/dist/src/utils/CodeModeConfig.js.map +1 -0
  115. package/dist/src/utils/toolNamespaces.d.ts +9 -0
  116. package/dist/src/utils/toolNamespaces.d.ts.map +1 -0
  117. package/dist/src/utils/toolNamespaces.js +29 -0
  118. package/dist/src/utils/toolNamespaces.js.map +1 -0
  119. package/dist/src/version.d.ts +2 -0
  120. package/dist/src/version.d.ts.map +1 -0
  121. package/dist/src/version.js +3 -0
  122. package/dist/src/version.js.map +1 -0
  123. package/dist/tests/agent/PIITokenizer.test.d.ts +2 -0
  124. package/dist/tests/agent/PIITokenizer.test.d.ts.map +1 -0
  125. package/dist/tests/agent/PIITokenizer.test.js +19 -0
  126. package/dist/tests/agent/PIITokenizer.test.js.map +1 -0
  127. package/dist/tests/agent/SchemaToTypeScriptMapper.test.d.ts +2 -0
  128. package/dist/tests/agent/SchemaToTypeScriptMapper.test.d.ts.map +1 -0
  129. package/dist/tests/agent/SchemaToTypeScriptMapper.test.js +27 -0
  130. package/dist/tests/agent/SchemaToTypeScriptMapper.test.js.map +1 -0
  131. package/dist/tests/agent/ToolDescriptionBuilder.test.d.ts +2 -0
  132. package/dist/tests/agent/ToolDescriptionBuilder.test.d.ts.map +1 -0
  133. package/dist/tests/agent/ToolDescriptionBuilder.test.js +142 -0
  134. package/dist/tests/agent/ToolDescriptionBuilder.test.js.map +1 -0
  135. package/dist/tests/index.test.js +2 -2
  136. package/dist/tests/index.test.js.map +1 -1
  137. package/dist/tests/kubernetes/KubernetesClient.test.js +10 -1
  138. package/dist/tests/kubernetes/KubernetesClient.test.js.map +1 -1
  139. package/dist/tests/server/MCPServer.integration.test.js +2 -2
  140. package/dist/tests/server/MCPServer.integration.test.js.map +1 -1
  141. package/dist/tests/server/MCPServer.test.js +1 -6
  142. package/dist/tests/server/MCPServer.test.js.map +1 -1
  143. package/dist/tests/tools/RunCodeTool.test.d.ts +2 -0
  144. package/dist/tests/tools/RunCodeTool.test.d.ts.map +1 -0
  145. package/dist/tests/tools/RunCodeTool.test.js +211 -0
  146. package/dist/tests/tools/RunCodeTool.test.js.map +1 -0
  147. package/dist/tests/tools/kubernetes/KubeListTool.test.d.ts +2 -0
  148. package/dist/tests/tools/kubernetes/KubeListTool.test.d.ts.map +1 -0
  149. package/dist/tests/tools/kubernetes/KubeListTool.test.js +45 -0
  150. package/dist/tests/tools/kubernetes/KubeListTool.test.js.map +1 -0
  151. package/package.json +15 -12
  152. package/.prettierrc.json +0 -11
  153. package/dist/src/tools/helm/HelmReleaseTool.d.ts +0 -10
  154. package/dist/src/tools/helm/HelmReleaseTool.d.ts.map +0 -1
  155. package/dist/src/tools/helm/HelmReleaseTool.js +0 -44
  156. package/dist/src/tools/helm/HelmReleaseTool.js.map +0 -1
  157. package/src/cli/cli.ts +0 -25
  158. package/src/cli/run-command.js +0 -391
  159. package/src/index.ts +0 -47
  160. package/src/kubernetes/BaseResourceOperations.ts +0 -286
  161. package/src/kubernetes/CircuitBreaker.ts +0 -485
  162. package/src/kubernetes/ConnectionManager.ts +0 -114
  163. package/src/kubernetes/ConnectionPool.ts +0 -551
  164. package/src/kubernetes/ErrorHandler.ts +0 -436
  165. package/src/kubernetes/ErrorHandling.ts +0 -401
  166. package/src/kubernetes/KubernetesClient.ts +0 -653
  167. package/src/kubernetes/README.md +0 -349
  168. package/src/kubernetes/ResourceOperations.ts +0 -116
  169. package/src/kubernetes/RetryStrategy.ts +0 -372
  170. package/src/kubernetes/RetryableOperation.ts +0 -313
  171. package/src/kubernetes/docs/ResourceOperations.md +0 -606
  172. package/src/kubernetes/index.ts +0 -116
  173. package/src/kubernetes/resources/ConfigMapOperations.ts +0 -368
  174. package/src/kubernetes/resources/CustomResourceOperations.ts +0 -392
  175. package/src/kubernetes/resources/DeploymentOperations.ts +0 -294
  176. package/src/kubernetes/resources/IngressOperations.ts +0 -277
  177. package/src/kubernetes/resources/MetricOperations.ts +0 -1734
  178. package/src/kubernetes/resources/NamespaceOperations.ts +0 -129
  179. package/src/kubernetes/resources/PersistentVolumeClaimOperations.ts +0 -516
  180. package/src/kubernetes/resources/PersistentVolumeOperations.ts +0 -438
  181. package/src/kubernetes/resources/PodOperations.ts +0 -417
  182. package/src/kubernetes/resources/SecretOperations.ts +0 -314
  183. package/src/kubernetes/resources/ServiceOperations.ts +0 -283
  184. package/src/kubernetes/utils/ResourceUtils.ts +0 -553
  185. package/src/plugins/ArgoCDToolsPlugin.ts +0 -93
  186. package/src/plugins/ArgoToolsPlugin.ts +0 -98
  187. package/src/plugins/BaseToolsPlugin.ts +0 -149
  188. package/src/plugins/HelmToolsPlugin.ts +0 -97
  189. package/src/plugins/KubernetesToolsPlugin.ts +0 -229
  190. package/src/plugins/SamplePlugin.ts +0 -60
  191. package/src/plugins/index.ts +0 -4
  192. package/src/server/MCPServer.ts +0 -536
  193. package/src/tools/argo/ArgoCronListTool.ts +0 -78
  194. package/src/tools/argo/ArgoGetTool.ts +0 -91
  195. package/src/tools/argo/ArgoListTool.ts +0 -144
  196. package/src/tools/argo/ArgoLogsTool.ts +0 -131
  197. package/src/tools/argo/BaseTool.ts +0 -69
  198. package/src/tools/argo/index.ts +0 -5
  199. package/src/tools/argocd/ArgoCDAppGetTool.ts +0 -109
  200. package/src/tools/argocd/ArgoCDAppHistoryTool.ts +0 -91
  201. package/src/tools/argocd/ArgoCDAppListTool.ts +0 -144
  202. package/src/tools/argocd/ArgoCDAppLogsTool.ts +0 -162
  203. package/src/tools/argocd/ArgoCDAppResourcesTool.ts +0 -139
  204. package/src/tools/argocd/ArgoCDAppTool.ts +0 -171
  205. package/src/tools/argocd/BaseTool.ts +0 -83
  206. package/src/tools/argocd/index.ts +0 -3
  207. package/src/tools/helm/BaseTool.ts +0 -60
  208. package/src/tools/helm/HelmGetHooksTool.ts +0 -44
  209. package/src/tools/helm/HelmGetManifestTool.ts +0 -44
  210. package/src/tools/helm/HelmGetNotesTool.ts +0 -44
  211. package/src/tools/helm/HelmGetResourcesTool.ts +0 -140
  212. package/src/tools/helm/HelmGetTool.ts +0 -140
  213. package/src/tools/helm/HelmGetValuesTool.ts +0 -70
  214. package/src/tools/helm/HelmHistoryTool.ts +0 -56
  215. package/src/tools/helm/HelmListTool.ts +0 -107
  216. package/src/tools/helm/HelmListWithResourcesTool.ts +0 -194
  217. package/src/tools/helm/HelmStatusTool.ts +0 -62
  218. package/src/tools/helm/index.ts +0 -4
  219. package/src/tools/kubernetes/BaseTool.ts +0 -76
  220. package/src/tools/kubernetes/ExecTool.ts +0 -308
  221. package/src/tools/kubernetes/GetConfigMapTool.ts +0 -33
  222. package/src/tools/kubernetes/GetContainerLogsTool.ts +0 -140
  223. package/src/tools/kubernetes/GetCronJobsTool.ts +0 -47
  224. package/src/tools/kubernetes/GetDaemonSetsTool.ts +0 -55
  225. package/src/tools/kubernetes/GetDeploymentsTool.ts +0 -33
  226. package/src/tools/kubernetes/GetEndpointSlicesTool.ts +0 -57
  227. package/src/tools/kubernetes/GetEndpointsTool.ts +0 -53
  228. package/src/tools/kubernetes/GetEventsTool.ts +0 -133
  229. package/src/tools/kubernetes/GetHPATool.ts +0 -48
  230. package/src/tools/kubernetes/GetIngressTool.ts +0 -39
  231. package/src/tools/kubernetes/GetJobsTool.ts +0 -54
  232. package/src/tools/kubernetes/GetLimitRangesTool.ts +0 -40
  233. package/src/tools/kubernetes/GetMetricsTool.ts +0 -61
  234. package/src/tools/kubernetes/GetNamespacesTool.ts +0 -36
  235. package/src/tools/kubernetes/GetNodesTool.ts +0 -55
  236. package/src/tools/kubernetes/GetPDBTool.ts +0 -48
  237. package/src/tools/kubernetes/GetPersistentVolumeClaimsTool.ts +0 -113
  238. package/src/tools/kubernetes/GetPersistentVolumesTool.ts +0 -107
  239. package/src/tools/kubernetes/GetPodMetricsTool.ts +0 -113
  240. package/src/tools/kubernetes/GetPodsTool.ts +0 -39
  241. package/src/tools/kubernetes/GetReplicaSetsTool.ts +0 -51
  242. package/src/tools/kubernetes/GetResourceQuotaTool.ts +0 -55
  243. package/src/tools/kubernetes/GetResourceTool.ts +0 -1296
  244. package/src/tools/kubernetes/GetSecretsTool.ts +0 -55
  245. package/src/tools/kubernetes/GetServicesTool.ts +0 -39
  246. package/src/tools/kubernetes/GetStatefulSetsTool.ts +0 -55
  247. package/src/tools/kubernetes/KubeListTool.ts +0 -1684
  248. package/src/tools/kubernetes/KubeLogTool.ts +0 -935
  249. package/src/tools/kubernetes/KubeMetricsTool.ts +0 -220
  250. package/src/tools/kubernetes/KubeNetTool.ts +0 -481
  251. package/src/tools/kubernetes/PortForwardTool.ts +0 -307
  252. package/src/tools/kubernetes/index.ts +0 -10
  253. package/src/utils/CliUtils.ts +0 -218
  254. package/src/utils/SensitiveData.ts +0 -148
  255. package/tsconfig.json +0 -36
package/CHANGELOG.md CHANGED
@@ -5,6 +5,56 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [1.4.0] - 2025-11-29
11
+
12
+ ### Added
13
+ - **RunCode Tool Exposure**: Exposed `run_code` tool by default in standard mode alongside other tools.
14
+ - **Code-Mode Prompt**: Added `code-mode` prompt for injecting the full TypeScript API documentation, tool overview, and examples into the context.
15
+
16
+ ### Changed
17
+ - **Documentation**: Improved README.md to be more professional, valid, and concise.
18
+ - **Name Change**: Changed name from `kubeview-mcp` to `kubeview` to align with the new MCP server name.
19
+ - **Dependencies**: Updated deprecated dependencies.
20
+
21
+ ### Fixed
22
+ - **Filter Logic**: `kube_list` now honors namespace/selector filters even when `resourceType` is omitted.
23
+ - **Runtime Errors**: Fixed `ERR_MODULE_NOT_FOUND` for `typescript` package.
24
+ - **Build Issues**: Resolved TypeScript compilation errors in `src/index.ts`.
25
+ - **Logging**: Fixed "Required parameter name was null or undefined" error in `kube_log` and `kube_logs` tools.
26
+
27
+ ## [1.3.0] - 2025-11-27
28
+
29
+ ### Added
30
+ - **Code-Mode Execution**: Added sandboxed TypeScript code execution runtime following Anthropic's code execution with MCP approach
31
+ - **RunCodeTool**: Implemented `run_code` tool for executing TypeScript code in a sandboxed Node.js VM environment
32
+ - **Code-Mode CLI**: Added `kubeview-mcp-code-mode` binary and `npm run code-mode` script for standalone code execution
33
+ - **TypeScript Transpilation**: Integrated TypeScript compiler for runtime transpilation of agent code (ES2022 target)
34
+ - **Global Type Definitions**: Added `/sys/global.d.ts` resource providing TypeScript type definitions for all available tools
35
+ - **Tool Executor**: Implemented tool executor allowing sandboxed code to call MCP tools internally
36
+ - **Helper Functions**: Added namespaced `tools.*` helpers for discovery (`tools.list()`, `tools.search()`, `tools.help()`, `tools.call()`) and execution
37
+ - **Code-Mode Configuration**: Added `CodeModeConfig` with configurable sandbox limits (memory, timeout) and workspace settings
38
+ - **Mode Support**: Added `MCP_MODE` environment variable with three modes:
39
+ - `code`: exposes only `run_code` tool
40
+ - `tools`: exposes only Kubernetes/Helm/Argo tools (no `run_code`)
41
+ - `all`: exposes both tools and `run_code` (default)
42
+ - Replaced `NODE_MODE=code` with `MCP_MODE=code|tools|all`
43
+
44
+ ### Changed
45
+ - **Plugin Architecture**: Removed version property from various tools plugins and MCPServer for simplified plugin management
46
+ - **Dependencies**: Added TypeScript as a runtime dependency (previously dev-only) for code-mode transpilation
47
+ - **Tool Manifest**: Enhanced tool manifest system to support dynamic tool generation for agent code execution
48
+
49
+ ### Fixed
50
+ - **Type Definitions**: Fixed TypeScript typing for generated global DTS resources and resource registration
51
+
52
+ ## [1.2.0] - 2025-08-19
53
+
54
+ ### Changed
55
+ - **Changed variable naming**
56
+ - **Diabled logging by default**
57
+
8
58
  ## [1.1.0] - 2025-08-09
9
59
 
10
60
  ### Added
@@ -80,4 +130,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
80
130
  - Integration guides for Cursor IDE
81
131
  - API documentation for developers
82
132
 
83
- [1.0.0]: https://github.com/mikhae1/kubeview-mcp/releases/tag/v1.0.0
133
+ [1.0.0]: https://github.com/mikhae1/kubeview-mcp/releases/tag/v1.0.0
package/README.md CHANGED
@@ -4,248 +4,148 @@
4
4
  [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org/)
5
5
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.8+-blue)](https://www.typescriptlang.org/)
6
6
 
7
- KubeView MCP is a read-only Model Context Protocol (MCP) server that exposes AI-friendly tools for safe Kubernetes, Helm, Argo Workflows, and Argo CD introspection. It pairs with Cursor IDE, Claude Code/Desktop, and other MCP clients to let you inspect, diagnose, and debug clusters via natural language and without any change operations.
7
+ **KubeView** is a read-only Model Context Protocol (MCP) server that enables AI agents (like Cursor, Claude Desktop) to inspect, diagnose, and debug Kubernetes clusters safely. It provides a comprehensive set of tools for Kubernetes, Helm, Argo Workflows, and Argo CD.
8
8
 
9
9
  ---
10
10
 
11
11
  ## ✨ Features
12
12
 
13
- - **Kubernetes tools (read-only)**: list, get/describe, metrics, single-pod logs, multi-pod streaming logs with event merge, exec (read-only), port-forward, and in-cluster network diagnostics
14
- - **Cluster overview**: one-shot, LLM-optimized diagnostics across nodes, workloads, storage, events, and security posture
15
- - **Helm integration**: list releases; fetch values, manifest, notes, hooks, history, status, and parsed resources
16
- - **Argo Workflows**: list/get workflows and fetch workflow logs
17
- - **Argo CD**: list/get app details, resources, history, logs, and status via a single multi-operation tool
18
- - **Sensitive data masking**: global redaction for secrets/tokens in ConfigMaps, Secrets, and Helm values
19
- - **Zero write access**: designed to be safe in production from day one
13
+ - **🛡️ Read-Only & Safe**: Designed for production safety with zero write access and sensitive data masking.
14
+ - **☸️ Kubernetes Integration**: List/get resources, fetch metrics, stream logs, execute commands, and diagnose network issues.
15
+ - **📦 Helm Support**: Inspect releases, values, manifests, and history.
16
+ - **🐙 Argo Ecosystem**: Manage Argo Workflows and Argo CD applications.
17
+ - **🧠 Code Mode**: Sandboxed TypeScript environment for complex reasoning and multi-step workflows.
20
18
 
21
19
  ---
22
20
 
23
21
  ## 🚀 Quick Start
24
22
 
25
- ### Zero-install via npx
23
+ ### Prerequisites
24
+
25
+ - Node.js ≥ 18
26
+ - Access to a Kubernetes cluster
27
+ - Optional CLIs on current $PATH if you want to use those plugins: `helm`, `argo`, `argocd`
28
+
29
+ ### Installation
30
+
31
+ Run directly with `npx`:
26
32
 
27
33
  ```bash
28
- npx -y https://github.com/mikhae1/kubeview-mcp
34
+ npx -y kubeview-mcp
29
35
  ```
30
36
 
31
- Add to your MCP client config (for Cursor, `~/.cursor/mcp.json`):
37
+ ### Configuration for MCP Clients
38
+
39
+ Add to your `mcpServers` configuration (e.g., in Cursor or Claude Desktop):
32
40
 
33
41
  ```json
34
42
  {
35
43
  "mcpServers": {
36
- "kubeview-mcp": {
44
+ "kubeview": {
37
45
  "command": "npx",
38
- "args": ["-y", "https://github.com/mikhae1/kubeview-mcp"],
39
- "env": {
40
- "KUBECONFIG": "$HOME/.kube/config"
41
- }
46
+ "args": ["-y", "kubeview-mcp"]
42
47
  }
43
48
  }
44
49
  }
45
50
  ```
46
51
 
47
- ### Prerequisites
48
-
49
- - Node.js ≥ 18
50
- - Access to a Kubernetes cluster (kubeconfig)
51
- - Optional CLIs on PATH when using those plugins: `helm`, `argo`, `argocd`
52
-
53
- ### Local install
54
-
55
- ```bash
56
- git clone https://github.com/mikhae1/kubeview-mcp.git
57
- cd kubeview-mcp
58
- npm install
59
-
60
- # Generate local MCP config entries for Cursor and/or Claude Desktop
61
- npm run setup
62
- ```
63
-
64
- ### Run
52
+ ### Environment Variables
65
53
 
66
- ```bash
67
- # Build and start
68
- npm run build
69
- npm start
54
+ Configure the server using environment variables:
70
55
 
71
- # Or use the bundled binary wrapper
72
- kubeview-mcp serve
73
- ```
56
+ | Variable | Description | Default |
57
+ |----------|-------------|---------|
58
+ | `KUBECONFIG` | Path to kubeconfig file | `~/.kube/config` |
59
+ | `MCP_MODE` | Server mode: `all`, `code`, or `tools` | `all` |
60
+ | `MCP_LOG_LEVEL` | Log level (`error`, `warn`, `info`, `debug`) | `info` |
61
+ | `MCP_HIDE_SENSITIVE` | Enable global sensitive data masking | `false` |
74
62
 
75
63
  ---
76
64
 
77
- ## 📟 Tool Index (CLI)
78
-
79
- Invoke tools with the helper:
80
-
81
- ```bash
82
- npm run command -- <tool_name> [--param=value ...]
83
- ```
65
+ ## 🛠️ Tools Overview
84
66
 
85
67
  ### Kubernetes
86
-
87
- - **kube_list**: List resources or, when no `resourceType` is provided, return a cluster diagnostics overview
88
- - Params: `resourceType`, `namespace`, `labelSelector`, `fieldSelector`
89
- - Supported `resourceType` for listing: `pod`, `service`, `deployment`, `node`, `namespace`, `persistentvolume`, `persistentvolumeclaim`, `secret`, `configmap`, `role`, `clusterrole`, `rolebinding`, `clusterrolebinding`
90
- - **kube_get**: Describe a single resource or list a type using plural, kind, shortname, or fully-qualified `group/version/resource`
91
- - Params: `resourceType` (required), `name`, `namespace`, `includeEvents`, `includeDiagnostics`, `eventsLimit`, `restartThreshold`, `skipSanitize` (for ConfigMaps)
92
- - **kube_metrics**: Node and pod CPU/memory metrics, optional Prometheus enrichment and diagnostics
93
- - Params: `scope` (`all|nodes|pods`), `namespace`, `podName`, `includeSummary`, `diagnostics`, `prometheusQueries[]`, `fetchPodSpecs`, thresholds (`topN`, `cpuSaturationThreshold`, `memorySaturationThreshold`, `podRestartThreshold`, `podLimitPressureThreshold`)
94
- - **kube_logs**: Pod/container logs (like `kubectl logs`)
95
- - Params: `podName` (required), `namespace`, `container`, `tailLines`, `since`, `previous`, `timestamps`
96
- - **kube_log**: Multi-pod & multi-container log tail with dynamic discovery and merged Events
97
- - Selectors: `namespace`, `labelSelector`, `ownerKind` (`Deployment|DaemonSet|Job`), `ownerName`
98
- - Filters: `podRegex`, `containerRegex`, `messageRegex`, `excludeRegex`, `jsonPaths` (e.g., `[{"path":"level","equals":"error"}]`)
99
- - Time/tail: `tailLines`, `since` (e.g., `15m`), `sinceTime` (RFC3339), `timestamps`, `previous`
100
- - Session bounds: `durationSeconds` (default 30), `maxLines`
101
- - Events: `includeEvents` (default true), `eventType` (`Normal|Warning|All`)
102
- - Output: `structure` (`object|text`). In object mode each line has `type: 'log'|'event'`. In text mode events are prefixed with `[event]`.
103
- - **kube_exec**: Execute a command in a container via Kubernetes API only; returns stdout/stderr
104
- - Params: `podName` (required), `namespace`, `container`, `args[]` | `argv` | `command`, `stdin`, `tty`, `timeoutSeconds`, `shell`
105
- - **kube_port**: Temporary port-forward to a pod or service (auto-terminates)
106
- - Params: `namespace`, `podName` | `serviceName`, `remotePort` (required), `localPort`, `address`, `timeoutSeconds`, `readinessTimeoutSeconds`
107
- - **kube_net**: In-pod network diagnostics (DNS resolution, internet egress, pod/service connectivity)
108
- - Params: `sourcePod` (required), `namespace`, `container`, `targetPod`, `targetPodNamespace`, `targetService`, `targetServiceNamespace`, `targetPort`, `externalHost`, `externalPort`, `dnsNames[]`, toggles: `runDnsTest`, `runInternetTest`, `runPodConnectivityTest`, `runServiceConnectivityTest`, `timeoutSeconds`
68
+ - **`kube_list`**: List resources or get cluster diagnostics.
69
+ - **`kube_get`**: Describe specific resources (supports all K8s types).
70
+ - **`kube_metrics`**: Fetch CPU/memory metrics for nodes and pods.
71
+ - **`kube_logs`**: Fetch or stream container logs.
72
+ - **`kube_exec`**: Execute commands in containers (read-only recommended).
73
+ - **`kube_port`**: Port-forward to pods/services.
74
+ - **`kube_net`**: Run in-cluster network diagnostics.
109
75
 
110
76
  ### Helm
77
+ - **`helm_list`**: List Helm releases.
78
+ - **`helm_get`**: Fetch release values, manifests, and history.
111
79
 
112
- - **helm_list**: List Helm releases
113
- - Params: `namespace`, `allNamespaces`, `outputFormat`, `selector`, `maxReleases`, `deployed`, `failed`, `pending`, `superseded`, `uninstalled`, `uninstalling`
114
- - **helm_get**: Get release data
115
- - Params: `what` (`values|manifest|notes|hooks|resources|status|history`), `releaseName` (required), `namespace`, `revision`, `outputFormat`, `allValues`, `resourceType`, `showResources`
80
+ ### Argo
81
+ - **`argo_list` / `argo_get`**: Manage Argo Workflows.
82
+ - **`argocd_app`**: Inspect Argo CD applications and resources.
116
83
 
117
- ### Argo Workflows
84
+ ### Utilities
85
+ - **`run_code`**: Execute sandboxed TypeScript code for complex tasks.
118
86
 
119
- - **argo_list**: List workflows with rich filters
120
- - Params: `namespace`, `allNamespaces`, `outputFormat`, `selector`, status flags (`running|succeeded|failed|pending|completed|status`), `since`, `chunked`, `maxWorkflows`
121
- - **argo_get**: Get workflow details
122
- - Params: `workflowName` (required), `namespace`, `outputFormat`, `showParameters`, `showArtifacts`, `showEvents`, `nodeFieldSelector`
123
- - **argo_logs**: Get workflow logs
124
- - Params: `workflowName` (required), `namespace`, `container`, `follow`, `previous`, `since`, `sinceTime`, `tail`, `timestamps`, `grep`, `noColor`
87
+ > **Note**: For detailed parameter usage, the AI agent can query the tool definitions directly.
125
88
 
126
- ### Argo CD
89
+ ---
127
90
 
128
- - **argocd_app**: Multi-operation tool for Argo CD apps
129
- - Params: `operation` (`list|get|resources|logs|history|status`) plus operation-specific flags (`appName`, `outputFormat`, `selector`, `project`, `cluster`, `namespace`, `repo`, `health`, `sync`, `server`, `grpcWeb`, `plaintext`, `insecure`, `refresh`, `hardRefresh`, `group`, `kind`, `name`, `container`, `follow`, `previous`, `since`, `sinceTime`, `tail`, `timestamps`)
91
+ ## 🧠 Code Mode
130
92
 
131
- ---
93
+ Inspired by [Code execution with MCP](https://www.anthropic.com/engineering/code-execution-with-mcp), KubeView ships with a code-mode runtime that allows agents to explore the API, search tools, and execute complex workflows in a sandboxed environment.
132
94
 
133
- ## ⚙️ Configuration
95
+ ### What it provides
134
96
 
135
- Provide env vars via your MCP client config or shell.
97
+ - **MCP Bridge Layer**: Seamlessly connects to all registered MCP server tools.
98
+ - **Dynamic TypeScript Definitions**: Automatically converts tool schemas into a strongly-typed `global.d.ts` resource, enabling agents to use valid TypeScript patterns and enjoy type safety without hallucinating parameters.
99
+ - **Tool Search Utilities**: Runtime helpers like `tools.search()` and `tools.list()` allow agents to progressively discover capabilities without needing to load the entire schema context upfront.
100
+ - **Sandboxed Execution**: A locked-down Node.js environment (via `vm`) with controlled access to the `console` and the `tools` global object, ensuring safe execution of agent-generated code.
136
101
 
137
- - **KUBECONFIG**: Path to kubeconfig (default: `$HOME/.kube/config`)
138
- - **MCP_LOG_LEVEL**: `error|warn|info|debug`
139
- - **MCP_LOG_ENABLE**: `true|1` to enable server file logging (default: disabled)
140
- - **MCP_LOG_FILE**: Path to server log file (default when enabled: `kubeview-mcp.log`)
141
- - **MCP_TIMEOUT**: Global per-tool timeout in ms (applies to all tools)
142
- - CLI timeouts: **MCP_HELM_TIMEOUT**, **MCP_ARGO_TIMEOUT**, **MCP_ARGOCD_TIMEOUT** (ms)
143
- - CLI executable overrides: **MCP_HELM_PATH**, **MCP_ARGO_PATH**, **MCP_ARGOCD_PATH**
144
- - Plugin toggles: **MCP_DISABLE_KUBERNETES_PLUGIN**, **MCP_DISABLE_HELM_PLUGIN**, **MCP_DISABLE_ARGO_PLUGIN**, **MCP_DISABLE_ARGOCD_PLUGIN** (`true|1` to disable)
145
- - Kubernetes options: **MCP_KUBE_CONTEXT**, **MCP_K8S_SKIP_TLS_VERIFY** (`true|1`)
102
+ ### Usage
146
103
 
147
- Example (Cursor `mcp.json`):
104
+ For complex tasks requiring logic, loops, or data processing, use **Code Mode**:
148
105
 
149
106
  ```json
150
- {
151
- "mcpServers": {
152
- "kubeview-mcp": {
153
- "command": "npx",
154
- "args": ["-y", "https://github.com/mikhae1/kubeview-mcp"],
155
- "env": {
156
- "KUBECONFIG": "$HOME/.kube/config",
157
- "MCP_LOG_LEVEL": "info",
158
- "MCP_HELM_TIMEOUT": "45000",
159
- "MCP_DISABLE_ARGO_PLUGIN": "1"
160
- }
161
- }
162
- }
163
- }
107
+ "env": { "MCP_MODE": "code" }
164
108
  ```
165
109
 
166
- ---
167
-
168
- ## 🔒 Sensitive Data Masking
169
-
170
- Global masking prevents accidental disclosure of secrets (enabled when any of the flags below are set):
110
+ ### 💡 Pro Tip: Code Mode Prompt
171
111
 
172
- - Enable: `MCP_HIDE_SENSITIVE` or `MCP_HIDE_SENSITIVE_DATA` or `MCP_MASK_SENSITIVE_DATA` `true|1|yes|on`
173
- - Mask text override: `MCP_SENSITIVE_MASK` (default: `*** FILTERED ***`)
112
+ The server includes a built-in prompt named **`code-mode`** that injects the full TypeScript API documentation, tool overview, and examples into the context.
174
113
 
175
- Effects:
176
-
177
- - ConfigMaps: values redacted by key/value heuristics; forcing `skipSanitize=true` on `kube_get` will still be overridden by global masking
178
- - Secrets: list/describe returns only key names; values are masked
179
- - Helm: `helm_get` with `what=values` applies masking on returned text
114
+ **In Cursor IDE**:
115
+ Simply type `/kubeview/code-mode` in the prompt (or select it from the `/` prompt menu). This gives the AI the exact context it needs to write correct `run_code` scripts immediately.
180
116
 
181
117
  ---
182
118
 
183
- ## 💡 Examples
184
-
185
- ```bash
186
- # Cluster diagnostics overview (no resourceType)
187
- npm run command -- kube_list
188
-
189
- # Pods in a namespace
190
- npm run command -- kube_list --resourceType=pod --namespace=default
191
-
192
- # Describe a deployment with events and diagnostics
193
- npm run command -- kube_get --resourceType=deployment --name=web --namespace=prod
194
-
195
- # Metrics summary with diagnostics
196
- npm run command -- kube_metrics --includeSummary=true --diagnostics=true
119
+ ## 💻 Local Development
197
120
 
198
- # Logs from a pod (last 200 lines)
199
- npm run command -- kube_logs --podName=nginx-123 --namespace=default --tailLines=200
121
+ 1. **Clone & Install**:
122
+ ```bash
123
+ git clone https://github.com/mikhae1/kubeview-mcp.git
124
+ cd kubeview-mcp
125
+ npm install
126
+ ```
200
127
 
201
- # Stream logs across pods by owner with events (10 minutes back)
202
- npm run command -- kube_log --namespace=prod --ownerKind=Deployment --ownerName=api --since=10m --includeEvents=true --durationSeconds=20
128
+ 2. **Build & Run**:
129
+ ```bash
130
+ npm run build
131
+ npm start
132
+ ```
203
133
 
204
- # Filter by labels and container name, text output
205
- npm run command -- kube_log --namespace=default --labelSelector='app=db,tier=api' --containerRegex='^(main|sidecar)$' --structure=text --durationSeconds=15
134
+ 3. **Test**:
135
+ ```bash
136
+ npm test
137
+ ```
206
138
 
207
- # Only errors from JSON logs
208
- npm run command -- kube_log --namespace=prod --labelSelector='app=my-api' --jsonPaths='[{"path":"level","equals":"error"}]' --messageRegex='timeout|exception' --since=30m --durationSeconds=20
139
+ ### CLI Usage
209
140
 
210
- # Only events (text mode)
211
- npm run command -- kube_log --namespace=default --includeEvents=true --structure=text --messageRegex='^\\[event\\]' --durationSeconds=10
141
+ You can test tools directly via the CLI:
212
142
 
213
- # Port-forward service 80 -> local 8080 for 90s
214
- npm run command -- kube_port --serviceName=my-svc --namespace=default --remotePort=80 --localPort=8080 --timeoutSeconds=90
215
-
216
- # Network diagnostics from a pod
217
- npm run command -- kube_net --sourcePod=api-0 --namespace=prod --targetService=db --runServiceConnectivityTest=true
218
-
219
- # Helm release values (masked)
220
- npm run command -- helm_get --what=values --releaseName=my-release --namespace=default --allValues=true
221
-
222
- # Argo CD app resources
223
- npm run command -- argocd_app --operation=resources --appName=my-app --outputFormat=json
143
+ ```bash
144
+ npm run command -- kube_list --namespace=default
224
145
  ```
225
146
 
226
147
  ---
227
148
 
228
- ## 🤝 Contributing
229
-
230
- 1. Fork the repo
231
- 2. Create a feature branch: `git checkout -b feat/my-awesome-feature`
232
- 3. Commit: `git commit -m "feat: add my awesome feature"`
233
- 4. Push: `git push origin feat/my-awesome-feature`
234
- 5. Open a Pull Request
235
-
236
- Tip: run `npm run lint` and `npm run test` locally before submitting.
237
-
238
- ---
239
-
240
149
  ## 📄 License
241
150
 
242
- MIT see `LICENSE`.
243
-
244
- ---
245
-
246
- ## 🙏 Acknowledgments
247
-
248
- - Model Context Protocol SDK
249
- - Kubernetes JavaScript Client
250
- - Winston
251
- - TypeScript
151
+ MIT © [kubeview-mcp team](https://github.com/mikhae1/kubeview-mcp)
package/TODO.md CHANGED
@@ -1,2 +1,2 @@
1
1
  - kube_logs (multiple log streams + events, selectors support)
2
- -
2
+ - add support for k8s context selector
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { fileURLToPath } from 'url';
4
+ import path from 'path';
5
+ import fs from 'fs';
6
+ import { spawn, execSync } from 'child_process';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+ const projectRoot = path.resolve(__dirname, '..');
11
+
12
+ function ensureBuild() {
13
+ const distDir = path.join(projectRoot, 'dist');
14
+ const cliPath = path.join(distDir, 'src', 'cli', 'code-mode.js');
15
+ if (fs.existsSync(cliPath)) {
16
+ return cliPath;
17
+ }
18
+
19
+ console.error('[kubeview-mcp] Building project for code-mode CLI...');
20
+ try {
21
+ execSync('npm run build', { cwd: projectRoot, stdio: 'inherit' });
22
+ } catch (error) {
23
+ console.error('Failed to build project for code-mode CLI.');
24
+ console.error(error);
25
+ process.exit(1);
26
+ }
27
+
28
+ if (!fs.existsSync(cliPath)) {
29
+ console.error('code-mode CLI not found after build. Expected at:', cliPath);
30
+ process.exit(1);
31
+ }
32
+
33
+ return cliPath;
34
+ }
35
+
36
+ function runCodeMode() {
37
+ const cliPath = ensureBuild();
38
+ // Pass all arguments to the CLI
39
+ const args = process.argv.slice(2);
40
+
41
+ const child = spawn('node', [cliPath, ...args], {
42
+ cwd: projectRoot,
43
+ stdio: 'inherit',
44
+ env: {
45
+ ...process.env,
46
+ KUBE_MCP_FORCE_VM_SANDBOX: '1',
47
+ },
48
+ });
49
+
50
+ child.on('close', (code) => {
51
+ process.exit(code ?? 0);
52
+ });
53
+
54
+ child.on('error', (error) => {
55
+ console.error('Failed to start code-mode CLI:', error);
56
+ process.exit(1);
57
+ });
58
+ }
59
+
60
+ runCodeMode();
@@ -154,7 +154,10 @@ class KubeMCPCLI {
154
154
 
155
155
  try {
156
156
  // Determine the correct index path after build
157
- const finalIndexPath = fs.existsSync(indexPathFlat) ? indexPathFlat : indexPathNested;
157
+ // Prefer the nested path because the TypeScript build outputs to dist/src by default.
158
+ // Older builds may leave a flat dist/index.js behind, which can point to stale artifacts
159
+ // (e.g., missing version.cjs). Prioritizing the nested path avoids those mismatches.
160
+ const finalIndexPath = fs.existsSync(indexPathNested) ? indexPathNested : indexPathFlat;
158
161
 
159
162
  // Debug: Check if the file actually exists
160
163
  if (!fs.existsSync(finalIndexPath)) {
package/bin/setup.js CHANGED
@@ -343,11 +343,12 @@ class SetupManager {
343
343
  console.log('Add the following to your mcp.json (e.g. ~/.cursor/mcp.json):\n');
344
344
  console.log(`{
345
345
  "mcpServers": {
346
- "kubeview-mcp": {
346
+ "kubeview": {
347
347
  "command": "npx",
348
- "args": ["https://github.com/mikhae1/kubeview-mcp"],
348
+ "args": ["-y", "kubeview-mcp"],
349
349
  "env": {
350
- "KUBECONFIG": "$HOME/.kube/config"
350
+ "KUBECONFIG": "$HOME/.kube/config",
351
+ "MCP_MODE": "all"
351
352
  }
352
353
  }
353
354
  }
@@ -0,0 +1,41 @@
1
+ import type { Tool } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { Logger } from 'winston';
3
+ export interface MCPServerConfig {
4
+ name: string;
5
+ command: string;
6
+ args?: string[];
7
+ env?: Record<string, string>;
8
+ timeoutMs?: number;
9
+ }
10
+ export interface ToolRegistration {
11
+ qualifiedName: string;
12
+ server: string;
13
+ toolName: string;
14
+ tool: Tool;
15
+ }
16
+ export interface MCPBridgeOptions {
17
+ enablePII?: boolean;
18
+ logger?: Logger;
19
+ defaultTimeoutMs?: number;
20
+ }
21
+ export declare class MCPBridge {
22
+ private readonly configs;
23
+ private readonly options;
24
+ private clients;
25
+ private toolRegistry;
26
+ private piiTokenizer?;
27
+ private toolDiscoveryCache;
28
+ private configByServer;
29
+ constructor(configs: MCPServerConfig[], options?: MCPBridgeOptions);
30
+ initialize(): Promise<void>;
31
+ private initializeServer;
32
+ private cacheToolMetadata;
33
+ getRegisteredTools(): ToolRegistration[];
34
+ getToolMetadata(qualifiedName: string): ToolRegistration | undefined;
35
+ listServers(): string[];
36
+ listToolsForServer(serverName: string): Tool[];
37
+ callTool<T = any>(qualifiedName: string, args: any): Promise<T>;
38
+ close(): Promise<void>;
39
+ private withTimeout;
40
+ }
41
+ //# sourceMappingURL=MCPBridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MCPBridge.d.ts","sourceRoot":"","sources":["../../../../src/agent/bridge/MCPBridge.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAmB,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,qBAAa,SAAS;IAQlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAR1B,OAAO,CAAC,OAAO,CAAkC;IACjD,OAAO,CAAC,YAAY,CAA4C;IAChE,OAAO,CAAC,YAAY,CAAC,CAAe;IACpC,OAAO,CAAC,kBAAkB,CAAkC;IAC5D,OAAO,CAAC,cAAc,CAA2C;gBAG9C,OAAO,EAAE,eAAe,EAAE,EAC1B,OAAO,GAAE,gBAAqB;IAOpC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAU1B,gBAAgB;IAmC9B,OAAO,CAAC,iBAAiB;IAclB,kBAAkB,IAAI,gBAAgB,EAAE;IAIxC,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIpE,WAAW,IAAI,MAAM,EAAE;IAIvB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE;IAIxC,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC;IA+B/D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YASrB,WAAW;CAiB1B"}
@@ -0,0 +1,127 @@
1
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
2
+ import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
3
+ import { PIITokenizer } from '../security/PIITokenizer.js';
4
+ export class MCPBridge {
5
+ configs;
6
+ options;
7
+ clients = new Map();
8
+ toolRegistry = new Map();
9
+ piiTokenizer;
10
+ toolDiscoveryCache = new Map();
11
+ configByServer = new Map();
12
+ constructor(configs, options = {}) {
13
+ this.configs = configs;
14
+ this.options = options;
15
+ if (options.enablePII) {
16
+ this.piiTokenizer = new PIITokenizer();
17
+ }
18
+ }
19
+ async initialize() {
20
+ for (const config of this.configs) {
21
+ if (this.configByServer.has(config.name)) {
22
+ throw new Error(`Duplicate MCP server name: ${config.name}`);
23
+ }
24
+ this.configByServer.set(config.name, config);
25
+ await this.initializeServer(config);
26
+ }
27
+ }
28
+ async initializeServer(config) {
29
+ const envEntries = Object.entries({
30
+ ...process.env,
31
+ ...config.env,
32
+ }).filter((entry) => typeof entry[1] === 'string');
33
+ const mergedEnv = Object.fromEntries(envEntries);
34
+ const transport = new StdioClientTransport({
35
+ command: config.command,
36
+ args: config.args ?? [],
37
+ env: mergedEnv,
38
+ });
39
+ const client = new Client({
40
+ name: 'kube-mcp-code-mode-client',
41
+ version: '1.0.0',
42
+ }, {
43
+ capabilities: {},
44
+ });
45
+ if (this.options.logger) {
46
+ this.options.logger.info(`Connecting to MCP server '${config.name}'`);
47
+ }
48
+ await client.connect(transport);
49
+ this.clients.set(config.name, client);
50
+ const toolsResponse = await client.listTools();
51
+ this.cacheToolMetadata(config.name, toolsResponse);
52
+ }
53
+ cacheToolMetadata(serverName, toolsResponse) {
54
+ this.toolDiscoveryCache.set(serverName, toolsResponse.tools);
55
+ for (const tool of toolsResponse.tools) {
56
+ const qualifiedName = `${serverName}__${tool.name}`;
57
+ this.toolRegistry.set(qualifiedName, {
58
+ qualifiedName,
59
+ server: serverName,
60
+ toolName: tool.name,
61
+ tool,
62
+ });
63
+ }
64
+ }
65
+ getRegisteredTools() {
66
+ return Array.from(this.toolRegistry.values());
67
+ }
68
+ getToolMetadata(qualifiedName) {
69
+ return this.toolRegistry.get(qualifiedName);
70
+ }
71
+ listServers() {
72
+ return Array.from(this.clients.keys());
73
+ }
74
+ listToolsForServer(serverName) {
75
+ return this.toolDiscoveryCache.get(serverName) ?? [];
76
+ }
77
+ async callTool(qualifiedName, args) {
78
+ const registration = this.toolRegistry.get(qualifiedName);
79
+ if (!registration) {
80
+ throw new Error(`Tool ${qualifiedName} not found`);
81
+ }
82
+ const client = this.clients.get(registration.server);
83
+ if (!client) {
84
+ throw new Error(`Server ${registration.server} not connected`);
85
+ }
86
+ const sanitizedArgs = this.piiTokenizer ? this.piiTokenizer.tokenize(args) : args;
87
+ const timeoutMs = this.configByServer.get(registration.server)?.timeoutMs ?? this.options.defaultTimeoutMs;
88
+ const callPromise = client.callTool({
89
+ name: registration.toolName,
90
+ arguments: sanitizedArgs,
91
+ });
92
+ let result;
93
+ if (timeoutMs && timeoutMs > 0) {
94
+ result = await this.withTimeout(callPromise, timeoutMs, qualifiedName);
95
+ }
96
+ else {
97
+ result = await callPromise;
98
+ }
99
+ const detokenized = this.piiTokenizer ? this.piiTokenizer.detokenize(result) : result;
100
+ return detokenized;
101
+ }
102
+ async close() {
103
+ for (const client of this.clients.values()) {
104
+ await client.close();
105
+ }
106
+ this.clients.clear();
107
+ this.toolRegistry.clear();
108
+ this.toolDiscoveryCache.clear();
109
+ }
110
+ async withTimeout(promise, timeoutMs, label) {
111
+ return new Promise((resolve, reject) => {
112
+ const timer = setTimeout(() => {
113
+ reject(new Error(`${label} timed out after ${timeoutMs}ms`));
114
+ }, timeoutMs);
115
+ promise
116
+ .then((value) => {
117
+ clearTimeout(timer);
118
+ resolve(value);
119
+ })
120
+ .catch((err) => {
121
+ clearTimeout(timer);
122
+ reject(err);
123
+ });
124
+ });
125
+ }
126
+ }
127
+ //# sourceMappingURL=MCPBridge.js.map