diff --git a/src/argocd/client.ts b/src/argocd/client.ts index 78772a6..d8c751d 100644 --- a/src/argocd/client.ts +++ b/src/argocd/client.ts @@ -22,8 +22,35 @@ export class ArgoCDClient { } public async listApplications(params?: { search?: string }) { - const { body } = await this.client.get(`/api/v1/applications`, params); - return body; + const { body } = await this.client.get(`/api/v1/applications`); + + // If no search parameter, return all applications with filtered fields + const filteredItems = body.items?.map((app) => ({ + metadata: { + name: app.metadata?.name, + namespace: app.metadata?.namespace, + labels: app.metadata?.labels + }, + status: { + health: app.status?.health, + sync: app.status?.sync + } + })) || []; + + if (!params?.search) { + return { items: filteredItems }; + } + + // Full-text search across filtered fields and subfields + const searchTerm = params.search.toLowerCase(); + + const searchMatches = filteredItems.filter((app) => { + // Convert the filtered app object to a string for full-text search + const searchableContent = JSON.stringify(app).toLowerCase(); + return searchableContent.includes(searchTerm); + }); + + return { items: searchMatches }; } public async getApplication(applicationName: string) { @@ -107,21 +134,29 @@ export class ArgoCDClient { public async getWorkloadLogs( applicationName: string, applicationNamespace: string, - resourceRef: V1alpha1ResourceResult + resourceRef: V1alpha1ResourceResult, + container?: string, + tailLines?: number ) { const logs: ApplicationLogEntry[] = []; + const params: any = { + appNamespace: applicationNamespace, + namespace: resourceRef.namespace, + resourceName: resourceRef.name, + group: resourceRef.group, + kind: resourceRef.kind, + version: resourceRef.version, + follow: false, + tailLines: tailLines ?? 100 + }; + + if (container) { + params.container = container; + } + await this.client.getStream( `/api/v1/applications/${applicationName}/logs`, - { - appNamespace: applicationNamespace, - namespace: resourceRef.namespace, - resourceName: resourceRef.name, - group: resourceRef.group, - kind: resourceRef.kind, - version: resourceRef.version, - follow: false, - tailLines: 100 - }, + params, (chunk) => logs.push(chunk) ); return logs; diff --git a/src/server/server.ts b/src/server/server.ts index 74a623e..b45956b 100644 --- a/src/server/server.ts +++ b/src/server/server.ts @@ -98,13 +98,17 @@ export class Server extends McpServer { { applicationName: z.string(), applicationNamespace: ApplicationNamespaceSchema, - resourceRef: ResourceRefSchema + resourceRef: ResourceRefSchema, + container: z.string().optional().describe('Optional container name to get logs from a specific container'), + tailLines: z.number().optional().describe('Number of lines to tail from the end of the logs (default: 100)') }, - async ({ applicationName, applicationNamespace, resourceRef }) => + async ({ applicationName, applicationNamespace, resourceRef, container, tailLines }) => await this.argocdClient.getWorkloadLogs( applicationName, applicationNamespace, - resourceRef as V1alpha1ResourceResult + resourceRef as V1alpha1ResourceResult, + container, + tailLines ) ); this.addJsonOutputTool(