update_metric_setting
Modify quality metric reporting and threshold enforcement settings for DeepSource projects to customize code analysis.
Instructions
Update the settings for a quality metric
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectKey | Yes | DeepSource project key to identify the project | |
| repositoryId | Yes | Repository GraphQL ID | |
| metricShortcode | Yes | Code for the metric to update | |
| isReported | Yes | Whether the metric should be reported | |
| isThresholdEnforced | Yes | Whether the threshold should be enforced |
Implementation Reference
- src/handlers/quality-metrics.ts:355-407 (handler)Core handler factory for update_metric_setting tool. Creates DeepSourceClient, calls client.updateMetricSetting to perform the update, logs activity, formats response with success status, message, and next steps.export const createUpdateMetricSettingHandler: HandlerFactory< BaseHandlerDeps, DeepsourceUpdateMetricSettingParams > = createBaseHandlerFactory( 'update_metric_setting', async (deps, { projectKey, repositoryId, metricShortcode, isReported, isThresholdEnforced }) => { const apiKey = deps.getApiKey(); deps.logger.debug('API key retrieved from config', { length: apiKey.length, prefix: `${apiKey.substring(0, 5)}...`, }); const client = new DeepSourceClient(apiKey); deps.logger.info('Updating metric setting', { projectKey, repositoryId, metricShortcode, isReported, isThresholdEnforced, }); const result = await client.updateMetricSetting({ repositoryId, metricShortcode, isReported, isThresholdEnforced, }); deps.logger.info('Metric setting update result', { success: result.ok, projectKey, metricShortcode, }); const updateResult = { ok: result.ok, projectKey, // Echo back the project key for context metricShortcode, settings: { isReported, isThresholdEnforced, }, message: result.ok ? `Successfully updated settings for ${metricShortcode}` : `Failed to update settings for ${metricShortcode}`, next_steps: result.ok ? ['Use quality_metrics to view the updated metrics'] : ['Check if you have sufficient permissions', 'Verify the repository ID is correct'], }; return wrapInApiResponse(updateResult); } );
- src/handlers/quality-metrics.ts:416-422 (handler)Exported handler function that creates dependencies and invokes the update metric setting handler factory.export async function handleDeepsourceUpdateMetricSetting( params: DeepsourceUpdateMetricSettingParams ) { const deps = createDefaultHandlerDeps({ logger }); const handler = createUpdateMetricSettingHandler(deps); return handler(params); }
- src/server/tool-registration.ts:92-101 (registration)Tool handler registration in TOOL_HANDLERS object, performs type casting on input params and calls the main handler function.update_metric_setting: async (params: unknown) => { const typedParams = params as Record<string, unknown>; return handleDeepsourceUpdateMetricSetting({ projectKey: typedParams.projectKey as string, repositoryId: typedParams.repositoryId as string, metricShortcode: typedParams.metricShortcode as MetricShortcode, isReported: typedParams.isReported as boolean, isThresholdEnforced: typedParams.isThresholdEnforced as boolean, }); },
- Zod schema definition for the update_metric_setting tool, including input parameters (projectKey, repositoryId, metricShortcode, isReported, isThresholdEnforced) and output structure.export const updateMetricSettingToolSchema = { name: 'update_metric_setting', description: 'Update the settings for a quality metric', inputSchema: { projectKey: z.string().describe('DeepSource project key to identify the project'), repositoryId: z.string().describe('Repository GraphQL ID'), metricShortcode: z.nativeEnum(MetricShortcode).describe('Code for the metric to update'), isReported: z.boolean().describe('Whether the metric should be reported'), isThresholdEnforced: z.boolean().describe('Whether the threshold should be enforced'), }, outputSchema: { ok: z.boolean(), projectKey: z.string(), metricShortcode: z.string(), settings: z.object({ isReported: z.boolean(), isThresholdEnforced: z.boolean(), }), message: z.string(), next_steps: z.array(z.string()), }, };
- src/client/metrics-client.ts:113-135 (helper)MetricsClient method that executes the GraphQL mutation to update metric settings via DeepSource API.async updateMetricSetting( params: UpdateMetricSettingParams ): Promise<MetricSettingUpdateResponse> { try { this.logger.info('Updating metric setting', { repositoryId: params.repositoryId, metricShortcode: params.metricShortcode, }); const mutation = MetricsClient.buildUpdateSettingMutation(); const response = await this.executeGraphQL(mutation, { ...params }); if (!response.data) { throw new Error('No data received from GraphQL API'); } this.logger.info('Successfully updated metric setting'); return { ok: true }; } catch (error) { this.logger.error('Error updating metric setting', { error }); throw error; } }