Skip to main content
Glama
notasandy

MCP Code Sanitizer

generate_tests

Generate test cases and runnable test code for provided code, with support for various languages and test frameworks, including a coverage estimate.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
languageNopython
frameworkNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main async handler function that generates tests. Takes code, language (default 'python'), and optional framework. Sends a request to Groq LLM with the TESTS prompt, caches the result, and returns JSON with test cases, runnable code, and coverage estimate.
    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=True, indent=2)
        cache.set(key, out)
        return out
  • tools/__init__.py:4-11 (registration)
    Re-export of generate_tests from tools.tests module.
    from .tests     import generate_tests
    from .file_tool import analyze_file
    from .cache_tool import cache_info
    from .report    import generate_report
    __all__ = [
        "analyze_code", "compare_code", "explain_code",
        "generate_tests", "analyze_file", "cache_info", "generate_report",
    ]
Behavior3/5

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

With no annotations, the description carries full burden. It discloses the return structure (JSON with test cases, runnable code, coverage estimate) but does not mention side effects, authorization needs, or rate limits. It is adequate but not rich.

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

Conciseness4/5

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

The description is front-loaded with purpose and efficiently lists parameters in an Args block. It is concise though slightly verbose with line breaks, but overall well-structured and easy to parse.

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

Completeness3/5

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

Given 3 parameters and no annotations, the description covers purpose and parameters but lacks constraints on 'language' and 'framework' (e.g., allowed values). It mentions return structure but not pagination or error handling. Adequate but not fully comprehensive.

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

Parameters5/5

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

Schema description coverage is 0%, so the description compensates fully by explaining each parameter (code, language, framework) with clear semantics. It adds value beyond the raw schema field names and defaults.

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 'Generates tests for the provided code', specifying the verb 'generates' and the resource 'tests for code'. It effectively distinguishes from sibling tools (e.g., analyze_code, explain_code) which focus on analysis rather than 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?

The description provides no guidance on when to use this tool versus alternatives, no prerequisites, and no exclusions. It lacks explicit context for appropriate usage beyond the basic purpose.

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