Skip to main content
Glama
sapientpants

DeepSource MCP Server

by sapientpants

recent_run_issues

Retrieve code quality issues from the latest analysis on a specific branch to identify and address problems in your project.

Instructions

Get issues from the most recent analysis run on a specific branch

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectKeyYesDeepSource project key to fetch issues for
branchNameYesBranch name to fetch the most recent run from
firstNoNumber of items to retrieve (forward pagination)
afterNoCursor to start retrieving items after (forward pagination)
lastNoNumber of items to retrieve (backward pagination)
beforeNoCursor to start retrieving items before (backward pagination)
page_sizeNoNumber of items per page (alias for first, for convenience)
max_pagesNoMaximum number of pages to fetch (enables automatic multi-page fetching)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
runYes
issuesYes
pageInfoYes
totalCountYes

Implementation Reference

  • Top-level exported handler function for the 'recent_run_issues' tool. Sets up domain repository and client dependencies, creates the handler, executes it, and handles error responses.
    export async function handleDeepsourceRecentRunIssues(
      params: DeepsourceRecentRunIssuesParams
    ): Promise<ApiResponse> {
      const baseDeps = createDefaultHandlerDeps({ logger });
      const apiKey = baseDeps.getApiKey();
      const repositoryFactory = new RepositoryFactory({ apiKey });
      const analysisRunRepository = repositoryFactory.createAnalysisRunRepository();
      const client = new DeepSourceClient(apiKey);
    
      const deps: RecentRunIssuesHandlerDeps = {
        analysisRunRepository,
        client,
        logger,
      };
    
      const handler = createRecentRunIssuesHandlerWithRepo(deps);
      const result = await handler(params);
    
      // If the domain handler returned an error response, throw an error for backward compatibility
      if (result.isError) {
        const firstContent = result.content[0];
        if (firstContent) {
          const errorData = JSON.parse(firstContent.text);
          throw new Error(errorData.error);
        } else {
          throw new Error('Unknown recent run issues error');
        }
      }
    
      return result;
    }
  • Domain-aware handler factory and execution logic. Finds the most recent run using the analysis run repository, fetches issues via DeepSource client, formats response with run details and issues.
    export function createRecentRunIssuesHandlerWithRepo(deps: RecentRunIssuesHandlerDeps) {
      return async function handleRecentRunIssues(params: DeepsourceRecentRunIssuesParams) {
        try {
          const { projectKey, branchName } = params;
          const projectKeyBranded = asProjectKey(projectKey);
          const branchNameBranded = asBranchName(branchName);
    
          deps.logger.info('Fetching recent run from repository and issues from client', {
            projectKey,
            branchName,
          });
    
          // Get the most recent run using domain repository
          const recentRun = await deps.analysisRunRepository.findMostRecent(
            projectKeyBranded,
            branchNameBranded
          );
    
          if (!recentRun) {
            deps.logger.error('No recent run found for branch', { projectKey, branchName });
            throw new Error(
              `No recent analysis run found for branch "${branchName}" in project "${projectKey}"`
            );
          }
    
          deps.logger.info('Found recent run, fetching issues via client', {
            runId: recentRun.runId,
            commitOid: recentRun.commitInfo.oid,
            branchName: recentRun.commitInfo.branch,
          });
    
          // Get issues for this run using the client (since we don't have an issue domain aggregate yet)
          const result = await deps.client.getRecentRunIssues(projectKey, branchName as BranchName);
    
          // Verify we got the same run (sanity check)
          if (!result.run || result.run.runUid !== recentRun.runId) {
            deps.logger.warn('Mismatch between domain run and client run', {
              domainRunId: recentRun.runId,
              clientRunUid: result.run?.runUid || 'null',
            });
          }
    
          deps.logger.info('Successfully fetched recent run issues', {
            runId: recentRun.runId,
            commitOid: recentRun.commitInfo.oid,
            issueCount: result.items.length,
            totalCount: result.totalCount,
            hasNextPage: result.pageInfo?.hasNextPage,
            hasPreviousPage: result.pageInfo?.hasPreviousPage,
          });
    
          const recentRunData = {
            run: {
              id: recentRun.runId,
              runUid: recentRun.runId, // Domain aggregate uses runId as unique identifier
              commitOid: recentRun.commitInfo.oid,
              branchName: recentRun.commitInfo.branch,
              baseOid: recentRun.commitInfo.baseOid,
              status: recentRun.status,
              createdAt: recentRun.timestamps.createdAt,
              updatedAt: recentRun.timestamps.startedAt || recentRun.timestamps.createdAt,
              finishedAt: recentRun.timestamps.finishedAt,
              summary: {
                occurrencesIntroduced: recentRun.summary.totalIntroduced.count,
                occurrencesResolved: recentRun.summary.totalResolved.count,
                occurrencesSuppressed: recentRun.summary.totalSuppressed.count,
                occurrenceDistributionByAnalyzer: recentRun.summary.byAnalyzer.map((dist) => ({
                  analyzerShortcode: dist.analyzerShortcode,
                  introduced: dist.introduced.count,
                })),
                occurrenceDistributionByCategory: recentRun.summary.byCategory.map((dist) => ({
                  category: dist.category,
                  introduced: dist.introduced.count,
                })),
              },
              repository: {
                name: 'Repository', // Domain aggregate doesn't store repository name directly
                id: recentRun.repositoryId,
              },
            },
            issues: result.items.map((issue: DeepSourceIssue) => ({
              id: issue.id,
              title: issue.title,
              shortcode: issue.shortcode,
              category: issue.category,
              severity: issue.severity,
              status: issue.status,
              issue_text: issue.issue_text,
              file_path: issue.file_path,
              line_number: issue.line_number,
              tags: issue.tags,
            })),
            pageInfo: {
              hasNextPage: result.pageInfo?.hasNextPage || false,
              hasPreviousPage: result.pageInfo?.hasPreviousPage || false,
              startCursor: result.pageInfo?.startCursor || null,
              endCursor: result.pageInfo?.endCursor || null,
            },
            totalCount: result.totalCount,
            // Provide helpful information and guidance
            usage_examples: {
              pagination: {
                next_page: 'For forward pagination, use first and after parameters',
                previous_page: 'For backward pagination, use last and before parameters',
              },
              related_tools: {
                run_details: 'Use the run tool to get detailed information about a specific run',
                all_issues: 'Use the project_issues tool to get all issues in the project',
                other_runs: 'Use the runs tool to list all runs for the project',
              },
            },
          };
    
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify(recentRunData),
              },
            ],
          };
        } catch (error) {
          deps.logger.error('Error in handleRecentRunIssues', {
            errorType: typeof error,
            errorName: error instanceof Error ? error.name : 'Unknown',
            errorMessage: error instanceof Error ? error.message : String(error),
            errorStack: error instanceof Error ? error.stack : 'No stack available',
          });
    
          const errorMessage = error instanceof Error ? error.message : 'Unknown error';
          deps.logger.debug('Returning error response', { errorMessage });
    
          return {
            isError: true,
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  error: errorMessage,
                  details: 'Failed to retrieve recent run issues',
                }),
              },
            ],
          };
        }
      };
    }
  • Input and output schema definition using Zod for the 'recent_run_issues' MCP tool.
    export const recentRunIssuesToolSchema = {
      name: 'recent_run_issues',
      description: 'Get issues from the most recent analysis run on a specific branch',
      inputSchema: {
        projectKey: z.string().describe('DeepSource project key to fetch issues for'),
        branchName: z.string().describe('Branch name to fetch the most recent run from'),
        first: z.number().optional().describe('Number of items to retrieve (forward pagination)'),
        after: z
          .string()
          .optional()
          .describe('Cursor to start retrieving items after (forward pagination)'),
        last: z.number().optional().describe('Number of items to retrieve (backward pagination)'),
        before: z
          .string()
          .optional()
          .describe('Cursor to start retrieving items before (backward pagination)'),
        page_size: z
          .number()
          .optional()
          .describe('Number of items per page (alias for first, for convenience)'),
        max_pages: z
          .number()
          .optional()
          .describe('Maximum number of pages to fetch (enables automatic multi-page fetching)'),
      },
      outputSchema: {
        run: z.object({
          id: z.string(),
          runUid: z.string(),
          commitOid: z.string(),
          branchName: z.string(),
          baseOid: z.string(),
          status: z.string(),
          createdAt: z.string(),
          updatedAt: z.string(),
          finishedAt: z.string().optional(),
          summary: z.object({
            occurrencesIntroduced: z.number(),
            occurrencesResolved: z.number(),
            occurrencesSuppressed: z.number(),
            occurrenceDistributionByAnalyzer: z
              .array(
                z.object({
                  analyzerShortcode: z.string(),
                  introduced: z.number(),
                })
              )
              .optional(),
            occurrenceDistributionByCategory: z
              .array(
                z.object({
                  category: z.string(),
                  introduced: z.number(),
                })
              )
              .optional(),
          }),
          repository: z.object({
            name: z.string(),
            id: z.string(),
          }),
        }),
        issues: z.array(
          z.object({
            id: z.string(),
            title: z.string(),
            shortcode: z.string(),
            category: z.string(),
            severity: z.string(),
            status: z.string(),
            issue_text: z.string(),
            file_path: z.string(),
            line_number: z.number(),
            tags: z.array(z.string()),
          })
        ),
        pageInfo: z.object({
          hasNextPage: z.boolean(),
          hasPreviousPage: z.boolean(),
          startCursor: z.string().nullable(),
          endCursor: z.string().nullable(),
        }),
        totalCount: z.number(),
      },
    };
  • Active handler adapter and invocation in TOOL_HANDLERS map used for registering the tool.
    recent_run_issues: async (params: unknown) => {
      const typedParams = params as Record<string, unknown>;
      const recentRunParams: DeepsourceRecentRunIssuesParams = {
        projectKey: typedParams.projectKey as string,
        branchName: typedParams.branchName as string,
      };
    
      if (typeof typedParams.first === 'number') {
        recentRunParams.first = typedParams.first;
      }
      if (typeof typedParams.last === 'number') {
        recentRunParams.last = typedParams.last;
      }
      if (typeof typedParams.after === 'string') {
        recentRunParams.after = typedParams.after;
      }
      if (typeof typedParams.before === 'string') {
        recentRunParams.before = typedParams.before;
      }
    
      return handleDeepsourceRecentRunIssues(recentRunParams);
    },
  • Deprecated registration of the 'recent_run_issues' tool in legacy index-registry.
      ...recentRunIssuesToolSchema,
      handler: async (params) => {
        const adaptedParams = adaptRecentRunIssuesParams(params);
        return handleDeepsourceRecentRunIssues(adaptedParams);
      },
    });
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes a read operation ('Get issues'), but doesn't mention any behavioral traits such as authentication requirements, rate limits, error conditions, or what happens if no recent run exists. This leaves significant gaps in understanding how the tool behaves beyond its basic function.

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 that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to understand at a glance, with every part of the sentence contributing essential information.

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 the tool's complexity (8 parameters, pagination features) and the presence of an output schema (which handles return values), the description is minimally adequate. However, with no annotations and multiple sibling tools, it lacks context on behavioral aspects and usage differentiation, leaving room for improvement in completeness.

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?

The input schema has 100% description coverage, clearly documenting all 8 parameters including pagination details. The description adds no additional parameter semantics beyond implying that 'branchName' is used to fetch the 'most recent run', which is already suggested by the schema. This meets the baseline score of 3 since 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 verb 'Get' and the resource 'issues from the most recent analysis run on a specific branch', making the purpose understandable. However, it doesn't differentiate this tool from sibling tools like 'project_issues' or 'run', which appear related to issues and runs, leaving some ambiguity about when to choose this specific tool.

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 'project_issues' or 'run'. It mentions 'most recent analysis run on a specific branch', which implies a context, but doesn't explicitly state when this is preferred over other issue-fetching tools or what prerequisites might be needed.

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