Skip to content

Commit 479abda

Browse files
csz-akuityalexmt
andauthored
feat: Add pagination and field stripping for list_applications (#60)
* docs: remove akuity references (#57) * remove akuity reference Signed-off-by: Alexander Matyushentsev <[email protected]> * remove akuity references Signed-off-by: Alexander Matyushentsev <[email protected]> --------- Signed-off-by: Alexander Matyushentsev <[email protected]> Signed-off-by: Cristina Szumilo <[email protected]> * Add filtering, pagination, and field stripping Signed-off-by: Cristina Szumilo <[email protected]> * linting Signed-off-by: Cristina Szumilo <[email protected]> --------- Signed-off-by: Alexander Matyushentsev <[email protected]> Signed-off-by: Cristina Szumilo <[email protected]> Co-authored-by: Alexander Matyushentsev <[email protected]>
1 parent 49dc8b7 commit 479abda

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

src/argocd/client.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,47 @@ 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 =
32+
body.items?.map((app) => ({
33+
metadata: {
34+
name: app.metadata?.name,
35+
namespace: app.metadata?.namespace,
36+
labels: app.metadata?.labels,
37+
creationTimestamp: app.metadata?.creationTimestamp
38+
},
39+
spec: {
40+
project: app.spec?.project,
41+
source: app.spec?.source,
42+
destination: app.spec?.destination
43+
},
44+
status: {
45+
sync: app.status?.sync,
46+
health: app.status?.health,
47+
summary: app.status?.summary
48+
}
49+
})) ?? [];
50+
51+
// Apply pagination
52+
const start = params?.offset ?? 0;
53+
const end = params?.limit ? start + params.limit : strippedItems.length;
54+
const items = strippedItems.slice(start, end);
55+
56+
return {
57+
items,
58+
metadata: {
59+
resourceVersion: body.metadata?.resourceVersion,
60+
totalItems: strippedItems.length,
61+
returnedItems: items.length,
62+
hasMore: end < strippedItems.length
63+
}
64+
};
2765
}
2866

2967
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)