Skip to content

Commit 3e3986a

Browse files
committed
Allow fetching a smaller subset of logs and add client side filtering with fewer fields
1 parent ea9c071 commit 3e3986a

File tree

2 files changed

+55
-16
lines changed

2 files changed

+55
-16
lines changed

src/argocd/client.ts

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,35 @@ export class ArgoCDClient {
2222
}
2323

2424
public async listApplications(params?: { search?: string }) {
25-
const { body } = await this.client.get<V1alpha1ApplicationList>(`/api/v1/applications`, params);
26-
return body;
25+
const { body } = await this.client.get<V1alpha1ApplicationList>(`/api/v1/applications`);
26+
27+
// If no search parameter, return all applications with filtered fields
28+
const filteredItems = body.items?.map((app) => ({
29+
metadata: {
30+
name: app.metadata?.name,
31+
namespace: app.metadata?.namespace,
32+
labels: app.metadata?.labels
33+
},
34+
status: {
35+
health: app.status?.health,
36+
sync: app.status?.sync
37+
}
38+
})) || [];
39+
40+
if (!params?.search) {
41+
return { items: filteredItems };
42+
}
43+
44+
// Full-text search across filtered fields and subfields
45+
const searchTerm = params.search.toLowerCase();
46+
47+
const searchMatches = filteredItems.filter((app) => {
48+
// Convert the filtered app object to a string for full-text search
49+
const searchableContent = JSON.stringify(app).toLowerCase();
50+
return searchableContent.includes(searchTerm);
51+
});
52+
53+
return { items: searchMatches };
2754
}
2855

2956
public async getApplication(applicationName: string) {
@@ -107,21 +134,29 @@ export class ArgoCDClient {
107134
public async getWorkloadLogs(
108135
applicationName: string,
109136
applicationNamespace: string,
110-
resourceRef: V1alpha1ResourceResult
137+
resourceRef: V1alpha1ResourceResult,
138+
container?: string,
139+
tailLines?: number
111140
) {
112141
const logs: ApplicationLogEntry[] = [];
142+
const params: any = {
143+
appNamespace: applicationNamespace,
144+
namespace: resourceRef.namespace,
145+
resourceName: resourceRef.name,
146+
group: resourceRef.group,
147+
kind: resourceRef.kind,
148+
version: resourceRef.version,
149+
follow: false,
150+
tailLines: tailLines ?? 100
151+
};
152+
153+
if (container) {
154+
params.container = container;
155+
}
156+
113157
await this.client.getStream<ApplicationLogEntry>(
114158
`/api/v1/applications/${applicationName}/logs`,
115-
{
116-
appNamespace: applicationNamespace,
117-
namespace: resourceRef.namespace,
118-
resourceName: resourceRef.name,
119-
group: resourceRef.group,
120-
kind: resourceRef.kind,
121-
version: resourceRef.version,
122-
follow: false,
123-
tailLines: 100
124-
},
159+
params,
125160
(chunk) => logs.push(chunk)
126161
);
127162
return logs;

src/server/server.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,17 @@ export class Server extends McpServer {
9898
{
9999
applicationName: z.string(),
100100
applicationNamespace: ApplicationNamespaceSchema,
101-
resourceRef: ResourceRefSchema
101+
resourceRef: ResourceRefSchema,
102+
container: z.string().optional().describe('Optional container name to get logs from a specific container'),
103+
tailLines: z.number().optional().describe('Number of lines to tail from the end of the logs (default: 100)')
102104
},
103-
async ({ applicationName, applicationNamespace, resourceRef }) =>
105+
async ({ applicationName, applicationNamespace, resourceRef, container, tailLines }) =>
104106
await this.argocdClient.getWorkloadLogs(
105107
applicationName,
106108
applicationNamespace,
107-
resourceRef as V1alpha1ResourceResult
109+
resourceRef as V1alpha1ResourceResult,
110+
container,
111+
tailLines
108112
)
109113
);
110114
this.addJsonOutputTool(

0 commit comments

Comments
 (0)