Token导航 LogoToken导航TokenDH.com
final project se333 NigelMaloney logo
开发工具stdio官方级别未说明来源级核验

final project se333 NigelMaloney

MCP Server

一个基于Python的模型上下文协议(MCP)服务器,提供自动化的代码质量分析和测试分析工具,适用于开发环境中的代码审查和测试管理。

工具数

6

提示词数

0

GitHub Stars

0

资源数

0
代码审查Claude静态分析Claude DesktopClaudeVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

ghaccount409-school

提供方

ghaccount409-school

最后核验

2026/5/17 20:20

运行时

Python

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

uv run python main.py

详细介绍

SE333最终项目——MCP服务器

基于Python 模型上下文协议(MCP)服务器 提供自动化代码质量分析和测试分析工具,使用 fastmcp 通过SSE运输。

存储库:

______________________________________________________________________

目录

  1. 概述
  2. 安装和设置
  3. 配置
  4. 运行提示工作流
  5. MCP工具参考

- 分析_平均值 - generate_test_report - 检测码味道 - 扫描安全风险 - enforce_style_guide - 检查复杂性

  1. 测试
  2. 故障排除和常见问题

______________________________________________________________________

概述

此MCP服务器公开了六个代码质量分析工具,这些工具与中描述的工作流相一致 tester.prompt.mdcodereview.prompt.md所有工具都可以通过HTTP/SSE由任何兼容MCP的客户端(VS Code、Claude Desktop等)调用。

技术栈:

