Skip to content

Commit c4c17b1

Browse files
committed
Add MCP resource documenting dcover CLI options
Expose comprehensive dcover configuration documentation through an MCP resource (data://config). This allows LLM clients to query available dcover options and their descriptions, enabling intelligent tool usage and better test generation configurations. The resource includes 50+ dcover CLI options covering: - Test framework selection - Mocking strategies (Mockito, Spring) - Coverage options - Build system preferences - Output customization - Security and sandbox settings Marked as read-only and idempotent for efficient caching.
1 parent e6ab7be commit c4c17b1

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

covermcp/server.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,173 @@ def write_tests() -> list[dict]:
9191
]
9292

9393

94+
@mcp.resource(
95+
"data://config",
96+
description="Provides the configuration options for creating tests with Diffblue Cover.",
97+
mime_type="application/json",
98+
annotations={"readOnlyHint": True, "idempotentHint": True},
99+
)
100+
def create_options() -> dict:
101+
"""Provide comprehensive dcover CLI option documentation.
102+
103+
Exposes 50+ dcover configuration options covering test frameworks,
104+
mocking, coverage, build systems, and Spring configurations. Enables
105+
LLMs to discover and use dcover features intelligently.
106+
107+
Returns:
108+
dict: Mapping of CLI option names to descriptions. Keys can be
109+
passed directly to dcover via the create tool's args parameter.
110+
111+
Note:
112+
Exposed at URI "data://config". Marked read-only and idempotent
113+
for efficient caching.
114+
"""
115+
return {
116+
"--active-profiles": "The comma separated list of profiles to use where creating Spring tests. Not providing a "
117+
"value will use the default profile.",
118+
"--allow-jni": "The comma separated list of additional JNI library name prefixes that should be usable within "
119+
"the sandbox when creating and evaluating tests. JNI library names are the strings supplied in "
120+
"calls to System.loadLibrary(...). By default only JDK provided libraries are allowed. ",
121+
"--annotate-suppress-warnings": "Adds the @SuppressWarning annotation to methods with the given tags, for "
122+
'example: "--annotate-suppress-warnings=unused,rawtypes", would produce '
123+
'@SuppressWarnings({"unused","rawtypes"})',
124+
"--batch": "Do not display progress bars. Automatically enabled when environment variable CI=true, or when "
125+
"using the Cover MCP server.",
126+
"--class-name-template=<template>": "How test classes are named, where Cover will attempt to insert Tests. "
127+
"The same template must be used in dcover create and dcover validate "
128+
"executions. Available replacements: ${CLASS} - the name of the class "
129+
"under test. Default: ${CLASS}DiffblueTest, Tip: Quote or escape "
130+
"templates to stop your shell mangling them.",
131+
"--compliance-level=<value>": "By default dcover automatically detects the Java compliance value, or falls "
132+
"back to 1.8. Use this option to set a specific level from 3 to 17.",
133+
"--cover-all-enums": "Attempt to generate tests using all possible values for enum types used as a parameter, "
134+
"or to generate test cases that cause the method-under-test to return all possible values "
135+
"of enum types. (This will happen even if this provides no additional line coverage.) ",
136+
"--report-file=<report>": "Location of the JSON-formatted test-writing summary report.",
137+
"--coverage-reports": "Once test creation has completed, run JaCoCo commands to get separate coverage reports "
138+
"for the Diffblue and the non-Diffblue tests. All tests that follow the naming pattern "
139+
"(e.g. *DiffblueTest.java) are considered, not just the tests that were created in the "
140+
"current run. By default, the reports are placed in .diffblue/reports/. This option is "
141+
"incompatible with --class-name-template. The command to create the JaCoCo reports can "
142+
"be customised using a custom DiffblueBuild.yaml configuration.",
143+
"--classpath=<value>": "A ':' separated list of directories and JAR archives to search for class files.",
144+
"--test-output-dir=<value>": "Directory where the Diffblue tests are written.",
145+
"--define=<String=String>": "Set system properties to be applied when running tests.",
146+
"--[no-]descriptive-test-names": "Use descriptive test names.",
147+
"--diffblue-class-name-template=<template>": "How the Diffblue test classes are named. Contents will be "
148+
"treated as MaintainedByDiffblue. The same template must be used "
149+
"in dcover create and dcover validate executions. Available "
150+
"replacements: "
151+
"${CLASS} - the name of the class under test."
152+
"Default: ${CLASS}DiffblueTest Tip: Quote or escape templates to "
153+
"stop your shell mangling them.",
154+
"--disable-sandbox": "Uses a more permissive security manager policy for the methods under test. Use with "
155+
"caution: This allows the execution of potentially unsafe code during test creation, "
156+
"which may damage your system environment.",
157+
"--preflight": "Check that the project's environment is ready to run Diffblue Cover.",
158+
"--exclude=<entryPointExclusions>": "Package/class/method to exclude from test-writing. For example, with the "
159+
"specification: dcover create --exclude='com.example.*.model.*' Diffblue "
160+
"Cover will exclude all classes in a model package.",
161+
"--environment=<String=String>": "Set environment variables to be applied when running dcover.",
162+
"--exclude-method=<methodExclusions>": "Methods that should not be used in tests. For example, with the "
163+
"specification: dcover create --exclude-method='com.example.*. model.*' "
164+
"Diffblue Cover test will not make any calls to methods in the model "
165+
"package. Environment: DIFFBLUE_EXCLUDE_METHOD",
166+
"--exclude-modules=<module>[, <module>...]": "Exclude specified modules from the discovered module list. "
167+
"Environment: DIFFBLUE_EXCLUDE_MODULES",
168+
"--exclude-trivial-methods": "Do not write tests for trivial methods.",
169+
"--gradle": "Make Cover prefer the use of Gradle build system.",
170+
"--help": "Show this help message and exit.",
171+
"--include-modules=<module>[, <module>...]": "Include only specified modules from the discovered module list. "
172+
"Environment: DIFFBLUE_INCLUDE_MODULES",
173+
"--keep-partial-tests": "Keep all created tests, even partial tests. These tests may prevent your project from "
174+
"compiling successfully. The provided tests may include tests without assertions, "
175+
"non-compiling tests, non-deterministic tests, tests that throw, and tests that "
176+
"violate the security policy.",
177+
"--location=<value>": "The location in Reports where the uploaded project will be placed.",
178+
"--maven": "Make Cover prefer the use of Maven build system.",
179+
"--max-assertions-per-test=<value>": "Set the maximum number of assertions generated per test. "
180+
"Environment: DIFFBLUE_MAX_ASSERTIONS_PER_TEST",
181+
"--method-name-template=<template>": "Tell dcover how to name test methods. "
182+
"Available replacements: "
183+
"${INNER} - the name of the inner class for the method under test, "
184+
"or blank. "
185+
"${UNIT} - a summary of the methods under test. "
186+
"${METHOD} - the name of the first method under test. "
187+
"${GIVEN} - a summary of the conditions before testing, or blank if no "
188+
"summary is available. ${WHEN} - a summary of the conditions under test, "
189+
"or blank if no summary is available. "
190+
"${THEN} - summary of the test's consequences, or blank if no summary is "
191+
"available. "
192+
"${_} - an underscore, or a blank string if there are no values to "
193+
"separate. Default: test${INNER}${UNIT}${_}${GIVEN}${_}${WHEN}${_}${THEN} "
194+
"For example, given an inner class Foo with an equals(Object) and "
195+
"hashCode() implementation, a test method might be named "
196+
"testFooEqualsAndHashCode_whenOtherIsEqual_thenRet urnEqual(). "
197+
"Tip: Quote or escape templates to stop your shell mangling them.",
198+
"--mock=<value>[, <value>...]": "Prefixes of package/class to mock using Mockito.mock(). The class containing "
199+
"the method under test is never mocked. Non-void, non-private instance methods "
200+
"are stubbed with when(). thenReturn().",
201+
"--mock-construction=<value>[, <value>...]": "Fully qualified names of classes for which to mock constructors "
202+
"using Mockito.mockConstruction. This feature is available with "
203+
"Mockito 3.5.0 and above, when using the inline mock maker. "
204+
"Constructors of the method under test will not be mocked.",
205+
"--mock-method-returns": "Make Cover to be more willing to accept returning mock values from mocked methods. "
206+
"This may allow Cover to write more tests for code which has complex class "
207+
"dependencies, however it may also degrade coverage for code where business logic is "
208+
"complex.",
209+
"--mock-static=<value>[, <value>...]": "Names of classes to mock using Mockito. mockStatic(). This feature is "
210+
"available with Mockito 3.4.0 and above, when inline mocking is "
211+
"enabled. If the method under test is static its class will not be "
212+
"mocked.",
213+
"--name=<value>": "Name of reports bundle. Defaults to the current timestamp, or the latest commit hash when "
214+
"used within Git.",
215+
"--new-jacoco-coverage": "Only create tests that add coverage to the project.",
216+
"--no-spring-boot-tests": "[Beta] When enabled, tests will not use Spring Boot for dependency injection, "
217+
"instead falling back to other mechanisms such as Mockito's @InjectMocks if "
218+
"available.",
219+
"--no-spring-tests": "When enabled, tests will not use Spring contexts for dependency injection",
220+
"--output-comments": "Used to suppress the // Arrange, // Act, and // Assert comments in tests written by "
221+
"Diffblue Cover (set to false). Default is true (show comments).",
222+
"--patch-only=<value>": "Specifies a patch file to have dcover only create tests for the code changes covered "
223+
"by the patch and classes that call classes in the patch. For a multi-module project, "
224+
"generate the patch at the root of the project and provide the absolute path to the "
225+
"patch file, using `--working-directory` with the relative path to the module. The "
226+
"same patch file can be used for each module.",
227+
"--project-name=<value>": "Name of the project shown in Reports of the project being uploaded.",
228+
"--fix-build": "Perform refactorings to fix issues found while attempting to create tests.",
229+
"--report-password=<value>": "Password for authentication when uploading Diffblue Cover Reports. Password can "
230+
"alternatively be set via the environment variable, "
231+
"DIFFBLUE_COVER_REPORTS_PASSWORD",
232+
"--report-username=<value>": "Username for authentication when uploading Diffblue Cover Reports. Username can "
233+
"alternatively be set via the environment variable, "
234+
"DIFFBLUE_COVER_REPORTS_USERNAME",
235+
"--resume-from-module=<module>": "Resume iteration from the specified module. "
236+
"Environment: DIFFBLUE_RESUME_FROM_MODULE",
237+
"--spring-configuration=<value>[, <value>...]": "The Spring configuration classes to use in tests.",
238+
"--spring-integration-tests": "Tests created for Spring components will use mocking only for Repository "
239+
"dependencies. All other dependencies will be resolved by Spring directly. Not "
240+
"applied when creating tests for @Controller classes.",
241+
"--strict": "Forces the strict definition of all project environment options by you - Diffblue Cover will not "
242+
"attempt to make an automated selection. For example, if multiple testing frameworks are "
243+
"configured for your project then running with this option will lead to an error, unless you "
244+
"define which testing framework Cover should use when writing tests. Without this option, Cover "
245+
"would choose one of the testing frameworks for you, and proceed.",
246+
"--testing-framework=<testFrameworkArgument>": "dcover automatically determines the current version of the "
247+
"testing framework in use. This option allows you to specify "
248+
"the framework from 'junit-4.7' to 'junit-5.8', or 'testng'. You"
249+
" can also specify 'junit-4' (any version of JUnit 4) and "
250+
"'junit-5' (any version of JUnit 5)",
251+
"--upload[=<URL>]": "URL of a Cover Reports server to upload reports to.",
252+
"--version": "Print version information and exit.",
253+
"--verbose": "Display more detailed information.",
254+
"--preflight-without-tests": "During the preflight checks, dcover will run the existing tests. To disable that "
255+
"behavior specify this option",
256+
"--working-directory=<value>": "Set the working directory for running dcover. "
257+
"Environment: DIFFBLUE_WORKING_DIRECTORY",
258+
} # fmt: skip
259+
260+
94261
@mcp.tool()
95262
# Ignore "too many parameters for a method" check
96263
async def create( # noqa: PLR0913

0 commit comments

Comments
 (0)