Skip to main content
Glama

deepsource_update_metric_threshold

Modify or remove threshold values for quality metrics in a DeepSource project, enabling precise control over pass/fail criteria per language or repository.

Instructions

Update the threshold for a specific quality metric in a DeepSource project.

This allows setting or removing threshold values that determine if a metric passes or fails. Thresholds can be set per language or for the entire repository (AGGREGATE).

Examples:

  • Set a 80% line coverage threshold: metricShortcode="LCV", metricKey="AGGREGATE", thresholdValue=80

  • Remove a threshold: metricShortcode="LCV", metricKey="AGGREGATE", thresholdValue=null

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
metricKeyYesThe language or context key for the metric
metricShortcodeYesThe shortcode of the metric to update
projectKeyYesThe unique identifier for the DeepSource project
repositoryIdYesThe GraphQL repository ID (get this from deepsource_quality_metrics response)
thresholdValueNoThe new threshold value (null to remove the threshold)

Implementation Reference

  • Handler factory creating the function that executes the deepsource_update_metric_threshold tool logic. Uses DeepSourceClient to set the metric threshold.
    export const createUpdateMetricThresholdHandler: HandlerFactory< BaseHandlerDeps, DeepsourceUpdateMetricThresholdParams > = createBaseHandlerFactory( 'update_metric_threshold', async (deps, { projectKey, repositoryId, metricShortcode, metricKey, thresholdValue }) => { 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 threshold', { projectKey, repositoryId, metricShortcode, metricKey, thresholdValue, }); const result = await client.setMetricThreshold({ repositoryId, metricShortcode, metricKey, thresholdValue: thresholdValue ?? null, }); deps.logger.info('Metric threshold update result', { success: result.ok, projectKey, metricShortcode, metricKey, }); const updateResult = { ok: result.ok, projectKey, // Echo back the project key for context metricShortcode, metricKey, thresholdValue, message: result.ok ? `Successfully ${thresholdValue !== null && thresholdValue !== undefined ? 'updated' : 'removed'} threshold for ${metricShortcode} (${metricKey})` : `Failed to update threshold for ${metricShortcode} (${metricKey})`, 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); } );
  • Public exported handler function for the tool, which initializes dependencies and calls the core handler factory.
    export async function handleDeepsourceUpdateMetricThreshold( params: DeepsourceUpdateMetricThresholdParams ) { const deps = createDefaultHandlerDeps({ logger }); const handler = createUpdateMetricThresholdHandler(deps); return handler(params); }
  • Type definition for the input parameters of the tool handler.
    export interface DeepsourceUpdateMetricThresholdParams { /** DeepSource project key to identify the project */ projectKey: string; /** Repository GraphQL ID */ repositoryId: string; /** Code for the metric to update */ metricShortcode: MetricShortcode; /** Context key for the metric */ metricKey: MetricKey; /** New threshold value, or null to remove */ thresholdValue?: number | null; }
  • Tool registration mapping for 'update_metric_threshold' that adapts parameters and calls the handler. Note: tool name may be prefixed with 'deepsource_' in schema.
    update_metric_threshold: async (params: unknown) => { const typedParams = params as Record<string, unknown>; const thresholdParams: { projectKey: string; repositoryId: string; metricShortcode: MetricShortcode; metricKey: MetricKey; thresholdValue?: number | null; } = { projectKey: typedParams.projectKey as string, repositoryId: typedParams.repositoryId as string, metricShortcode: typedParams.metricShortcode as MetricShortcode, metricKey: typedParams.metricKey as MetricKey, }; const thresholdValue = typedParams.thresholdValue as number | null | undefined; if (thresholdValue !== undefined) { thresholdParams.thresholdValue = thresholdValue; } return handleDeepsourceUpdateMetricThreshold(thresholdParams); },
  • Parameter adapter converting raw MCP params to typed handler params.
    export function adaptUpdateMetricThresholdParams( params: unknown ): DeepsourceUpdateMetricThresholdParams { const typedParams = params as Record<string, unknown>; const result: DeepsourceUpdateMetricThresholdParams = { projectKey: typedParams.projectKey as string, // Handler still expects string repositoryId: typedParams.repositoryId as string, // Handler still expects string metricShortcode: typedParams.metricShortcode as MetricShortcode, metricKey: typedParams.metricKey as MetricKey, }; const thresholdValue = typedParams.thresholdValue as number | null | undefined; if (thresholdValue !== undefined) { result.thresholdValue = thresholdValue; } return result; }
  • Deprecated tool registration using schema and adapter (for backward compatibility).
    toolRegistry.registerTool({ ...updateMetricThresholdToolSchema, handler: async (params) => { const adaptedParams = adaptUpdateMetricThresholdParams(params); return handleDeepsourceUpdateMetricThreshold(adaptedParams); }, });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sapientpants/deepsource-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server