组件版本
Python3.14.0
fastmcp/mcp3.1.0+/1.26.0+
运输苏格兰和南方能源公司(http://127.0.0.1:8000/sse)
测试运行器pytest 9.0+,带pytest cov

______________________________________________________________________

安装和设置

先决条件

  • Python 3.14+
  • uv 包管理器

步骤

# 1. Clone the repository
git clone https://github.com/ghaccount409-school/final_project_se333_NigelMaloney.git
cd final_project_se333_NigelMaloney
cd CodeBase

# 2. Install dependencies (creates .venv automatically)
uv sync

# 3. Install dev dependencies (pytest, pytest-cov)
uv add pytest pytest-cov --dev

# 4. Start the server
uv run python main.py

服务器启动于 http://127.0.0.1:8000。您应该看到:

INFO:     Started server process [XXXXX]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

______________________________________________________________________

配置

VS代码(mcp.json)

添加以下内容 %APPDATA%\Code\User\mcp.json (Windows)或 ~/.config/Code/User/mcp.json (macOS/Linux):

{
  "servers": {
    "se333-MCP-server": {
      "url": "http://127.0.0.1:8000/sse",
      "type": "http"
    }
  }
}

克劳德桌面版

{
  "mcpServers": {
    "se333-server": {
      "command": "uv",
      "args": ["run", "python", "/absolute/path/to/final_project_se333_NigelMaloney/CodeBase/main.py"]
    }
  }
}

服务器默认值

设置默认值注释
主持人127.0.0.1仅环回-不暴露于网络
港口8000变化 fastmcp 如果需要
运输sseVS Code HTTP类型连接需要

______________________________________________________________________

运行提示工作流

此存储库包括从Copilot Chat使用的提示文件:

  • .github/prompts/tester.prompt.md
  • .github/prompts/codereview.prompt.md

在Copilot聊天中使用以下命令:

运行测试人员工作流程

#file:.github/prompts/tester.prompt.md  

例子:

#file:.github/prompts/tester.prompt.md https://github.com/spring-projects/spring-petclinic https://github.com/ghaccount409-school/se333-demo

这与测试仪提示指令模式相匹配:

#file:./tester.prompt.md  

运行代码审查工作流

#file:.github/prompts/codereview.prompt.md

当前 codereview.prompt.md 其指令中不需要位置存储库参数。

______________________________________________________________________

MCP工具参考

analyze_coverage

来源: tester.prompt.md --步骤5(解析Jacoco/覆盖率输出并识别差距)

评估代码覆盖率,并返回带有建议的结构化状态。

参数:

名称类型描述
covered_linesint测试覆盖的线路
total_linesint代码库中的总行数

退货: dict

密钥类型描述
coveragefloat四舍五入到小数点后两位的百分比
covered_linesint输入回声
total_linesint输入回声
statusstr"excellent""good""acceptable""poor""error"
recommendationstr人类可读指南

状态阈值:

状态条件
excellent100%
good≥ 90%
acceptable≥ 70%
poor\ 10

例子:

check_complexity(cyclomatic_complexity=12, lines_of_code=80)
# → {"complexity_level": "high", "density": 0.15, "needs_refactoring": True, ...}

______________________________________________________________________

测试

# from repository root:
# cd final_project_se333_NigelMaloney/CodeBase

# Run all tests
uv run pytest test_main.py -v

# Run with coverage report
uv run pytest test_main.py --cov=main --cov-report=term-missing

# Run a specific test class
uv run pytest test_main.py::TestScanSecurityRisks -v

测试套件摘要(37个测试,100%覆盖率):

课程测试涵盖的工具
TestAnalyzeCoverage6analyze_coverage
TestGenerateTestReport6generate_test_report
TestDetectCodeSmells6detect_code_smells
TestScanSecurityRisks6scan_security_risks
TestEnforceStyleGuide6enforce_style_guide
TestCheckComplexity6check_complexity
TestMainEntrypoint1服务器启动

______________________________________________________________________

故障排除和常见问题

安装

Q No module named 'mcp'No module named 'fastmcp'

uv syncCodeBase 安装所有声明的依赖项的目录。如果 uv 不在您的路径上,请将其定位在 ~/.local/bin/uv (macOS/Linux)或 %USERPROFILE%\.local\bin\uv.exe (Windows)。

______________________________________________________________________

Q Python 3.14 not foundrequires-python >=3.14

检查您的版本 python --version如果低于3.14,请通过安装 python.orgpyenv:

pyenv install 3.14.0
pyenv local 3.14.0
cd CodeBase
uv sync

______________________________________________________________________

Q: Windows上的虚拟环境激活失败

# PowerShell (may require execution policy change)
Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
.\.venv\Scripts\Activate.ps1

或使用 uv run 直接避免手动激活。

______________________________________________________________________

运行时

Q OSError: [Errno 10048] / Address already in use 在8000端口

另一个进程正在使用端口8000(可能是之前的服务器实例)。

# Windows — find and kill the process
Get-Process -Id (Get-NetTCPConnection -LocalPort 8000).OwningProcess | Stop-Process

______________________________________________________________________

Q: VS Code无法发现MCP工具

  1. 确认服务器正在运行:打开浏览器 http://127.0.0.1:8000/sse --您应该看到一个流式响应。
  2. 检查你的 mcp.json 用途 "type": "http" 以及确切的URL http://127.0.0.1:8000/sse.
  3. 重新加载VS代码: Ctrl+Shift+P → *开发者:重新加载窗口*.
  4. 检查MCP日志: Ctrl+Shift+P → *MCP:显示日志*.

______________________________________________________________________

Q: 工具调用返回 422 Unprocessable Entity

所有布尔参数必须是JSON布尔值(true/false),不是字符串("true").所有整数参数必须是JSON数字,而不是字符串。

// Wrong
{"has_duplicates": "true", "has_long_functions": "false"}

// Correct
{"has_duplicates": true, "has_long_functions": false}

______________________________________________________________________

Q analyze_coverage 回报 "status": "error"

total_lines 被传递为 0。在调用此工具之前,请确保覆盖率工具已针对实际源文件运行。

______________________________________________________________________

测试

Q pytest 未找到

cd CodeBase
uv add pytest pytest-cov --dev

______________________________________________________________________

Q test_main_runs_mcp_server 失败与 OSError

端口8000已占用(活动服务器已在运行)。在运行测试之前停止它,因为此测试会模拟 FastMCP.run 但早期的测试运行可能使事件循环处于不良状态。终止服务器进程并重新运行。

______________________________________________________________________

Q: 添加新工具后覆盖率降至100%以下

为每个引入的新分支编写至少一个测试。运行:

cd CodeBase
uv run pytest test_main.py --cov=main --cov-report=term-missing

Missing 列将显示尚未覆盖的确切行。

______________________________________________________________________

安全与生产

Q: 在公共IP上公开此服务器安全吗?

否。服务器没有身份验证、TLS和速率限制。它仅用于本地/环回使用。对于任何网络部署,将其放置在具有HTTPS和API密钥验证的反向代理(例如nginx)之后。

______________________________________________________________________

Q: 如何向MCP服务器添加身份验证?

fastmcp 不提供内置的身份验证中间件。选项:

  1. 反向代理 --将nginx或Caddy放在前面,并需要一个承载令牌头。
  2. 定制中间件 --包装ASGI应用程序 mcp 与Starlette BaseHTTPMiddleware 这验证了一个秘密。
  3. 基于环境的秘密 --检查 os.environ["API_KEY"] 在每个工具内并提高 ValueError 关于不匹配。

______________________________________________________________________

最后更新时间: 2026年3月12日\ 版本: 0.1.0

目录标签

目录标签

代码审查Claude静态分析CSS本地部署代码质量分析自动化测试开发工具

支持客户端

Claude DesktopClaudeVS Code

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

运行时(runtime,运行环境)

Python

工具数量(toolCount,工具数)

6

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP