sync_application
Sync an ArgoCD application to its desired state. Supports dry run, prune, and syncing to a specific revision.
Instructions
sync_application syncs application. Specify applicationNamespace if the application is in a non-default namespace to avoid permission errors.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| applicationName | Yes | ||
| applicationNamespace | No | The namespace where the application is located. Required if application is not in the default namespace. | |
| dryRun | No | Perform a dry run sync without applying changes | |
| prune | No | Remove resources that are no longer defined in the source | |
| revision | No | Sync to a specific revision instead of the latest | |
| syncOptions | No | Additional sync options (e.g., ["CreateNamespace=true", "PrunePropagationPolicy=foreground"]) |
Implementation Reference
- src/argocd/client.ts:136-170 (handler)The ArgoCDClient.syncApplication method that executes the sync logic, POSTing to /api/v1/applications/{name}/sync with options like appNamespace, dryRun, prune, revision, and syncOptions.
public async syncApplication( applicationName: string, options?: { appNamespace?: string; dryRun?: boolean; prune?: boolean; revision?: string; syncOptions?: string[]; } ) { const syncRequest: Record<string, string | boolean | string[]> = {}; if (options?.appNamespace) { syncRequest.appNamespace = options.appNamespace; } if (options?.dryRun !== undefined) { syncRequest.dryRun = options.dryRun; } if (options?.prune !== undefined) { syncRequest.prune = options.prune; } if (options?.revision) { syncRequest.revision = options.revision; } if (options?.syncOptions) { syncRequest.syncOptions = options.syncOptions; } const { body } = await this.client.post<V1alpha1Application, V1alpha1Application>( `/api/v1/applications/${applicationName}/sync`, null, Object.keys(syncRequest).length > 0 ? syncRequest : undefined ); return body; } - src/server/server.ts:286-310 (schema)Input schema for the 'sync_application' tool, defining applicationName (string), applicationNamespace (optional), dryRun (optional boolean), prune (optional boolean), revision (optional string), and syncOptions (optional array of strings) via Zod.
'sync_application syncs application. Specify applicationNamespace if the application is in a non-default namespace to avoid permission errors.', { applicationName: z.string(), applicationNamespace: ApplicationNamespaceSchema.optional().describe( 'The namespace where the application is located. Required if application is not in the default namespace.' ), dryRun: z .boolean() .optional() .describe('Perform a dry run sync without applying changes'), prune: z .boolean() .optional() .describe('Remove resources that are no longer defined in the source'), revision: z .string() .optional() .describe('Sync to a specific revision instead of the latest'), syncOptions: z .array(z.string()) .optional() .describe( 'Additional sync options (e.g., ["CreateNamespace=true", "PrunePropagationPolicy=foreground"])' ) }, - src/server/server.ts:284-324 (registration)Registration of the 'sync_application' tool via addJsonOutputTool within the Server constructor, wrapping the handler callback that delegates to argocdClient.syncApplication.
this.addJsonOutputTool( 'sync_application', 'sync_application syncs application. Specify applicationNamespace if the application is in a non-default namespace to avoid permission errors.', { applicationName: z.string(), applicationNamespace: ApplicationNamespaceSchema.optional().describe( 'The namespace where the application is located. Required if application is not in the default namespace.' ), dryRun: z .boolean() .optional() .describe('Perform a dry run sync without applying changes'), prune: z .boolean() .optional() .describe('Remove resources that are no longer defined in the source'), revision: z .string() .optional() .describe('Sync to a specific revision instead of the latest'), syncOptions: z .array(z.string()) .optional() .describe( 'Additional sync options (e.g., ["CreateNamespace=true", "PrunePropagationPolicy=foreground"])' ) }, async ({ applicationName, applicationNamespace, dryRun, prune, revision, syncOptions }) => { const options: Record<string, string | boolean | string[]> = {}; if (applicationNamespace) options.appNamespace = applicationNamespace; if (dryRun !== undefined) options.dryRun = dryRun; if (prune !== undefined) options.prune = prune; if (revision) options.revision = revision; if (syncOptions) options.syncOptions = syncOptions; return await this.argocdClient.syncApplication( applicationName, Object.keys(options).length > 0 ? options : undefined ); } ); - src/server/server.ts:345-365 (helper)The addJsonOutputTool private method that wraps tool registration with JSON output formatting and error handling.
private addJsonOutputTool<Args extends ZodRawShape, T>( name: string, description: string, paramsSchema: Args, cb: (...cbArgs: Parameters<ToolCallback<Args>>) => T ) { this.tool(name, description, paramsSchema as ZodRawShape, async (...args) => { try { const result = await cb.apply(this, args as Parameters<ToolCallback<Args>>); return { isError: false, content: [{ type: 'text', text: JSON.stringify(result) }] }; } catch (error) { return { isError: true, content: [{ type: 'text', text: error instanceof Error ? error.message : String(error) }] }; } }); } - src/shared/models/schema.ts:3-11 (schema)The ApplicationNamespaceSchema Zod schema used for the optional applicationNamespace parameter of sync_application.
export const ApplicationNamespaceSchema = z .string() .min(1) .describe( `The namespace where the ArgoCD application resource will be created. This is the namespace of the Application resource itself, not the destination namespace for the application's resources. You can specify any valid Kubernetes namespace (e.g., 'argocd', 'argocd-apps', 'my-namespace', etc.). The default ArgoCD namespace is typically 'argocd', but you can use any namespace you prefer.` );