Skip to content

Commit 66b13cc

Browse files
committed
Add filtering, pagination, and field stripping
1 parent 49dc8b7 commit 66b13cc

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

src/argocd/client.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,46 @@ export class ArgoCDClient {
2121
this.client = new HttpClient(this.baseUrl, this.apiToken);
2222
}
2323

24-
public async listApplications(params?: { search?: string }) {
25-
const { body } = await this.client.get<V1alpha1ApplicationList>(`/api/v1/applications`, params);
26-
return body;
24+
public async listApplications(params?: { search?: string; limit?: number; offset?: number }) {
25+
const { body } = await this.client.get<V1alpha1ApplicationList>(
26+
`/api/v1/applications`,
27+
params?.search ? { search: params.search } : undefined
28+
);
29+
30+
// Strip heavy fields to reduce token usage
31+
const strippedItems = body.items?.map((app) => ({
32+
metadata: {
33+
name: app.metadata?.name,
34+
namespace: app.metadata?.namespace,
35+
labels: app.metadata?.labels,
36+
creationTimestamp: app.metadata?.creationTimestamp
37+
},
38+
spec: {
39+
project: app.spec?.project,
40+
source: app.spec?.source,
41+
destination: app.spec?.destination
42+
},
43+
status: {
44+
sync: app.status?.sync,
45+
health: app.status?.health,
46+
summary: app.status?.summary
47+
}
48+
})) ?? [];
49+
50+
// Apply pagination
51+
const start = params?.offset ?? 0;
52+
const end = params?.limit ? start + params.limit : strippedItems.length;
53+
const items = strippedItems.slice(start, end);
54+
55+
return {
56+
items,
57+
metadata: {
58+
resourceVersion: body.metadata?.resourceVersion,
59+
totalItems: strippedItems.length,
60+
returnedItems: items.length,
61+
hasMore: end < strippedItems.length
62+
}
63+
};
2764
}
2865

2966
public async getApplication(applicationName: string) {

src/server/server.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,30 @@ export class Server extends McpServer {
4040
.optional()
4141
.describe(
4242
'Search applications by name. This is a partial match on the application name and does not support glob patterns (e.g. "*"). Optional.'
43+
),
44+
limit: z
45+
.number()
46+
.int()
47+
.positive()
48+
.optional()
49+
.describe(
50+
'Maximum number of applications to return. Use this to reduce token usage when there are many applications. Optional.'
51+
),
52+
offset: z
53+
.number()
54+
.int()
55+
.min(0)
56+
.optional()
57+
.describe(
58+
'Number of applications to skip before returning results. Use with limit for pagination. Optional.'
4359
)
4460
},
45-
async ({ search }) =>
46-
await this.argocdClient.listApplications({ search: search ?? undefined })
61+
async ({ search, limit, offset }) =>
62+
await this.argocdClient.listApplications({
63+
search: search ?? undefined,
64+
limit,
65+
offset
66+
})
4767
);
4868
this.addJsonOutputTool(
4969
'get_application',

0 commit comments

Comments
 (0)