Skip to content

Commit fd679e9

Browse files
committed
Add args parameter to create tool for flexible option passing
Enable LLMs to pass arbitrary dcover CLI options through a new 'args' parameter in the create tool. This provides maximum flexibility for advanced test generation configurations without requiring predefined parameters for every possible option. Changes: - Add 'args' parameter to create() function signature - Document parameter in function docstring - Add logic to append args to command before environment options - Log args when provided for debugging Order of precedence for options: 1. Base command with --batch 2. LLM-provided args (new) 3. Environment variable DIFFBLUE_COVER_OPTIONS 4. Entry points This allows LLMs to leverage the comprehensive dcover options documented in the MCP resource while maintaining backward compatibility.
1 parent c4c17b1 commit fd679e9

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

covermcp/server.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,21 @@ def create_options() -> dict:
259259

260260

261261
@mcp.tool()
262-
# Ignore "too many parameters for a method" check
263-
async def create( # noqa: PLR0913
264-
path: Annotated[str | None, "The path to the dcover executable"] = None,
265-
working_directory: Annotated[Path, "The directory containing the project"] = DEFAULT_WORKING_DIRECTORY,
266-
dcover_timeout: Annotated[
267-
int | None, "The maximum time in seconds to wait for dcover to create tests."
268-
] = DEFAULT_TIMEOUT,
269-
entry_points: Annotated[
270-
list[str] | None,
271-
"The list of package names, class names, and/or methods to write tests for. "
272-
"The entries here should be fully qualified, in other words you must include "
273-
"the package and class names when specifying a method name.",
274-
] = None,
275-
ctx: Annotated[Context | None, "The MCP Server Context"] = None,
262+
# Ignore "too many parameters for a method" and "too many positional arguments" check
263+
async def create( # noqa: PLR0913,PLR0917
264+
path: Annotated[str | None, "The path to the dcover executable"] = None,
265+
working_directory: Annotated[Path, "The directory containing the project"] = DEFAULT_WORKING_DIRECTORY,
266+
dcover_timeout: Annotated[
267+
int | None, "The maximum time in seconds to wait for dcover to create tests."
268+
] = DEFAULT_TIMEOUT,
269+
entry_points: Annotated[
270+
list[str] | None,
271+
"The list of package names, class names, and/or methods to write tests for. "
272+
"The entries here should be fully qualified, in other words you must include "
273+
"the package and class names when specifying a method name.",
274+
] = None,
275+
args: Annotated[list[str] | None, "The options to pass to dcover"] = None,
276+
ctx: Annotated[Context | None, "The MCP Server Context"] = None,
276277
) -> object:
277278
"""Invoke Diffblue Cover to generate unit tests for Java code.
278279
@@ -290,6 +291,7 @@ async def create( # noqa: PLR0913
290291
entry_points: List of fully-qualified Java targets (packages, classes, or methods)
291292
to generate tests for. Examples: ['com.example.MyClass',
292293
'com.example.MyClass.myMethod']. If None, tests entire project.
294+
args: Additional arguments to pass to dcover. Defaults to None.
293295
ctx: MCP server context for logging and progress reporting (auto-injected by FastMCP).
294296
295297
Returns:
@@ -319,6 +321,10 @@ async def create( # noqa: PLR0913
319321

320322
command = [path, "create", "--batch"]
321323

324+
if args is not None and len(args) > 0:
325+
await ctx.debug(f"{args} provided by LLM")
326+
command.extend(args)
327+
322328
options = os.getenv(DIFFBLUE_COVER_OPTIONS)
323329
if options is not None and len(options) > 0:
324330
await ctx.debug(f"{DIFFBLUE_COVER_OPTIONS} provided in environment variable")

0 commit comments

Comments
 (0)