Skip to content

test(mcp): name and split the MCP tests by behaviour #3765

Closed

Description

@dan-petty

Problem or Motivation

Part of #1330. The MCP test files are named after libraries, or hold several behaviours in one file. A failing file does not say which behaviour broke. The tool listing that clients see has no snapshot, so a change to a tool name, description or input schema passes unseen.

Measured at origin/main 29309f0:

File Lines Tests Problem
tests/ai/mcp/test_fastmcp_contracts.py 1,686 61 Six behaviours in one file: registry, prompts and resources, argv of tools, dispatch logging, domain hydration, argument refusal
tests/ai/mcp/test_mcp.py 851 27 Tool exposure table, scan tools, server start, CLI and a catch-all
tests/ai/mcp/test_fastmcp_in_process.py 300 14 Named after FastMCP, tests the dispatcher
tests/ai/agents/test_pydantic_ai_toolsets.py 342 13 Named after the library. One class TestPydanticAIToolsetsSubsystem
tests/ai/tools/test_pydantic_ai_tools.py 134 5 Named after the library. One class TestPydanticAIToolsSubsystem

The tool listing: 145 tools are registered. The listing as JSON (name, description, input schema, sorted by name) is 124,234 characters when compact. It is 181,944 characters with two-space indentation, the form of a syrupy JSON snapshot. It is the same in two processes and with another HOME. It holds no absolute path. I checked this at 4a2d958 and re-ran the count of 145 tools at 29309f0.

Left out on purpose. These files are not in this child.

Proposed Solution & Architectural Design

Blocked by child B, which edits the MCP files heavily. Move code, keep test names, and keep each test body unchanged unless a rule below says otherwise. A reviewer then sees pure moves.

Proposed split. The implementer may adjust the names. Each name states a behaviour.

  • test_fastmcp_contracts.py becomes test_mcp_tool_registry.py (registration, docstrings, annotations, mutating floor, published schemas, roadmap registration), test_mcp_prompts_and_resources.py, test_mcp_tool_argv.py (the argv each tool builds), test_mcp_dispatch_logging.py, test_mcp_domain_hydration.py and test_mcp_argument_refusal.py.
  • test_mcp.py becomes test_mcp_exposure_table.py (test_all_cli_commands_are_either_exposed_or_excluded), test_mcp_scan_tools.py (the semgrep and uv audit tools), test_mcp_run_command.py (the cases of _run_mcp_cmd from child B) and test_mcp_server_start.py. What remains moves to the files above. Child B already moved the CLI cases to tests/commands/test_mcp_serve.py.
  • test_fastmcp_in_process.py becomes test_mcp_dispatcher.py. The contract suite of child B stays in test_dispatcher_contract.py.
  • test_pydantic_ai_toolsets.py becomes test_agent_toolsets.py, and test_pydantic_ai_tools.py becomes test_agent_tools.py. The two library-named classes become plain test functions.

The snapshot. Add tests/ai/mcp/test_mcp_tool_listing.py. It reads the registered tools from the server with await mcp.list_tools(run_middleware=False). The test sorts the tools by name. It compares name, description and the input schema with one syrupy snapshot. Use syrupy's JSONSnapshotExtension, so a diff reads line by line. The snapshot is one file under tests/ai/mcp/__snapshots__/ of about 180 KB. If the owner prefers a smaller diff per review, split it by domain. I ran the listing in a scratch script. I did not write the snapshot test.

Acceptance criteria

  • None of the five files above exists under its old name. ls tests/ai/mcp/test_fastmcp_*.py tests/ai/mcp/test_mcp.py tests/ai/agents/test_pydantic_ai_toolsets.py tests/ai/tools/test_pydantic_ai_tools.py lists no file.
  • No test file that this child creates is longer than 600 lines.
  • No test class or test function in the new files has PydanticAI or pydantic_ai in its name.
  • The set of test names before and after is the same. The pull request body lists each exception as renamed, deleted with the reason, or new. A script in the pull request comment shows the diff of the two sets.
  • The snapshot test passes. It fails when a test adds a parameter to one tool, and it passes again when the snapshot is updated with --snapshot-update. The pull request body shows both runs.
  • The snapshot has 145 tools at the base commit, sorted by name. Two runs in two processes give identical files.
  • No new patch of a devops_cli name and no private import enters any moved file.
  • uv run devops ci passes. Coverage does not fall. The pull request body gives the counts of test files and tests before and after.

Target Subsystem

tests/ai/mcp/, tests/ai/agents/test_pydantic_ai_toolsets.py, tests/ai/tools/. No change in src.

Existing Tool Considered

syrupy (https://github.com/syrupy-project/syrupy, pinned 6.1.1 in pyproject.toml) with its JSONSnapshotExtension. The repository already uses syrupy, for example for tests/ci/__snapshots__/test_fail_to_pass.ambr. FastMCP's own list_tools supplies the listing. Nothing is built.

Activity

  1. added
    source/agent
    type/test
    scope/mcp
    status/new
    value/medium
    effort/medium
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/test. The test prefix of the title gives the type.
    • Scope: scope/mcp. The (mcp) scope of the title gives the scope.
    • Priority: P2-Medium. It improves test clarity and adds a snapshot, but it is blocked by another child and is not urgent.
    • Value: Medium. A failing file will name the broken behaviour, and the snapshot catches unseen tool listing changes.
    • Effort: Medium. Five files split into roughly twelve, plus one new snapshot test; bodies stay unchanged.
    • Related: test(roadmap): the four largest roadmap test files split by behaviour #3748, which asks for a different change. Both split test files by behaviour, but #3748 works on roadmap tests and this candidate works on MCP tests.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    status/in-progress
    and removed
    status/new
    on Nov 7, 2026
  5. added
    status/in-review
    and removed
    status/in-progress
    on Nov 7, 2026
  6. removed
    status/in-review
    on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/mcpsource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions