Sponsored by Deepsite.site

Python Testing Tools MCP Server

Created By
jazzberry-ai4 months ago
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.
Content

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
  1. Install dependencies from requirements.txt:
pip install -r requirements.txt
  1. 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

Server Config

{
  "/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"
        }
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Serper MCP ServerA Serper MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Amap Maps高德地图官方 MCP Server
Playwright McpPlaywright MCP server
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
WindsurfThe new purpose-built IDE to harness magic
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
DeepChatYour AI Partner on Desktop
CursorThe AI Code Editor