MCP Pytest Server

MCP Pytest Server

An MCP-compliant server that enables the execution of pytest test suites and the storage of results into a QA platform database. It allows AI models to trigger test runs, track execution progress, and retrieve historical test data through specialized tool interfaces.

Category
Visit Server

README

MCP Pytest 测试服务器

一个基于 Model Context Protocol (MCP) 的测试执行服务器,支持执行 pytest 测试并将结果存储到 QA 平台数据库。

功能特性

  • ✅ 支持 MCP 协议标准接口
  • ✅ 执行 pytest 测试套件
  • ✅ 解析测试结果并生成报告
  • ✅ 将测试结果存储到数据库
  • ✅ 提供工具调用接口供 Goose 使用
  • ✅ 支持异步执行和进度跟踪

架构设计

mcp-pytest-server/
├── src/                    # 源代码目录
│   ├── __init__.py
│   ├── main.py            # FastAPI 主应用
│   ├── mcp/               # MCP 协议实现
│   ├── pytest_executor/   # pytest 执行器
│   ├── database/          # 数据库操作
│   └── tools/             # 工具定义
├── tests/                 # 测试代码
├── config/                # 配置文件
├── docs/                  # 文档
└── requirements.txt       # 依赖包

快速开始

1. 安装依赖

pip install -r requirements.txt

2. 配置数据库

编辑 config/database.yaml 配置数据库连接。

3. 启动服务器

python -m src.main

4. 在 Goose 中配置

在 Goose 配置中添加 MCP 服务器:

mcp_servers:
  pytest_server:
    command: "python"
    args: ["-m", "src.main"]
    env:
      DATABASE_URL: "sqlite:///./test_results.db"

API 接口

MCP 标准接口

  • POST /initialize - 初始化连接
  • POST /tools/list - 列出可用工具
  • POST /tools/call - 调用工具
  • POST /resources/list - 列出资源
  • POST /resources/read - 读取资源

自定义工具

  1. run_pytest_tests - 执行 pytest 测试

    • 参数: test_path (测试路径), options (pytest 选项)
    • 返回: 测试执行结果和报告
  2. store_test_results - 存储测试结果到数据库

    • 参数: test_results (测试结果数据)
    • 返回: 存储状态和记录ID
  3. get_test_history - 获取历史测试记录

    • 参数: limit (限制数量), project (项目名称)
    • 返回: 历史测试记录列表

数据库设计

CREATE TABLE test_runs (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    project_name TEXT NOT NULL,
    test_path TEXT NOT NULL,
    total_tests INTEGER,
    passed INTEGER,
    failed INTEGER,
    skipped INTEGER,
    duration REAL,
    status TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE test_cases (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    run_id INTEGER,
    test_name TEXT NOT NULL,
    status TEXT,
    duration REAL,
    error_message TEXT,
    stack_trace TEXT,
    FOREIGN KEY (run_id) REFERENCES test_runs (id)
);

开发指南

添加新工具

  1. src/tools/ 目录下创建新的工具模块
  2. 实现工具函数并添加装饰器
  3. src/tools/__init__.py 中注册工具

扩展数据库模型

  1. src/database/models.py 中添加新模型
  2. 更新数据库迁移脚本
  3. 添加相应的 CRUD 操作

许可证

MIT License

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured