22
33This module provides a FastMCP server that exposes Diffblue Cover's test generation
44capabilities through the Model Context Protocol. It allows LLMs to invoke Diffblue Cover
5- to automatically generate unit tests for Java projects.
5+ to automatically generate unit tests for Java and Python projects.
66
77The server exposes a 'create' tool that wraps the dcover CLI, providing configurable
8- test generation with options for fuzzing, verification, and batch processing.
8+ test generation with options for fuzzing, verification, and batch processing. Additional
9+ tools 'refactor' and 'issues' are available for Java projects only.
910
1011Environment Variables:
1112 DIFFBLUE_COVER_CLI: Path to the dcover executable (optional if dcover is on PATH)
7576
7677@mcp .prompt ("write tests" )
7778def write_tests () -> list [dict ]:
78- """Provide system prompt for Java unit test writing guidance.
79+ """Provide system prompt for Java and Python unit test writing guidance.
7980
80- Establishes LLM context as a Java unit testing expert to improve
81+ Establishes LLM context as a unit testing expert to improve
8182 test generation quality and suggestions.
8283
8384 Returns:
@@ -86,7 +87,7 @@ def write_tests() -> list[dict]:
8687 return [
8788 {
8889 "role" : "system" ,
89- "content" : "You are a helpful assistant highly skilled at writing unit tests for java code." ,
90+ "content" : "You are a helpful assistant highly skilled at writing unit tests for Java and Python code." ,
9091 },
9192 ]
9293
@@ -113,6 +114,10 @@ def create_options() -> dict:
113114 for efficient caching.
114115 """
115116 return {
117+ "--agent" : "Select AI agent for test generation: NONE, CLAUDE, CODEX, COPILOT. When using an agent, tests are "
118+ "generated method-by-method with git commit checkpointing. It is recommended to use this option where "
119+ "available as it improves test quality. Set the agent to match the LLM platform in use, e.g. when "
120+ "running in Claude Code, use '--agent=claude'. Default: NONE" ,
116121 "--active-profiles" : "The comma separated list of profiles to use where creating Spring tests. Not providing a "
117122 "value will use the default profile." ,
118123 "--allow-jni" : "The comma separated list of additional JNI library name prefixes that should be usable within "
@@ -379,23 +384,27 @@ async def create( # noqa: PLR0913,PLR0917
379384 args : Annotated [list [str ] | None , "The options to pass to dcover" ] = None ,
380385 ctx : Annotated [Context | None , "The MCP Server Context" ] = None ,
381386) -> object :
382- """Invoke Diffblue Cover to generate unit tests for Java code.
387+ """Invoke Diffblue Cover to generate unit tests for Java or Python code.
383388
384- This tool executes the dcover CLI to automatically generate JUnit tests for the
385- specified Java classes, methods, or packages. It supports various configuration
386- options to control the test generation process.
389+ This tool executes the dcover CLI to automatically generate tests for the
390+ specified classes, methods, packages, or modules. For Java projects, it generates
391+ JUnit tests. For Python projects (experimental), pass "--python" in the args parameter
392+ to generate pytest tests. It supports various configuration options to control the
393+ test generation process.
387394
388395 Args:
389396 path: Path to the dcover executable. If not provided, searches system PATH
390397 and the DIFFBLUE_COVER_CLI environment variable.
391- working_directory: Root directory of the Java project to test. Defaults to
398+ working_directory: Root directory of the project to test. Defaults to
392399 the current working directory.
393400 dcover_timeout: Maximum execution time in seconds. Defaults to 600. Set to None
394401 for no timeout (not recommended).
395- entry_points: List of fully-qualified Java targets (packages, classes, or methods)
396- to generate tests for. Examples: ['com.example.MyClass',
397- 'com.example.MyClass.myMethod']. If None, tests entire project.
398- args: Additional arguments to pass to dcover. Defaults to None.
402+ entry_points: List of fully-qualified targets (packages, classes, or methods)
403+ to generate tests for. For Java: ['com.example.MyClass',
404+ 'com.example.MyClass.myMethod']. For Python: ['mymodule', 'mymodule.MyClass'].
405+ If None, tests entire project.
406+ args: Additional arguments to pass to dcover. For Python projects, include "--python".
407+ Defaults to None.
399408 ctx: MCP server context for logging and progress reporting (auto-injected by FastMCP).
400409
401410 Returns:
@@ -411,6 +420,12 @@ async def create( # noqa: PLR0913,PLR0917
411420 The error includes the partial output collected before failure.
412421
413422 Note:
423+ For enhanced test generation using LLMs, pass "--agent=claude" (or "codex", "copilot")
424+ in the args parameter. This uses the specified LLM agent for test generation instead of
425+ the internal non-LLM engine. It is recommended to use this option where available as it
426+ improves test quality. If used, set the agent to the same type as yourself, e.g. when
427+ running in Claude Code, use "--agent=claude".
428+
414429 If DIFFBLUE_COVER_OPTIONS environment variable is set, it overrides all
415430 option parameters (batch, skip_verification, etc.) except path, working_directory,
416431 timeout, and entry_points.
@@ -478,11 +493,13 @@ async def refactor( # noqa: PLR0913,PLR0917
478493 args : Annotated [list [str ] | None , "The additional options to pass to dcover refactor" ] = None ,
479494 ctx : Annotated [Context | None , "The MCP Server Context" ] = None ,
480495) -> object :
481- """Invoke Diffblue Cover to refactor the project (aliased as 'fix-build').
496+ """Invoke Diffblue Cover to refactor the Java project (aliased as 'fix-build').
482497
483498 This tool executes the `dcover refactor` command to apply automated
484499 refactorings, such as fixing build issues or adding missing dependencies.
485500
501+ **Note:** This command is Java-only and does not support Python projects.
502+
486503 Args:
487504 path: Path to the dcover executable. If not provided, searches system PATH
488505 and the DIFFBLUE_COVER_CLI environment variable.
@@ -534,11 +551,13 @@ async def issues( # noqa: PLR0913,PLR0917
534551 args : Annotated [list [str ] | None , "The additional options to pass to dcover issues" ] = None ,
535552 ctx : Annotated [Context | None , "The MCP Server Context" ] = None ,
536553) -> object :
537- """Invoke Diffblue Cover to identify project issues.
554+ """Invoke Diffblue Cover to identify Java project issues.
538555
539556 This tool executes the `dcover issues` command to output a prioritized
540557 list of project issues that may prevent test generation.
541558
559+ **Note:** This command is Java-only and does not support Python projects.
560+
542561 Args:
543562 path: Path to the dcover executable. If not provided, searches system PATH
544563 and the DIFFBLUE_COVER_CLI environment variable.
0 commit comments