Python Testing Tools MCP Server

by jazzberry-ai

416 downloads
Not rated
GitHub

About

An advanced Model Context Protocol (MCP) server that provides AI-powered Python testing tools. This project leverages both Google's Gemini AI and BAML (Boundary ML) to intelligently generate comprehensive unit tests and perform sophisticated fuzz testing on Python code.

Details

Author
jazzberry-ai
Downloads
416
Categories
Other, Developer Tools

- AI-powered unit test generation with 4–6 test cases per function
- Intelligent fuzz testing with 20 diverse inputs including edge cases
- Advanced AST analysis for maximum code coverage
- Built-in coverage measurement using coverage.py
- Proper unittest framework with exception testing and safe input parsing
- Automatic import resolution and formatted test file creation

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Python Testing Tools MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install dependencies from requirements.txt, set the GEMINI_API_KEY environment variable, and run python mcp_server.py. For integration with Claude Code, use FastMCP to install the server, then configure it in .claude.json. After starting Claude Code, use commands like "create unit tests for @file.py", "generate comprehensive coverage tests for @file.py", or "fuzz test the function_name in @file.py".

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "python testing tools mcp server": {
            "mcpServers": {
                "python_testing_tools": {
                    "type": "stdio",
                    "command": "uv",
                    "args": [
                        "run",
                        "--with",
                        "fastmcp",
                        "fastmcp",
                        "run",
                        "/path/to/your/project/python_testing_mcp_server.py"
                    ],
                    "env": {
                        "GEMINI_API_KEY": "your-api-key-here"
                    }
                }
            }
        }
    }
}

/path/to/your/project

{
    "mcpServers": {
        "python_testing_tools": {
            "type": "stdio",
            "command": "uv",
            "args": [
                "run",
                "--with",
                "fastmcp",
                "fastmcp",
                "run",
                "/path/to/your/project/python_testing_mcp_server.py"
            ],
            "env": {
                "GEMINI_API_KEY": "your-api-key-here"
            }
        }
    }
}

Configuration

The server uses environment variables for configuration:

- GEMINI_API_KEY: Required - Your Google Gemini API key for AI-powered test generation
- GEMINI_MODEL: Optional - Gemini model to use (default: gemini-2.5-flash)

The BAML configuration in baml_src/main.baml defines:
- AI function signatures for test generation, fuzz input creation, and coverage-focused test generation
- Structured response formats using BAML classes (PythonTestFile, FuzzInput, CoverageAnalysis)
- Detailed prompts for comprehensive test coverage, including branch and path analysis

Installation

1. Create and activate a virtual environment:

python3 -m venv .venv
source .venv/bin/activate

2. Install dependencies from requirements.txt:

pip install -r requirements.txt

3. Set your Gemini API key:

export GEMINI_API_KEY="your-api-key-here"

Running the Server

To run the MCP server:

python mcp_server.py

Running the Server in Claude Code

The documentation for FastMCP and Claude Code can be found here: https://gofastmcp.com/integrations/claude-code

Step 1: Install the MCP Server

Install the server using FastMCP:

fastmcp install claude-code python_testing_mcp_server.py --env GEMINI_API_KEY='your-api-key-here'

Step 2: Configure Claude Code

Your .claude.json configuration should look like this:

{
  "/path/to/your/project": {
    "allowedTools": [],
    "history": [],
    "mcpContextUris": [],
    "mcpServers": {
      "python_testing_tools": {
        "type": "stdio",
        "command": "uv",
        "args": [
          "run",
          "--with",
          "fastmcp",
          "fastmcp",
          "run",
          "/path/to/your/project/python_testing_mcp_server.py"
        ],
        "env": {
          "GEMINI_API_KEY": "your-api-key-here"
        }
      }
    },
    "enabledMcpjsonServers": [],
    "disabledMcpjsonServers": [],
    "hasTrustDialogAccepted": false,
    "projectOnboardingSeenCount": 0,
    "hasClaudeMdExternalIncludesApproved": false,
    "hasClaudeMdExternalIncludesWarningShown": false
  }
}

Note: Replace /path/to/your/project with the actual path to your project directory, and your-api-key-here with your actual Gemini API key.

Step 3: Start Claude Code

Start Claude Code:

claude

Step 4: Verify Connection

Check if the MCP server is connected:

/mcp

Step 5: Test the Tools

Test the unit test generation tool:

create unit tests for @demo/basic_example_functions.py

Test the coverage testing tool:

generate comprehensive coverage tests for @demo/basic_example_functions.py

Test the fuzz testing tool:

fuzz test the add function in @demo/basic_example_functions.py

These should create test files in the demo folder with comprehensive test coverage.

Available Tools

Unit Test Generator

- Function: generate_unit_tests_tool - Description: Generates comprehensive unit tests for all functions in a Python file using AI - Parameters: - file_path (str) - Path to the Python file to generate tests for - Features: - Generates 4-6 test cases per function covering normal, edge, and error cases - Uses proper unittest framework with self.assertRaises() for exception testing - Automatically handles module imports and class naming conventions - Creates properly formatted test files with correct indentation

Fuzz Tester

- Function: fuzz_test_function_tool - Description: Performs intelligent fuzz testing on a specific function using AI-generated inputs - Parameters: - file_path (str) - Path to the Python file containing the function - function_name (str) - Name of the specific function to fuzz test - Features: - Generates 20 diverse test inputs including edge cases and malformed data - Tests with boundary values, large inputs, and unusual data combinations - Reports crashes with detailed error traces and input values - Uses ast.literal_eval() for safe input parsing

Coverage Tester

- Function: generate_coverage_tests_tool - Description: Generates comprehensive test cases designed to achieve maximum code coverage using advanced AST analysis and AI-powered test generation - Parameters: - file_path (str) - Path to the Python file to generate coverage tests for - Features: - Advanced AST Analysis: Automatically detects branches, loops, exception paths, and return statements - Intelligent Coverage Targeting: Generates tests specifically designed to cover all code paths - Built-in Coverage Measurement: Integrates coverage.py for real-time coverage reporting - Comprehensive Test Scenarios: Creates tests for: - Branch coverage (if/elif/else conditions) - Loop coverage (zero, one, multiple iterations, break/continue) - Exception coverage (try/except/finally blocks) - Return path coverage (all possible return statements) - Parameter coverage (different types, boundary values, edge cases) - Type compatibility testing (invalid inputs, TypeError scenarios) - State-of-the-Art Testing: Includes infinity/NaN testing, large number handling, empty collections - Automatic Import Resolution: Properly includes all necessary imports (sys, math, etc.) - Coverage Reporting: Generates detailed coverage reports showing achieved coverage percentages
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.