Skip to content

Commit 0480119

Browse files
feat: add cluster management tool to list registered clusters
Signed-off-by: bradfordwagner <wagner.bradford@gmail.com>
1 parent 40b4b88 commit 0480119

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const urlForGithub = `https://insiders.vscode.dev/redirect?url=${encodeURICompon
3737

3838
The server provides the following ArgoCD management tools:
3939

40+
### Cluster Management
41+
- `list_clusters`: List all clusters registered with ArgoCD
42+
4043
### Application Management
4144
- `list_applications`: List and filter all applications
4245
- `get_application`: Get detailed information about a specific application

src/argocd/client.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
V1alpha1ResourceAction,
88
V1alpha1ResourceDiff,
99
V1alpha1ResourceResult,
10-
V1alpha1ApplicationResourceResult
10+
V1alpha1ApplicationResourceResult,
11+
V1alpha1ClusterList
1112
} from '../types/argocd-types.js';
1213
import { HttpClient } from './http.js';
1314

@@ -65,6 +66,19 @@ export class ArgoCDClient {
6566
};
6667
}
6768

69+
public async listClusters(params?: { server?: string; name?: string }) {
70+
const queryParams: Record<string, string> = {};
71+
if (params?.server) queryParams.server = params.server;
72+
if (params?.name) queryParams.name = params.name;
73+
74+
const { body } = await this.client.get<V1alpha1ClusterList>(
75+
`/api/v1/clusters`,
76+
Object.keys(queryParams).length > 0 ? queryParams : undefined
77+
);
78+
79+
return body;
80+
}
81+
6882
public async getApplication(applicationName: string, appNamespace?: string) {
6983
const queryParams = appNamespace ? { appNamespace } : undefined;
7084
const { body } = await this.client.get<V1alpha1Application>(

src/server/server.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ export class Server extends McpServer {
6565
offset
6666
})
6767
);
68+
this.addJsonOutputTool(
69+
'list_clusters',
70+
'list_clusters returns list of clusters registered with ArgoCD',
71+
{
72+
server: z
73+
.string()
74+
.optional()
75+
.describe('Filter clusters by server URL. Optional.'),
76+
name: z
77+
.string()
78+
.optional()
79+
.describe('Filter clusters by name. Optional.')
80+
},
81+
async ({ server, name }) =>
82+
await this.argocdClient.listClusters({
83+
server: server ?? undefined,
84+
name: name ?? undefined
85+
})
86+
);
6887
this.addJsonOutputTool(
6988
'get_application',
7089
'get_application returns application by application name. Optionally specify the application namespace to get applications from non-default namespaces.',

src/types/argocd-types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ export type V1alpha1ResourceAction = ArgoCD.V1alpha1ResourceAction;
1111
export type V1alpha1ResourceDiff = ArgoCD.V1alpha1ResourceDiff;
1212
export type V1alpha1ResourceResult = ArgoCD.V1alpha1ResourceResult;
1313
export type V1alpha1ApplicationResourceResult = ArgoCD.ApplicationApplicationResourceResponse;
14+
export type V1alpha1Cluster = ArgoCD.V1alpha1Cluster;
15+
export type V1alpha1ClusterList = ArgoCD.V1alpha1ClusterList;

0 commit comments

Comments
 (0)