Skip to main content

pytest-mcp-contract

Pytest helpers for domain MCP tool contracts: registered names, annotations, and in-memory handler calls.

This is not protocol conformance. It does not wrap npx @modelcontextprotocol/conformance, does not ship security payloads, and does not run an LLM in CI.

Install

pip install pytest-mcp-contract

For in-memory registry access against the MCP Python SDK:

pip install "pytest-mcp-contract[mcp]"

The mcp extra pins the MCP Python SDK the same way swamp-ops does today: mcp[cli]>=2.0.0 (SDK 2.x MCPServer).

Develop from a git checkout:

pip install -e ".[mcp]"

Usage

Override the mcp_server fixture with your server object. The plugin lists names from the in-memory registry (no stdio subprocess).

import pytest
from mcp_contract.assert_mcp import assert_tools_named
from mcp_contract.session import list_tool_names

@pytest.fixture
def mcp_server():
    from swamp_ops.server import server
    return server

def test_tool_names(mcp_server):
    assert_tools_named(list_tool_names(mcp_server), {"swamp_estate_status", ...})

list_tool_names reads MCPServer._tool_manager._tools (or tool_manager._tools). That is the same private registry swamp-ops already inspects. If the shape is unknown, the helper fails instead of skipping — registry drift is what this plugin is for.

Calls go through the registered Tool.fn handler, not mcp.Client. v1 is in-memory only.

See also

Those cover protocol and transport. This plugin asserts your tool set.

License

Apache-2.0

Release files for pytest-mcp-contract 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-mcp-contract 0.1.1
File Size Uploaded
pytest_mcp_contract-0.1.1.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-mcp-contract 0.1.1
File Interpreter ABI Platform
pytest_mcp_contract-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / pytest_mcp_contract-0.1.1.tar.gz

Download URL pytest_mcp_contract-0.1.1.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f577de057741f6c3dad60af3764aede8d10632db02069029ec5d637f6710eb9b
BLAKE2b-256 checksum
How to use checksums
c30c24430c62235d27581b537cb6a574bb68646a24e508409638378e4c32738d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release files / pytest_mcp_contract-0.1.1-py3-none-any.whl

Download URL pytest_mcp_contract-0.1.1-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31d6ff4e134c84f31aa8c27b00b8a4cc295c4ecfc2dbf6133d493845c89bddfe
BLAKE2b-256 checksum
How to use checksums
c7846d1fb0bcd271eb79d9d78ea718e49c87b5684a32199d50a3dfe5f5af0710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page