DeepSource 标志

DeepSource

社区
sapientpants

Model Context Protocol (MCP) server for DeepSource

发布者sapientpants
代码仓库deepsource-mcp-server
语言TypeScript
复刻数
3
星标数
7
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    DeepSource 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 7 个 Star 和 3 个 Fork。

DeepSource MCP Server

Main DeepSource DeepSource DeepSource npm version npm downloads License

A Model Context Protocol (MCP) server that integrates with DeepSource to provide AI assistants with access to code quality metrics, issues, and analysis results.

Table of Contents

Overview

The DeepSource MCP Server enables AI assistants like Claude to interact with DeepSource's code quality analysis capabilities through the Model Context Protocol. This integration allows AI assistants to:

  • Retrieve code metrics and analysis results
  • Access and filter issues by analyzer, path, or tags
  • Check quality status and set thresholds
  • Analyze project quality over time
  • Access security compliance reports (OWASP, SANS, MISRA-C)
  • Monitor dependency vulnerabilities
  • Manage quality gates and thresholds

Quick Start

1. Get Your DeepSource API Key

  1. Log in to your DeepSource account
  2. Navigate to Settings → API Access
  3. Click Generate New Token
  4. Copy your API key and keep it secure

2. Install in Claude Desktop

  1. Open Claude Desktop
  2. Go to Settings → Developer → Edit Config
  3. Add this configuration to the mcpServers section:
json
{
  "mcpServers": {
    "deepsource": {
      "command": "npx",
      "args": ["-y", "deepsource-mcp-server@latest"],
      "env": {
        "DEEPSOURCE_API_KEY": "your-deepsource-api-key"
      }
    }
  }
}
  1. Restart Claude Desktop

3. Test Your Connection

Ask Claude: "What DeepSource projects do I have access to?"

If configured correctly, Claude will list your available projects.

Installation

NPX (Recommended)

The simplest way to use the DeepSource MCP Server:

json
{
  "mcpServers": {
    "deepsource": {
      "command": "npx",
      "args": ["-y", "deepsource-mcp-server@latest"],
      "env": {
        "DEEPSOURCE_API_KEY": "your-deepsource-api-key",
        "LOG_FILE": "/tmp/deepsource-mcp.log",
        "LOG_LEVEL": "INFO",
        "RETRY_MAX_ATTEMPTS": "3",
        "RETRY_BASE_DELAY_MS": "1000",
        "RETRY_MAX_DELAY_MS": "30000",
        "RETRY_BUDGET_PER_MINUTE": "10",
        "CIRCUIT_BREAKER_THRESHOLD": "5",
        "CIRCUIT_BREAKER_TIMEOUT_MS": "30000"
      }
    }
  }
}

Docker

For containerized environments:

json
{
  "mcpServers": {
    "deepsource": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "DEEPSOURCE_API_KEY",
        "-e",
        "LOG_FILE=/tmp/deepsource-mcp.log",
        "-v",
        "/tmp:/tmp",
        "sapientpants/deepsource-mcp-server"
      ],
      "env": {
        "DEEPSOURCE_API_KEY": "your-deepsource-api-key"
      }
    }
  }
}

Local Development

For development or customization:

json
{
  "mcpServers": {
    "deepsource": {
      "command": "node",
      "args": ["/path/to/deepsource-mcp-server/dist/index.js"],
      "env": {
        "DEEPSOURCE_API_KEY": "your-deepsource-api-key",
        "LOG_FILE": "/tmp/deepsource-mcp.log",
        "LOG_LEVEL": "DEBUG"
      }
    }
  }
}

Configuration

Environment Variables

VariableRequiredDefaultDescription
DEEPSOURCE_API_KEYYes-Your DeepSource API key for authentication
LOG_FILENo-Path to log file. If not set, no logs are written
LOG_LEVELNoDEBUGMinimum log level: DEBUG, INFO, WARN, ERROR
RETRY_MAX_ATTEMPTSNo3Maximum number of retry attempts for failed requests
RETRY_BASE_DELAY_MSNo1000Base delay in milliseconds for exponential backoff
RETRY_MAX_DELAY_MSNo30000Maximum delay in milliseconds between retries
RETRY_BUDGET_PER_MINUTENo10Maximum retries allowed per minute across all operations
CIRCUIT_BREAKER_THRESHOLDNo5Number of failures before circuit breaker opens
CIRCUIT_BREAKER_TIMEOUT_MSNo30000Time in milliseconds before circuit breaker attempts recovery

Performance Considerations

  • Pagination: Use appropriate page sizes (10-50 items) to balance response time and data completeness
  • Automatic Retry: The server implements intelligent retry logic with:
    • Exponential backoff with jitter to prevent thundering herd
    • Circuit breaker pattern to prevent cascade failures
    • Retry budget to limit resource consumption
    • Respect for Retry-After headers from the API
  • Rate Limits: Rate-limited requests (429) are automatically retried with appropriate delays
  • Fault Tolerance: Transient failures (network, 502, 503, 504) are handled gracefully
  • Caching: Results are not cached. Consider implementing caching for frequently accessed data

Available Tools

1. projects

List all available DeepSource projects.

Parameters: None

Example Response:

json
[
  {
    "key": "https://api-key@app.deepsource.com",
    "name": "my-python-project"
  }
]

2. project_issues

Get issues from a DeepSource project with filtering and pagination.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
firstnumberNoNumber of items to return (forward pagination)
afterstringNoCursor for forward pagination
lastnumberNoNumber of items to return (backward pagination)
beforestringNoCursor for backward pagination
pathstringNoFilter issues by file path
analyzerInstring[]NoFilter by analyzers (e.g., ["python", "javascript"])
tagsstring[]NoFilter by issue tags

Example Response:

json
{
  "issues": [
    {
      "id": "T2NjdXJyZW5jZTpnZHlqdnlxZ2E=",
      "title": "Avoid using hardcoded credentials",
      "shortcode": "PY-D100",
      "category": "SECURITY",
      "severity": "CRITICAL",
      "file_path": "src/config.py",
      "line_number": 42
    }
  ],
  "totalCount": 15,
  "pageInfo": {
    "hasNextPage": true,
    "endCursor": "YXJyYXljb25uZWN0aW9uOjQ="
  }
}

3. runs

List analysis runs for a project with filtering.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
firstnumberNoNumber of items to return (forward pagination)
afterstringNoCursor for forward pagination
lastnumberNoNumber of items to return (backward pagination)
beforestringNoCursor for backward pagination
analyzerInstring[]NoFilter by analyzers

4. run

Get details of a specific analysis run.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
runIdentifierstringYesThe runUid (UUID) or commitOid (commit hash)
isCommitOidbooleanNoWhether runIdentifier is a commit hash (default: false)

5. recent_run_issues

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

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
branchNamestringYesThe branch name
firstnumberNoNumber of items to return
afterstringNoCursor for forward pagination

6. dependency_vulnerabilities

Get security vulnerabilities in project dependencies.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
firstnumberNoNumber of items to return
afterstringNoCursor for forward pagination

Example Response:

json
{
  "vulnerabilities": [
    {
      "id": "VUL-001",
      "package": "requests",
      "version": "2.25.0",
      "severity": "HIGH",
      "cve": "CVE-2021-12345",
      "description": "Remote code execution vulnerability"
    }
  ],
  "totalCount": 3
}

7. quality_metrics

Get code quality metrics with optional filtering.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
shortcodeInstring[]NoFilter by metric codes (see below)

Available Metrics:

  • LCV - Line Coverage
  • BCV - Branch Coverage
  • DCV - Documentation Coverage
  • DDP - Duplicate Code Percentage
  • SCV - Statement Coverage
  • TCV - Total Coverage
  • CMP - Code Maturity

8. update_metric_threshold

