Token导航 LogoToken导航TokenDH.com
MCP Java Testing Agent logo
开发工具stdio官方级别未说明来源级核验

MCP Java Testing Agent

MCP Server

MCP Java Testing Agent是一个自动化测试生成、覆盖率分析和样式检查的工具,专为Java/Maven项目设计。

工具数

0

提示词数

0

GitHub Stars

1

资源数

0
测试自动化PythonVS CodeVS Code

安装说明

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

作者 / 组织

amyfan7

提供方

amyfan7

最后核验

2026/5/17 20:21

快速接入

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

命令预览

pip install fastmcp

详细介绍

MCP Java测试代理

此存储库提供了一个MCP(模型上下文协议)服务器,该服务器公开了用于自动化Java/Maven项目的测试生成、覆盖率分析和样式检查的工具。它被设计为由MCP感知客户端使用 tester.prompt.md 提示。

______________________________________________________________________

概述

MCP服务器(在 main.py)公开了以下工具:

  • 在Java代码库中发现公共方法
  • 生成骨架JUnit测试
  • 运行Maven(mvn clean test)
  • 分析JaCoCo报道
  • 分析Checkstyle报告

高级循环(迭代直到达到覆盖率/样式目标)在 tester.prompt.md 并且由LLM客户端执行,而不是用Python硬编码。

______________________________________________________________________

需求

  • Python 3.x
  • Java JDK已安装 PATH
  • Maven(mvn)已安装并打开 PATH
  • Maven项目配置为:

- 将源放在类似下面 A2/src/main/java - 在以下位置生成JaCoCo XML A2/target/site/jacoco/jacoco.xml - 在以下位置生成Checkstyle XML A2/target/checkstyle-result.xml

  • 具有MCP功能的编辑器/客户端(例如,与MCP集成的VS代码)

______________________________________________________________________

安装和配置

  1. 克隆并安装:
   git clone 
   cd 
   pip install fastmcp

    Verify:

    java -version
    mvn -v

    Ensure your Maven pom.xml is set up to:

        Run tests

        Produce JaCoCo and Checkstyle reports at the paths above

运行MCP服务器

从项目根:

python服务器.py

这将通过SSE启动MCP服务器:

如果 __名字__ == "__主要的__": mcp.run(运输=“sse”)

您的MCP客户端应配置为连接到此服务器。 使用测试仪提示

假设您在启用MCP的VS Code编辑器中:

Open the project folder (containing main.py and tester.prompt.md).

Open tester.prompt.md (or tester.md) in the editor.

Press Ctrl+Shift+P to open the Command Palette.

Select “Run Prompt” (or the equivalent command).

Choose the tester prompt.

然后,MCP客户端将:

Call the tools defined in tester.prompt.md:

- mcp-final/generate-tests
- mcp-final/run_tests
- mcp-final/analyze-coverage
- mcp-final/get_all_public_methods
- mcp-final/analyze-checkstyle
- mcp-final/run-checkstyle
- mcp-final/git-add-all
- mcp-final/git-commit
- mcp-final/git_pull_request
- mcp-final/git_push
- mcp-final/git_status

Iterate to generate tests, run coverage/style checks, and produce a final summary.

项目结构(典型)

├── main.py#MCP服务器和工具 ├── .github/提示/ │ └── tester.prompt.md#代理配置/提示 ├── A2/ │ ├── pom.xml文件 │ ├── src/main/java/。..#Java源代码 │ └── 目标/ │ ├── site/jaco/jacoco.xml │ └── checkstyle-result.xml

根据需要调整路径;默认值用于工具实现。 MCP工具 generate_tests(源文件:str)->str

为给定的.java文件生成一个骨架JUnit测试类。

Extracts the class name and public method names via regex.

Creates {ClassName}Test with stub methods:

@Test
void test_methodName() {
    // TODO: implement test
}

Writes to: codebase/src/test/java/{ClassName}Test.java.

返回:成功时的路径消息,如果找不到文件/类/方法,则返回错误字符串。 get_all_public_methods(目录:str=“A2/src/main/java”)->列表\[str\]

递归扫描dir中的.java文件,并返回所有以public开头的行。

Uses os.walk to find .java files.

Reads each file line-by-line and keeps line.strip().startswith("public").

返回:原始行列表(方法签名、构造函数或公共字段)。 analyze_coverage(xml_path:str=“A2/target/site/jaco/jacoco.xml”)->dict

解析JaCoCo XML报告并列出指令覆盖率\str

运行Maven构建和测试:

mvn清洁测试

假设您的Maven配置在构建过程中运行Checkstyle和JaCoCo。

返回:Maven进程的stdout(本文中可见错误)。 analyze_checkstyle(xml_path:str=“A2/target/checkstyle result.xml”)->字典

解析Checkstyle XML报告并列出所有样式冲突。

输出结构:

{ “违规”:\[ { “file”:“/path/to/Foo.java”, “行”:“42”, “列”:“13”, “严重性”:“警告”, “message”:“行长度超过100个字符”, “源代码”:“com.puppycraw.tools.checkstyle.checks.sizes.LineLengthCheck” }, ... \], “计数”:5 }

如果缺少XML文件,则返回“error”键。 代理工作流摘要

tester.prompt.md中实现的典型工作流:

Call get_all_public_methods to discover public methods.

Call generate_tests to create initial JUnit tests.

Call run_checkstyle to run mvn clean test and produce JaCoCo + Checkstyle reports.

Call analyze_coverage to find uncovered methods.

Call analyze_checkstyle to find style violations.

Update tests and code (by the agent using file edits), then repeat steps 3–5.

Stop when:

    100% coverage and zero Checkstyle issues are reached, or

    A maximum iteration count (e.g., 10) is reached.

Produce a final summary report (tests created, coverage, style status, recommendations).

注意事项和限制

Regex-based parsing is simple and may not handle all Java edge cases (complex generics, annotations, inner classes).

Default paths (A2/src/main/java, codebase/src/test/java, etc.) can be customized; keep tool defaults in sync with your project layout.

run_checkstyle only runs mvn clean test; ensure your pom.xml actually binds JaCoCo and Checkstyle to this phase.

The iterative “improve coverage & style” loop is implemented by the MCP client/LLM using these tools, not within server.py itself.

目录标签

目录标签

测试自动化PythonVS Code本地部署代码覆盖率样式检查Java测试Maven集成

支持客户端

VS Code

接入字段

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

stdio

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

none

部署方式(deploymentType,部署类型)

local-only

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

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

0

权限和风险

stdiononelocal-only

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

安装前确认

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

来源信息

继续浏览同类 MCP