Skip to main content
Glama
notasandy

MCP Code Sanitizer

generate_tests

Generate tests for your code. Supports multiple languages and optional frameworks like pytest or Jest.

Instructions

Generates tests for the provided code.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesCode to generate tests for.
languageNoProgramming language.python
frameworkNoTest framework (optional — pytest, jest, unittest, etc.).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Async function that generates tests for provided code. Takes code, language, and optional framework, calls Groq API via the TESTS prompt, caches results, and returns JSON with test cases.
    async def generate_tests(code: str, language: str = "python", framework: str = "") -> str:
        """
        Generates tests for the provided code.
    
        Args:
            code:      Code to generate tests for.
            language:  Programming language.
            framework: Test framework (optional — pytest, jest, unittest, etc.).
    
        Returns:
            JSON with test cases, runnable test code, and coverage estimate.
        """
        if not code.strip():
            return error_response("Empty code provided.")
    
        key = cache.make_key("generate_tests", code, language, framework)
        if hit := cache.get(key):
            return hit
    
        framework_block = f"\nUse framework: {framework}" if framework else ""
        user = f"Language: {language}{framework_block}\n\nCode:\n```{language}\n{code}\n```"
    
        try:
            raw = await call(TESTS, user)
            result = json.loads(raw)
        except httpx.HTTPStatusError as e:
            return error_response(f"Groq API error {e.response.status_code}", e.response.text[:300])
        except json.JSONDecodeError as e:
            return error_response("Groq returned invalid JSON", str(e))
        except ValueError as e:
            return error_response(str(e))
    
        out = json.dumps(result, ensure_ascii=False, indent=2)
        cache.set(key, out)
        return out
  • Docstring/type annotations serving as the schema: accepts code (str), language (str, default python), framework (str, default empty). Returns JSON string.
    """
    Generates tests for the provided code.
    
    Args:
        code:      Code to generate tests for.
        language:  Programming language.
        framework: Test framework (optional — pytest, jest, unittest, etc.).
    
    Returns:
        JSON with test cases, runnable test code, and coverage estimate.
    """
  • tools/__init__.py:4-4 (registration)
    Re-exports generate_tests from tools/tests.py so it can be imported as tools.generate_tests.
    from .tests     import generate_tests
  • server.py:33-33 (registration)
    Registers generate_tests as an MCP tool on the FastMCP server.
    mcp.tool()(generate_tests)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It does not disclose whether this tool is read-only or has side effects, nor does it mention any permissions, rate limits, or behavioral traits beyond generating tests.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single, front-loaded sentence that conveys the core purpose efficiently with no unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite high schema coverage and an output schema, the description does not mention return format, test generation style, or edge cases. It is overly terse for a tool with three parameters.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds no value beyond the schema, merely restating the purpose. It does not explain nuances like language defaults or framework impact.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it generates tests for code, using a specific verb and resource. It is distinct from sibling tools like analyze_code or explain_code, which focus on understanding rather than test generation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives. For example, it does not mention that analyze_code might be better for understanding code before writing tests, nor does it specify any prerequisites or context for test generation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/notasandy/mcp-code-sanitizer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server