deepsource_update_metric_setting
Configure reporting and enforcement of quality metrics in DeepSource projects. Enable or disable metric display in the UI/API and set thresholds to fail checks when unmet.
Instructions
Update the settings for a quality metric in a DeepSource project.
This allows configuring how metrics are used in the project:
Enable/disable reporting the metric in the UI and API
Enable/disable enforcing thresholds (failing checks when thresholds aren't met)
Example:
Enable reporting and enforce thresholds: isReported=true, isThresholdEnforced=true
Only report but don't enforce: isReported=true, isThresholdEnforced=false
Disable completely: isReported=false, isThresholdEnforced=false
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| isReported | Yes | Whether the metric should be reported | |
| isThresholdEnforced | Yes | Whether the threshold should be enforced (can fail checks) | |
| metricShortcode | Yes | The shortcode of the metric to update | |
| projectKey | Yes | The unique identifier for the DeepSource project | |
| repositoryId | Yes | The GraphQL repository ID (get this from deepsource_quality_metrics response) |
Implementation Reference
- src/handlers/quality-metrics.ts:355-407 (handler)Core handler factory implementing the tool logic: adapts parameters, calls DeepSourceClient.updateMetricSetting API, logs, and returns formatted response.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); }
- TypeScript interface defining input parameters for the tool handler.export interface DeepsourceUpdateMetricSettingParams { /** DeepSource project key to identify the project */ projectKey: string; /** Repository GraphQL ID */ repositoryId: string; /** Code for the metric to update */ metricShortcode: MetricShortcode; /** Whether the metric should be reported */ isReported: boolean; /** Whether the threshold should be enforced */ isThresholdEnforced: boolean; }
- src/server/tool-registration.ts:92-101 (registration)Registers the tool handler in TOOL_HANDLERS for 'update_metric_setting', adapting params and calling handleDeepsourceUpdateMetricSetting.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, }); },
- src/index-registry.ts:122-128 (registration)Registers the tool using updateMetricSettingToolSchema with adapted handler calling the main handler function.toolRegistry.registerTool({ ...updateMetricSettingToolSchema, handler: async (params) => { const adaptedParams = adaptUpdateMetricSettingParams(params); return handleDeepsourceUpdateMetricSetting(adaptedParams); }, });
- Adapter function to convert raw MCP params to typed DeepsourceUpdateMetricSettingParams for the handler.export function adaptUpdateMetricSettingParams( params: unknown ): DeepsourceUpdateMetricSettingParams { const typedParams = params as Record<string, unknown>; return { projectKey: typedParams.projectKey as string, // Handler still expects string repositoryId: typedParams.repositoryId as string, // Handler still expects string metricShortcode: typedParams.metricShortcode as MetricShortcode, isReported: typedParams.isReported as boolean, isThresholdEnforced: typedParams.isThresholdEnforced as boolean, }; }