Skip to main content
Glama
sapientpants

DeepSource MCP Server

by sapientpants

update_metric_threshold

Adjust quality metric thresholds in DeepSource projects to control when issues are flagged, enabling teams to customize code quality standards based on their requirements.

Instructions

Update the threshold for a specific quality metric

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectKeyYesDeepSource project key to identify the project
repositoryIdYesRepository GraphQL ID
metricShortcodeYesCode for the metric to update
metricKeyYesContext key for the metric
thresholdValueNoNew threshold value, or null to remove

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
okYes
messageYes
metricKeyYes
next_stepsYes
projectKeyYes
thresholdValueNo
metricShortcodeYes

Implementation Reference

  • Core implementation of the update_metric_threshold tool handler. Creates DeepSourceClient and calls setMetricThreshold mutation.
    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);
      }
    );
  • Exported wrapper function for the update_metric_threshold handler that creates dependencies and invokes the core handler.
    export async function handleDeepsourceUpdateMetricThreshold(
      params: DeepsourceUpdateMetricThresholdParams
    ) {
      const deps = createDefaultHandlerDeps({ logger });
      const handler = createUpdateMetricThresholdHandler(deps);
      return handler(params);
    }
  • Zod schema definition for the update_metric_threshold tool, defining input and output validation.
    export const updateMetricThresholdToolSchema = {
      name: 'update_metric_threshold',
      description: 'Update the threshold for a specific 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'),
        metricKey: z.string().describe('Context key for the metric'),
        thresholdValue: z
          .number()
          .nullable()
          .optional()
          .describe('New threshold value, or null to remove'),
      },
      outputSchema: {
        ok: z.boolean(),
        projectKey: z.string(),
        metricShortcode: z.string(),
        metricKey: z.string(),
        thresholdValue: z.number().nullable().optional(),
        message: z.string(),
        next_steps: z.array(z.string()),
      },
    };
  • Registration of the update_metric_threshold tool in the legacy index-registry, using the schema and adapted handler.
    toolRegistry.registerTool({
      ...updateMetricThresholdToolSchema,
      handler: async (params) => {
        const adaptedParams = adaptUpdateMetricThresholdParams(params);
        return handleDeepsourceUpdateMetricThreshold(adaptedParams);
      },
    });
  • Adapter function to convert raw MCP params to typed DeepsourceUpdateMetricThresholdParams for the handler.
    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;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Update' implies mutation, but the description doesn't mention permissions required, whether changes are reversible, rate limits, or what happens when thresholdValue is null. This is inadequate for a mutation tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's appropriately sized and front-loaded, communicating the core purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that an output schema exists, the description doesn't need to explain return values. However, for a mutation tool with 5 parameters, no annotations, and sibling tools present, the description should provide more context about when to use it and behavioral implications. It's minimally adequate but has clear gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds no additional parameter information beyond what's in the schema, but doesn't need to compensate for gaps. The baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Update') and the resource ('threshold for a specific quality metric'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'update_metric_setting' or 'quality_metrics', leaving some ambiguity about when to use this versus those alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'update_metric_setting' or 'quality_metrics'. It doesn't mention prerequisites, context, or exclusions, leaving the agent to guess based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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