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.
- package/CHANGELOG.md +51 -1
- package/README.md +81 -181
- package/TODO.md +1 -1
- package/bin/kubeview-mcp-code-mode.js +60 -0
- package/bin/kubeview-mcp.js +4 -1
- package/bin/setup.js +4 -3
- package/dist/src/agent/bridge/MCPBridge.d.ts +41 -0
- package/dist/src/agent/bridge/MCPBridge.d.ts.map +1 -0
- package/dist/src/agent/bridge/MCPBridge.js +127 -0
- package/dist/src/agent/bridge/MCPBridge.js.map +1 -0
- package/dist/src/agent/codegen/CodegenManager.d.ts +26 -0
- package/dist/src/agent/codegen/CodegenManager.d.ts.map +1 -0
- package/dist/src/agent/codegen/CodegenManager.js +222 -0
- package/dist/src/agent/codegen/CodegenManager.js.map +1 -0
- package/dist/src/agent/codegen/SchemaToTypeScriptMapper.d.ts +13 -0
- package/dist/src/agent/codegen/SchemaToTypeScriptMapper.d.ts.map +1 -0
- package/dist/src/agent/codegen/SchemaToTypeScriptMapper.js +54 -0
- package/dist/src/agent/codegen/SchemaToTypeScriptMapper.js.map +1 -0
- package/dist/src/agent/codegen/ToolDescriptionBuilder.d.ts +66 -0
- package/dist/src/agent/codegen/ToolDescriptionBuilder.d.ts.map +1 -0
- package/dist/src/agent/codegen/ToolDescriptionBuilder.js +203 -0
- package/dist/src/agent/codegen/ToolDescriptionBuilder.js.map +1 -0
- package/dist/src/agent/codegen/ToolSchemaIntrospector.d.ts +10 -0
- package/dist/src/agent/codegen/ToolSchemaIntrospector.d.ts.map +1 -0
- package/dist/src/agent/codegen/ToolSchemaIntrospector.js +72 -0
- package/dist/src/agent/codegen/ToolSchemaIntrospector.js.map +1 -0
- package/dist/src/agent/codegen/types.d.ts +31 -0
- package/dist/src/agent/codegen/types.d.ts.map +1 -0
- package/dist/src/agent/codegen/types.js +2 -0
- package/dist/src/agent/codegen/types.js.map +1 -0
- package/dist/src/agent/config/CodeModeConfig.d.ts +67 -0
- package/dist/src/agent/config/CodeModeConfig.d.ts.map +1 -0
- package/dist/src/agent/config/CodeModeConfig.js +41 -0
- package/dist/src/agent/config/CodeModeConfig.js.map +1 -0
- package/dist/src/agent/runtime/code-executor/CodeExecutor.d.ts +25 -0
- package/dist/src/agent/runtime/code-executor/CodeExecutor.d.ts.map +1 -0
- package/dist/src/agent/runtime/code-executor/CodeExecutor.js +95 -0
- package/dist/src/agent/runtime/code-executor/CodeExecutor.js.map +1 -0
- package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.d.ts +21 -0
- package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.d.ts.map +1 -0
- package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.js +89 -0
- package/dist/src/agent/runtime/code-executor/NodeVmCodeExecutor.js.map +1 -0
- package/dist/src/agent/runtime/createSandboxManager.d.ts +4 -0
- package/dist/src/agent/runtime/createSandboxManager.d.ts.map +1 -0
- package/dist/src/agent/runtime/createSandboxManager.js +28 -0
- package/dist/src/agent/runtime/createSandboxManager.js.map +1 -0
- package/dist/src/agent/runtime/ivm/IVMSandboxManager.d.ts +24 -0
- package/dist/src/agent/runtime/ivm/IVMSandboxManager.d.ts.map +1 -0
- package/dist/src/agent/runtime/ivm/IVMSandboxManager.js +320 -0
- package/dist/src/agent/runtime/ivm/IVMSandboxManager.js.map +1 -0
- package/dist/src/agent/runtime/types.d.ts +12 -0
- package/dist/src/agent/runtime/types.d.ts.map +1 -0
- package/dist/src/agent/runtime/types.js +2 -0
- package/dist/src/agent/runtime/types.js.map +1 -0
- package/dist/src/agent/runtime/vm/VmSandboxManager.d.ts +23 -0
- package/dist/src/agent/runtime/vm/VmSandboxManager.d.ts.map +1 -0
- package/dist/src/agent/runtime/vm/VmSandboxManager.js +226 -0
- package/dist/src/agent/runtime/vm/VmSandboxManager.js.map +1 -0
- package/dist/src/agent/security/PIITokenizer.d.ts +15 -0
- package/dist/src/agent/security/PIITokenizer.d.ts.map +1 -0
- package/dist/src/agent/security/PIITokenizer.js +54 -0
- package/dist/src/agent/security/PIITokenizer.js.map +1 -0
- package/dist/src/cli/code-mode.d.ts +3 -0
- package/dist/src/cli/code-mode.d.ts.map +1 -0
- package/dist/src/cli/code-mode.js +214 -0
- package/dist/src/cli/code-mode.js.map +1 -0
- package/dist/src/index.d.ts +7 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +160 -20
- package/dist/src/index.js.map +1 -1
- package/dist/src/plugins/ArgoCDToolsPlugin.d.ts +0 -1
- package/dist/src/plugins/ArgoCDToolsPlugin.d.ts.map +1 -1
- package/dist/src/plugins/ArgoCDToolsPlugin.js +0 -1
- package/dist/src/plugins/ArgoCDToolsPlugin.js.map +1 -1
- package/dist/src/plugins/ArgoToolsPlugin.d.ts +0 -1
- package/dist/src/plugins/ArgoToolsPlugin.d.ts.map +1 -1
- package/dist/src/plugins/ArgoToolsPlugin.js +0 -1
- package/dist/src/plugins/ArgoToolsPlugin.js.map +1 -1
- package/dist/src/plugins/BaseToolsPlugin.d.ts +0 -1
- package/dist/src/plugins/BaseToolsPlugin.d.ts.map +1 -1
- package/dist/src/plugins/BaseToolsPlugin.js.map +1 -1
- package/dist/src/plugins/HelmToolsPlugin.d.ts +0 -1
- package/dist/src/plugins/HelmToolsPlugin.d.ts.map +1 -1
- package/dist/src/plugins/HelmToolsPlugin.js +0 -1
- package/dist/src/plugins/HelmToolsPlugin.js.map +1 -1
- package/dist/src/plugins/KubernetesToolsPlugin.d.ts +0 -1
- package/dist/src/plugins/KubernetesToolsPlugin.d.ts.map +1 -1
- package/dist/src/plugins/KubernetesToolsPlugin.js +0 -1
- package/dist/src/plugins/KubernetesToolsPlugin.js.map +1 -1
- package/dist/src/plugins/SamplePlugin.d.ts +0 -1
- package/dist/src/plugins/SamplePlugin.d.ts.map +1 -1
- package/dist/src/plugins/SamplePlugin.js +1 -2
- package/dist/src/plugins/SamplePlugin.js.map +1 -1
- package/dist/src/server/MCPServer.d.ts +40 -1
- package/dist/src/server/MCPServer.d.ts.map +1 -1
- package/dist/src/server/MCPServer.js +245 -33
- package/dist/src/server/MCPServer.js.map +1 -1
- package/dist/src/tools/RunCodeTool.d.ts +75 -0
- package/dist/src/tools/RunCodeTool.d.ts.map +1 -0
- package/dist/src/tools/RunCodeTool.js +638 -0
- package/dist/src/tools/RunCodeTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetContainerLogsTool.d.ts.map +1 -1
- package/dist/src/tools/kubernetes/GetContainerLogsTool.js +11 -1
- package/dist/src/tools/kubernetes/GetContainerLogsTool.js.map +1 -1
- package/dist/src/tools/kubernetes/KubeListTool.d.ts.map +1 -1
- package/dist/src/tools/kubernetes/KubeListTool.js +47 -29
- package/dist/src/tools/kubernetes/KubeListTool.js.map +1 -1
- package/dist/src/tools/kubernetes/KubeLogTool.d.ts.map +1 -1
- package/dist/src/tools/kubernetes/KubeLogTool.js +142 -26
- package/dist/src/tools/kubernetes/KubeLogTool.js.map +1 -1
- package/dist/src/utils/CodeModeConfig.d.ts +65 -0
- package/dist/src/utils/CodeModeConfig.d.ts.map +1 -0
- package/dist/src/utils/CodeModeConfig.js +41 -0
- package/dist/src/utils/CodeModeConfig.js.map +1 -0
- package/dist/src/utils/toolNamespaces.d.ts +9 -0
- package/dist/src/utils/toolNamespaces.d.ts.map +1 -0
- package/dist/src/utils/toolNamespaces.js +29 -0
- package/dist/src/utils/toolNamespaces.js.map +1 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +3 -0
- package/dist/src/version.js.map +1 -0
- package/dist/tests/agent/PIITokenizer.test.d.ts +2 -0
- package/dist/tests/agent/PIITokenizer.test.d.ts.map +1 -0
- package/dist/tests/agent/PIITokenizer.test.js +19 -0
- package/dist/tests/agent/PIITokenizer.test.js.map +1 -0
- package/dist/tests/agent/SchemaToTypeScriptMapper.test.d.ts +2 -0
- package/dist/tests/agent/SchemaToTypeScriptMapper.test.d.ts.map +1 -0
- package/dist/tests/agent/SchemaToTypeScriptMapper.test.js +27 -0
- package/dist/tests/agent/SchemaToTypeScriptMapper.test.js.map +1 -0
- package/dist/tests/agent/ToolDescriptionBuilder.test.d.ts +2 -0
- package/dist/tests/agent/ToolDescriptionBuilder.test.d.ts.map +1 -0
- package/dist/tests/agent/ToolDescriptionBuilder.test.js +142 -0
- package/dist/tests/agent/ToolDescriptionBuilder.test.js.map +1 -0
- package/dist/tests/index.test.js +2 -2
- package/dist/tests/index.test.js.map +1 -1
- package/dist/tests/kubernetes/KubernetesClient.test.js +10 -1
- package/dist/tests/kubernetes/KubernetesClient.test.js.map +1 -1
- package/dist/tests/server/MCPServer.integration.test.js +2 -2
- package/dist/tests/server/MCPServer.integration.test.js.map +1 -1
- package/dist/tests/server/MCPServer.test.js +1 -6
- package/dist/tests/server/MCPServer.test.js.map +1 -1
- package/dist/tests/tools/RunCodeTool.test.d.ts +2 -0
- package/dist/tests/tools/RunCodeTool.test.d.ts.map +1 -0
- package/dist/tests/tools/RunCodeTool.test.js +211 -0
- package/dist/tests/tools/RunCodeTool.test.js.map +1 -0
- package/dist/tests/tools/kubernetes/KubeListTool.test.d.ts +2 -0
- package/dist/tests/tools/kubernetes/KubeListTool.test.d.ts.map +1 -0
- package/dist/tests/tools/kubernetes/KubeListTool.test.js +45 -0
- package/dist/tests/tools/kubernetes/KubeListTool.test.js.map +1 -0
- package/package.json +15 -12
- package/.prettierrc.json +0 -11
- package/dist/src/tools/helm/HelmReleaseTool.d.ts +0 -10
- package/dist/src/tools/helm/HelmReleaseTool.d.ts.map +0 -1
- package/dist/src/tools/helm/HelmReleaseTool.js +0 -44
- package/dist/src/tools/helm/HelmReleaseTool.js.map +0 -1
- package/src/cli/cli.ts +0 -25
- package/src/cli/run-command.js +0 -391
- package/src/index.ts +0 -47
- package/src/kubernetes/BaseResourceOperations.ts +0 -286
- package/src/kubernetes/CircuitBreaker.ts +0 -485
- package/src/kubernetes/ConnectionManager.ts +0 -114
- package/src/kubernetes/ConnectionPool.ts +0 -551
- package/src/kubernetes/ErrorHandler.ts +0 -436
- package/src/kubernetes/ErrorHandling.ts +0 -401
- package/src/kubernetes/KubernetesClient.ts +0 -653
- package/src/kubernetes/README.md +0 -349
- package/src/kubernetes/ResourceOperations.ts +0 -116
- package/src/kubernetes/RetryStrategy.ts +0 -372
- package/src/kubernetes/RetryableOperation.ts +0 -313
- package/src/kubernetes/docs/ResourceOperations.md +0 -606
- package/src/kubernetes/index.ts +0 -116
- package/src/kubernetes/resources/ConfigMapOperations.ts +0 -368
- package/src/kubernetes/resources/CustomResourceOperations.ts +0 -392
- package/src/kubernetes/resources/DeploymentOperations.ts +0 -294
- package/src/kubernetes/resources/IngressOperations.ts +0 -277
- package/src/kubernetes/resources/MetricOperations.ts +0 -1734
- package/src/kubernetes/resources/NamespaceOperations.ts +0 -129
- package/src/kubernetes/resources/PersistentVolumeClaimOperations.ts +0 -516
- package/src/kubernetes/resources/PersistentVolumeOperations.ts +0 -438
- package/src/kubernetes/resources/PodOperations.ts +0 -417
- package/src/kubernetes/resources/SecretOperations.ts +0 -314
- package/src/kubernetes/resources/ServiceOperations.ts +0 -283
- package/src/kubernetes/utils/ResourceUtils.ts +0 -553
- package/src/plugins/ArgoCDToolsPlugin.ts +0 -93
- package/src/plugins/ArgoToolsPlugin.ts +0 -98
- package/src/plugins/BaseToolsPlugin.ts +0 -149
- package/src/plugins/HelmToolsPlugin.ts +0 -97
- package/src/plugins/KubernetesToolsPlugin.ts +0 -229
- package/src/plugins/SamplePlugin.ts +0 -60
- package/src/plugins/index.ts +0 -4
- package/src/server/MCPServer.ts +0 -536
- package/src/tools/argo/ArgoCronListTool.ts +0 -78
- package/src/tools/argo/ArgoGetTool.ts +0 -91
- package/src/tools/argo/ArgoListTool.ts +0 -144
- package/src/tools/argo/ArgoLogsTool.ts +0 -131
- package/src/tools/argo/BaseTool.ts +0 -69
- package/src/tools/argo/index.ts +0 -5
- package/src/tools/argocd/ArgoCDAppGetTool.ts +0 -109
- package/src/tools/argocd/ArgoCDAppHistoryTool.ts +0 -91
- package/src/tools/argocd/ArgoCDAppListTool.ts +0 -144
- package/src/tools/argocd/ArgoCDAppLogsTool.ts +0 -162
- package/src/tools/argocd/ArgoCDAppResourcesTool.ts +0 -139
- package/src/tools/argocd/ArgoCDAppTool.ts +0 -171
- package/src/tools/argocd/BaseTool.ts +0 -83
- package/src/tools/argocd/index.ts +0 -3
- package/src/tools/helm/BaseTool.ts +0 -60
- package/src/tools/helm/HelmGetHooksTool.ts +0 -44
- package/src/tools/helm/HelmGetManifestTool.ts +0 -44
- package/src/tools/helm/HelmGetNotesTool.ts +0 -44
- package/src/tools/helm/HelmGetResourcesTool.ts +0 -140
- package/src/tools/helm/HelmGetTool.ts +0 -140
- package/src/tools/helm/HelmGetValuesTool.ts +0 -70
- package/src/tools/helm/HelmHistoryTool.ts +0 -56
- package/src/tools/helm/HelmListTool.ts +0 -107
- package/src/tools/helm/HelmListWithResourcesTool.ts +0 -194
- package/src/tools/helm/HelmStatusTool.ts +0 -62
- package/src/tools/helm/index.ts +0 -4
- package/src/tools/kubernetes/BaseTool.ts +0 -76
- package/src/tools/kubernetes/ExecTool.ts +0 -308
- package/src/tools/kubernetes/GetConfigMapTool.ts +0 -33
- package/src/tools/kubernetes/GetContainerLogsTool.ts +0 -140
- package/src/tools/kubernetes/GetCronJobsTool.ts +0 -47
- package/src/tools/kubernetes/GetDaemonSetsTool.ts +0 -55
- package/src/tools/kubernetes/GetDeploymentsTool.ts +0 -33
- package/src/tools/kubernetes/GetEndpointSlicesTool.ts +0 -57
- package/src/tools/kubernetes/GetEndpointsTool.ts +0 -53
- package/src/tools/kubernetes/GetEventsTool.ts +0 -133
- package/src/tools/kubernetes/GetHPATool.ts +0 -48
- package/src/tools/kubernetes/GetIngressTool.ts +0 -39
- package/src/tools/kubernetes/GetJobsTool.ts +0 -54
- package/src/tools/kubernetes/GetLimitRangesTool.ts +0 -40
- package/src/tools/kubernetes/GetMetricsTool.ts +0 -61
- package/src/tools/kubernetes/GetNamespacesTool.ts +0 -36
- package/src/tools/kubernetes/GetNodesTool.ts +0 -55
- package/src/tools/kubernetes/GetPDBTool.ts +0 -48
- package/src/tools/kubernetes/GetPersistentVolumeClaimsTool.ts +0 -113
- package/src/tools/kubernetes/GetPersistentVolumesTool.ts +0 -107
- package/src/tools/kubernetes/GetPodMetricsTool.ts +0 -113
- package/src/tools/kubernetes/GetPodsTool.ts +0 -39
- package/src/tools/kubernetes/GetReplicaSetsTool.ts +0 -51
- package/src/tools/kubernetes/GetResourceQuotaTool.ts +0 -55
- package/src/tools/kubernetes/GetResourceTool.ts +0 -1296
- package/src/tools/kubernetes/GetSecretsTool.ts +0 -55
- package/src/tools/kubernetes/GetServicesTool.ts +0 -39
- package/src/tools/kubernetes/GetStatefulSetsTool.ts +0 -55
- package/src/tools/kubernetes/KubeListTool.ts +0 -1684
- package/src/tools/kubernetes/KubeLogTool.ts +0 -935
- package/src/tools/kubernetes/KubeMetricsTool.ts +0 -220
- package/src/tools/kubernetes/KubeNetTool.ts +0 -481
- package/src/tools/kubernetes/PortForwardTool.ts +0 -307
- package/src/tools/kubernetes/index.ts +0 -10
- package/src/utils/CliUtils.ts +0 -218
- package/src/utils/SensitiveData.ts +0 -148
- 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
|
[](https://nodejs.org/)
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
|
|
7
|
-
KubeView
|
|
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
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
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
|
-
###
|
|
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
|
|
34
|
+
npx -y kubeview-mcp
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
|
|
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
|
|
44
|
+
"kubeview": {
|
|
37
45
|
"command": "npx",
|
|
38
|
-
"args": ["-y", "
|
|
39
|
-
"env": {
|
|
40
|
-
"KUBECONFIG": "$HOME/.kube/config"
|
|
41
|
-
}
|
|
46
|
+
"args": ["-y", "kubeview-mcp"]
|
|
42
47
|
}
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
```
|
|
46
51
|
|
|
47
|
-
###
|
|
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
|
-
|
|
67
|
-
# Build and start
|
|
68
|
-
npm run build
|
|
69
|
-
npm start
|
|
54
|
+
Configure the server using environment variables:
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
##
|
|
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
|
-
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
|
|
92
|
-
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
-
|
|
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
|
-
###
|
|
84
|
+
### Utilities
|
|
85
|
+
- **`run_code`**: Execute sandboxed TypeScript code for complex tasks.
|
|
118
86
|
|
|
119
|
-
|
|
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
|
-
|
|
89
|
+
---
|
|
127
90
|
|
|
128
|
-
|
|
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
|
-
|
|
95
|
+
### What it provides
|
|
134
96
|
|
|
135
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
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
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
199
|
-
|
|
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
|
-
|
|
202
|
-
|
|
128
|
+
2. **Build & Run**:
|
|
129
|
+
```bash
|
|
130
|
+
npm run build
|
|
131
|
+
npm start
|
|
132
|
+
```
|
|
203
133
|
|
|
204
|
-
|
|
205
|
-
|
|
134
|
+
3. **Test**:
|
|
135
|
+
```bash
|
|
136
|
+
npm test
|
|
137
|
+
```
|
|
206
138
|
|
|
207
|
-
|
|
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
|
-
|
|
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
|
-
|
|
214
|
-
npm run command --
|
|
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
|
|
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();
|
package/bin/kubeview-mcp.js
CHANGED
|
@@ -154,7 +154,10 @@ class KubeMCPCLI {
|
|
|
154
154
|
|
|
155
155
|
try {
|
|
156
156
|
// Determine the correct index path after build
|
|
157
|
-
|
|
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
|
|
346
|
+
"kubeview": {
|
|
347
347
|
"command": "npx",
|
|
348
|
-
"args": ["
|
|
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
|