test: add MCP protocol smoke test for the stdio transport#133
Open
yagna-1 wants to merge 1 commit into
Open
Conversation
Adds tests/test_mcp_protocol.py with two end-to-end tests that spawn
`excel-mcp-server stdio` as a real subprocess and exercise the JSON-RPC
protocol over stdin/stdout:
- test_initialize_handshake_succeeds: server completes the MCP
initialize handshake and advertises the `tools` capability.
- test_documented_tools_are_listed: `create_workbook` and
`get_workbook_metadata` (both in TOOLS.md) are returned by tools/list
with valid object input schemas.
Why: the existing `test_sandbox_paths.py` exercises path-resolution
internals directly, but nothing currently runs the actual MCP entry
point. A regression in `__main__.py`, the FastMCP wiring in
`server.py`, or the handshake sequencing could ship without any test
failing. These two tests close that gap.
Implementation:
- Single new file, ~100 LoC, follows the existing unittest style of
`test_sandbox_paths.py`.
- Skipped automatically when `pytest-mcp-plugin` is not installed or
the `excel-mcp-server` entry point is not on PATH, so the suite stays
green in any environment.
- No production code changes, no dev-deps in pyproject.toml, no new
workflows. Maintainer can decide whether to wire it in.
To run locally:
uv add --dev "pytest-mcp-plugin>=0.2.3"
uv run pytest tests/test_mcp_protocol.py -v
Co-authored-by: Cursor <cursoragent@cursor.com>
Author
|
Heads-up: For context, v0.3.0 also runs Anthropic's |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds two end-to-end tests in
tests/test_mcp_protocol.pythat spawnexcel-mcp-server stdioas a real subprocess and exercise the JSON-RPC protocol over its stdin/stdout:test_initialize_handshake_succeeds— the server completes the MCPinitializehandshake and advertises thetoolscapability.test_documented_tools_are_listed—create_workbookandget_workbook_metadata(both inTOOLS.md) are returned bytools/listwith valid object input schemas.Why
The existing
test_sandbox_paths.pyexercises path-resolution internals directly, but nothing currently runs the actual MCP entry point. A regression in__main__.py, the FastMCP wiring inserver.py, or the handshake sequencing could ship without any test failing. These two tests close that gap.Implementation
unitteststyle oftest_sandbox_paths.py.pytest-mcp-pluginis not installed orexcel-mcp-serveris not on PATH, so the suite stays green in any environment, including the currentpublish.ymlworkflow which doesn't install dev deps.pyproject.tomldeps changes, no workflow changes. You decide whether to wire it in.To run locally:
```sh
uv add --dev "pytest-mcp-plugin>=0.2.3"
uv sync
uv run pytest tests/test_mcp_protocol.py -v
```
Verified locally
```text
$ uv run pytest tests/ -q
....... [100%]
7 passed in 0.97s
```
That's 5 existing + 2 new. Server runs in stdio mode — no Excel files touched.
Disclosure
I'm the author of
pytest-mcp-plugin(MIT, on PyPI). It's a small community library that drives MCP servers over stdio/HTTP from inside the test runner — Apache/MIT-compatible, not a vendored dependency. Repo: https://github.com/yagna-1/mcp-test.While testing this PR I caught and fixed a bug in
pytest-mcp-pluginitself: the client wasn't sendingnotifications/initializedafter the MCPinitializehandshake, which FastMCP requires before it will return tools fromtools/list. That fix shipped as v0.2.3 (May 5). The pin in this PR is>=0.2.3so users get the working version.Made with Cursor