{"id":49605389,"url":"https://github.com/0-co/mcp-test","last_synced_at":"2026-05-04T12:04:34.000Z","repository":{"id":346064636,"uuid":"1188389372","full_name":"0-co/mcp-test","owner":"0-co","description":"pytest integration and CLI for testing MCP servers — the missing testing layer for MCP","archived":false,"fork":false,"pushed_at":"2026-03-22T02:38:33.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-03-22T18:03:52.718Z","etag":null,"topics":["cli","integration-testing","mcp","mcp-server","mcp-testing","pytest","python","testing"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0-co.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-22T02:16:02.000Z","updated_at":"2026-03-22T02:38:29.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/0-co/mcp-test","commit_stats":null,"previous_names":["0-co/mcp-test"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/0-co/mcp-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0-co%2Fmcp-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0-co%2Fmcp-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0-co%2Fmcp-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0-co%2Fmcp-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0-co","download_url":"https://codeload.github.com/0-co/mcp-test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0-co%2Fmcp-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32606413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"ssl_error","status_checked_at":"2026-05-04T10:08:02.005Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","integration-testing","mcp","mcp-server","mcp-testing","pytest","python","testing"],"created_at":"2026-05-04T12:04:32.738Z","updated_at":"2026-05-04T12:04:33.993Z","avatar_url":"https://github.com/0-co.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mcp-pytest\n\npytest integration and CLI for testing MCP servers.\n\n[![PyPI](https://img.shields.io/pypi/v/mcp-pytest)](https://pypi.org/project/mcp-pytest/)\n\n```bash\npip install mcp-pytest\n```\n\n\u003e After installing, the CLI command is `mcp-test`. The Python import is `from mcp_test import MCPClient`.\n\nNo other MCP testing tools exist. If you're building a Python MCP server, you need this.\n\n## Quick Start\n\n**List tools your server exposes:**\n```bash\nmcp-test list \"python my_server.py\"\n```\n\n**Call a tool:**\n```bash\nmcp-test call \"python my_server.py\" search '{\"query\": \"hello\"}'\n```\n\n**Smoke test (verify server starts and tools respond):**\n```bash\nmcp-test check \"python my_server.py\" --smoke\n```\n\n## pytest Integration\n\nWrite real tests for your MCP server:\n\n```python\n# conftest.py\n# (no extra setup needed — the mcp_server fixture is auto-registered)\n\n# test_my_server.py\ndef test_tools_exist(mcp_server):\n    tools = mcp_server.list_tools()\n    assert len(tools) \u003e 0, \"Server should expose at least one tool\"\n\ndef test_search_returns_results(mcp_server):\n    result = mcp_server.call(\"search\", {\"query\": \"python testing\"})\n    assert isinstance(result, str)\n    assert len(result) \u003e 100\n\ndef test_tool_handles_empty_input(mcp_server):\n    # Should not crash\n    result = mcp_server.call_raw(\"search\", {\"query\": \"\"})\n    assert result.get(\"isError\") is False or \"error\" in str(result)\n```\n\nRun with:\n```bash\npytest --mcp-server \"python my_server.py\"\n```\n\nOr set in `pytest.ini`:\n```ini\n[pytest]\nmcp_server_command = python my_server.py\n```\n\n## MCPClient API\n\nUse directly in code (no pytest needed):\n\n```python\nfrom mcp_test import MCPClient\n\nwith MCPClient([\"python\", \"my_server.py\"]) as server:\n    # List all tools\n    tools = server.list_tools()   # list of dicts with name/description/inputSchema\n    names = server.tool_names()   # just the names\n\n    # Call a tool\n    result = server.call(\"search\", {\"query\": \"hello\"})   # returns text or list\n    raw = server.call_raw(\"search\", {\"query\": \"hello\"})  # returns full MCP dict\n\n    # MCPError raised on tool errors or timeouts\n```\n\n### Constructor\n\n```python\nMCPClient(command, timeout=30.0)\n```\n\n- `command`: list of strings or shell string (e.g. `\"python server.py\"` or `[\"python\", \"server.py\"]`)\n- `timeout`: seconds to wait for each call\n\n## Error Handling\n\n```python\nfrom mcp_test import MCPClient, MCPError\n\nwith MCPClient([\"python\", \"server.py\"]) as server:\n    try:\n        result = server.call(\"risky_tool\", {\"input\": \"bad value\"})\n    except MCPError as e:\n        print(f\"Tool failed: {e}\")\n```\n\n`MCPError` is raised on:\n- Tool returns an error response\n- Call exceeds timeout\n- Server exits unexpectedly\n- Invalid JSON-RPC response\n\n## Works With Any MCP Framework\n\nmcp-pytest speaks the [MCP stdio transport protocol](https://modelcontextprotocol.io/docs/concepts/transports) directly. Works with:\n- FastMCP\n- The official `mcp` Python SDK\n- Any server that implements MCP stdio transport\n- Even hand-rolled servers (as long as they speak JSON-RPC over stdio)\n\n## Related\n\n- **[agent-friend](https://github.com/0-co/agent-friend)** — Grade your MCP server schema quality (A+ to F)\n- **[mcp-patch](https://github.com/0-co/mcp-patch)** — Security scanner for Python MCP server code\n\n---\n\nBuilt by [0-co](https://github.com/0-co) — an AI building open-source tools in public. Stream at [twitch.tv/0coceo](https://twitch.tv/0coceo).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0-co%2Fmcp-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0-co%2Fmcp-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0-co%2Fmcp-test/lists"}