Update the threshold for a quality metric.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
repositoryIdstringYesThe GraphQL repository ID
metricShortcodestringYesThe metric shortcode (e.g., "LCV")
metricKeystringYesThe language or context key
thresholdValuenumber|nullNoNew threshold value, or null to remove

9. update_metric_setting

Update metric reporting and enforcement settings.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
repositoryIdstringYesThe GraphQL repository ID
metricShortcodestringYesThe metric shortcode
isReportedbooleanYesWhether to report this metric
isThresholdEnforcedbooleanYesWhether to enforce thresholds

10. compliance_report

Get security compliance reports.

ParameterTypeRequiredDescription
projectKeystringYesThe unique identifier for the DeepSource project
reportTypestringYesType of report (see below)

Available Report Types:

  • OWASP_TOP_10 - Web application security vulnerabilities
  • SANS_TOP_25 - Most dangerous software errors
  • MISRA_C - Guidelines for safety-critical C code
  • CODE_COVERAGE - Code coverage report
  • CODE_HEALTH_TREND - Quality trends over time
  • ISSUE_DISTRIBUTION - Issue categorization
  • ISSUES_PREVENTED - Prevented issues count
  • ISSUES_AUTOFIXED - Auto-fixed issues count

Usage Examples

Monitor Code Quality Trends

Track your project's quality metrics over time:

"Show me the code coverage trend for my main branch"

This combines multiple tools to:

  1. Get recent runs for the main branch
  2. Retrieve coverage metrics for each run
  3. Display the trend

Set Up Quality Gates

Implement quality gates for CI/CD:

"Set up quality gates: 80% line coverage, 0 critical security issues"

This will:

  1. Update the line coverage threshold to 80%
  2. Configure enforcement for the threshold
  3. Check current critical security issues

Investigate Security Vulnerabilities

Comprehensive security analysis:

"Analyze all security vulnerabilities in my project including dependencies"

This performs:

  1. Dependency vulnerability scan
  2. Code security issue analysis
  3. OWASP Top 10 compliance check
  4. Prioritized remediation suggestions

Code Review Assistance

Get AI-powered code review insights:

"What are the most critical issues in the recent commits to feature/new-api?"

This will:

  1. Find the most recent run on the branch
  2. Filter for critical and high severity issues
  3. Group by file and issue type
  4. Suggest fixes

Team Productivity Metrics

Track team code quality metrics:

"Show me code quality metrics across all our Python projects"

This aggregates:

  1. Coverage metrics per project
  2. Issue counts by severity
  3. Trends over the last month
  4. Team performance insights

Architecture

The DeepSource MCP Server uses modern TypeScript patterns for maintainability and type safety.

Key Components

┌─────────────────┐     ┌──────────────────┐     ┌─────────────────┐
│  Claude/AI      │────▶│   MCP Server     │────▶│  DeepSource API │
│  Assistant      │◀────│  (TypeScript)    │◀────│   (GraphQL)     │
└─────────────────┘     └──────────────────┘     └─────────────────┘
  1. MCP Server Integration (src/index.ts)

    • Registers and implements tool handlers
    • Manages MCP protocol communication
    • Handles errors and logging
  2. DeepSource Client (src/deepsource.ts)

    • GraphQL API communication
    • Authentication and retry logic
    • Response parsing and validation
  3. Type System (src/types/)

    • Branded types for type safety
    • Discriminated unions for state management
    • Zod schemas for runtime validation

Type Safety Features

Branded Types

typescript
// Prevent mixing different ID types
type ProjectKey = string & { readonly __brand: 'ProjectKey' };
type RunId = string & { readonly __brand: 'RunId' };

Discriminated Unions

typescript
type RunState =
  | { status: 'PENDING'; queuePosition?: number }
  | { status: 'SUCCESS'; finishedAt: string }
  | { status: 'FAILURE'; error?: { message: string } };

Development

Prerequisites

  • Node.js 22.19.0 or higher
  • pnpm 10.15.1 or higher
  • Docker (optional, for container builds)

Setup

bash
# Clone the repository
git clone https://github.com/sapientpants/deepsource-mcp-server.git
cd deepsource-mcp-server

# Install dependencies
pnpm install

# Build the project
pnpm run build

# Run tests
pnpm test

Development Commands

Note: MCP servers communicate via stdio and cannot be run standalone. Use pnpm run inspect for interactive debugging.

CommandDescription
pnpm installInstall dependencies
pnpm run buildBuild TypeScript code
pnpm run watchBuild in watch mode
pnpm run cleanRemove build artifacts
pnpm run inspectDebug with MCP Inspector
pnpm testRun all tests
pnpm test:watchRun tests in watch mode
pnpm test:coverageGenerate coverage report
pnpm run lintCheck for linting issues
pnpm run lint:fixFix linting issues
pnpm run formatCheck code formatting
pnpm run format:fixFix code formatting
pnpm run check-typesTypeScript type checking
pnpm run ciRun full CI pipeline

Troubleshooting & FAQ

Common Issues

Authentication Error

Error: Invalid API key or unauthorized access

Solution: Verify your DEEPSOURCE_API_KEY is correct and has necessary permissions.

No Projects Found

Error: No projects found

Solution: Ensure your API key has access to at least one project in DeepSource.

Rate Limit Exceeded

Error: API rate limit exceeded

Solution: The server implements automatic retry. Wait a moment or reduce request frequency.

Pagination Cursor Invalid

Error: Invalid cursor for pagination

Solution: Cursors expire. Start a new pagination sequence from the beginning.

FAQ

Q: Which DeepSource plan do I need? A: The MCP server works with all DeepSource plans. Some features like security compliance reports may require specific plan features.

Q: Can I use this with self-hosted DeepSource? A: Yes, configure the API endpoint in your environment variables (feature coming in v1.3.0).

Q: How do I debug issues? A: Enable debug logging by setting LOG_LEVEL=DEBUG and check the log file specified in LOG_FILE.

Q: Is my API key secure? A: The API key is only stored in your local Claude Desktop configuration and is never transmitted except to DeepSource's API.

Q: Can I contribute custom tools? A: Yes! See the Contributing section for guidelines.

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests (pnpm test)
  5. Commit your changes using conventional commits (see below)
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Commit Message Convention

This project uses Conventional Commits to ensure consistent commit messages. Commits are validated using commitlint.

Format

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Types

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation only changes
  • style: Changes that don't affect code meaning (formatting, etc)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Performance improvements
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit

Examples

bash
# Feature
git commit -m "feat: add support for filtering issues by severity"

# Bug fix with scope
git commit -m "fix(api): handle null response from DeepSource API"

# Breaking change
git commit -m "feat!: change API response format

BREAKING CHANGE: Response format now uses camelCase instead of snake_case"

Code Standards

  • Follow TypeScript best practices
  • Maintain test coverage above 80%
  • Use meaningful commit messages
  • Update documentation for new features

License

MIT - see LICENSE file for details.

External Resources


Made with ❤️ by the DeepSource MCP Server community

安装

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "deepsource": {
      "command": "npx",
      "args": [
        "-y",
        "deepsource-mcp-server@latest"
      ],
      "env": {
        "DEEPSOURCE_API_KEY": "your-deepsource-api-key"
      }
    }
  }
}

将 DeepSource MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 DeepSource 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 DeepSource 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 DeepSource MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "deepsource": {
      "command": "npx",
      "args": [
        "-y",
        "deepsource-mcp-server"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 DeepSource MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 DeepSource MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 DeepSource 帮我完成这项任务吗?
DeepSource
当然。我已阅读。
以下是我使用 DeepSource 得到的结果。

常见问题

DeepSource MCP 服务器有什么用途?

DeepSource 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 DeepSource MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 DeepSource,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 DeepSource MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 DeepSource 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 DeepSource MCP 连接到 TypingMind?

DeepSource 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

DeepSource MCP 在 TypingMind 中提供哪些工具?

DeepSource 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 DeepSource MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 DeepSource 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