mcp-page-probe 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_page_probe-0.1.0/.github/workflows/release.yml +40 -0
- mcp_page_probe-0.1.0/.gitignore +7 -0
- mcp_page_probe-0.1.0/LICENSE +21 -0
- mcp_page_probe-0.1.0/PKG-INFO +46 -0
- mcp_page_probe-0.1.0/README.md +34 -0
- mcp_page_probe-0.1.0/examples/client_registries.py +41 -0
- mcp_page_probe-0.1.0/pyproject.toml +24 -0
- mcp_page_probe-0.1.0/src/mcp_page_probe/__init__.py +61 -0
- mcp_page_probe-0.1.0/src/mcp_page_probe/cli.py +22 -0
- mcp_page_probe-0.1.0/src/mcp_page_probe/server.py +30 -0
- mcp_page_probe-0.1.0/tests/test_probe.py +13 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.13"
|
|
18
|
+
- run: python -m pip install build
|
|
19
|
+
- run: python -m pip install . pytest
|
|
20
|
+
- run: python -m pytest -q
|
|
21
|
+
- run: python -m build
|
|
22
|
+
- uses: actions/upload-artifact@v4
|
|
23
|
+
with:
|
|
24
|
+
name: dist
|
|
25
|
+
path: dist/
|
|
26
|
+
|
|
27
|
+
publish:
|
|
28
|
+
needs: build
|
|
29
|
+
runs-on: ubuntu-latest
|
|
30
|
+
environment:
|
|
31
|
+
name: pypi
|
|
32
|
+
url: https://pypi.org/project/mcp-page-probe/
|
|
33
|
+
permissions:
|
|
34
|
+
id-token: write
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/download-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: dist
|
|
39
|
+
path: dist/
|
|
40
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rion Hwang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: mcp-page-probe
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Test MCP client discovery and invocation of tools beyond the first page.
|
|
5
|
+
Project-URL: Repository, https://github.com/RionHwang0/mcp-page-probe
|
|
6
|
+
Author: Rion Hwang
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: mcp<3,>=2.3
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# mcp-page-probe
|
|
14
|
+
|
|
15
|
+
A local MCP server fixture and a pair of assertions for agent clients that discover tools across multiple pages. The second tool has to be visible and callable.
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pip install mcp-page-probe
|
|
19
|
+
mcp-page-probe check
|
|
20
|
+
mcp-page-probe check --empty-middle
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To test an application, configure its normal stdio transport with the command `mcp-page-probe serve --empty-middle`. In the application's test suite, pass its actual discovery and invocation adapters:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
from mcp_page_probe import assert_discovery
|
|
27
|
+
# list_names() returns the tool names exposed to the agent.
|
|
28
|
+
# invoke(name, args) dispatches through the application and returns its text result.
|
|
29
|
+
result = await assert_discovery(list_names, invoke)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The fixture serves `probe_first`, then optionally an empty list with a continuation cursor, then `probe_later`. The assertions reject absent and duplicate names, invoke the later tool with a unique argument and check its reply. If the application namespaces tools, remove its server prefix in the adapters. The built-in check runs the Python SDK client over a real subprocess. Client discovery behavior is specific to the application adapter.
|
|
33
|
+
|
|
34
|
+
[Protocol pagination](https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/pagination)
|
|
35
|
+
|
|
36
|
+
## Exercise two client registries
|
|
37
|
+
|
|
38
|
+
The [client example](examples/client_registries.py) exercises the Hugging Face Hub MCP client (1.33.0) and LangChain MCP adapters (0.3.2). Both exposed the two names across an empty middle page and returned the expected unique response from the later tool. Run from a source checkout with the fixture installed in a separate environment. The example reads the assertions from the checkout so each client can use its supported SDK version.
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
python -m venv fixture-env
|
|
42
|
+
fixture-env/bin/pip install .
|
|
43
|
+
python -m venv clients-env
|
|
44
|
+
clients-env/bin/pip install 'huggingface-hub==1.33.0' 'langchain-mcp-adapters==0.3.2' 'mcp>=1.20,<2'
|
|
45
|
+
PYTHONPATH=src clients-env/bin/python examples/client_registries.py "$PWD/fixture-env/bin/mcp-page-probe"
|
|
46
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# mcp-page-probe
|
|
2
|
+
|
|
3
|
+
A local MCP server fixture and a pair of assertions for agent clients that discover tools across multiple pages. The second tool has to be visible and callable.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pip install mcp-page-probe
|
|
7
|
+
mcp-page-probe check
|
|
8
|
+
mcp-page-probe check --empty-middle
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
To test an application, configure its normal stdio transport with the command `mcp-page-probe serve --empty-middle`. In the application's test suite, pass its actual discovery and invocation adapters:
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from mcp_page_probe import assert_discovery
|
|
15
|
+
# list_names() returns the tool names exposed to the agent.
|
|
16
|
+
# invoke(name, args) dispatches through the application and returns its text result.
|
|
17
|
+
result = await assert_discovery(list_names, invoke)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The fixture serves `probe_first`, then optionally an empty list with a continuation cursor, then `probe_later`. The assertions reject absent and duplicate names, invoke the later tool with a unique argument and check its reply. If the application namespaces tools, remove its server prefix in the adapters. The built-in check runs the Python SDK client over a real subprocess. Client discovery behavior is specific to the application adapter.
|
|
21
|
+
|
|
22
|
+
[Protocol pagination](https://modelcontextprotocol.io/specification/2025-11-25/server/utilities/pagination)
|
|
23
|
+
|
|
24
|
+
## Exercise two client registries
|
|
25
|
+
|
|
26
|
+
The [client example](examples/client_registries.py) exercises the Hugging Face Hub MCP client (1.33.0) and LangChain MCP adapters (0.3.2). Both exposed the two names across an empty middle page and returned the expected unique response from the later tool. Run from a source checkout with the fixture installed in a separate environment. The example reads the assertions from the checkout so each client can use its supported SDK version.
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
python -m venv fixture-env
|
|
30
|
+
fixture-env/bin/pip install .
|
|
31
|
+
python -m venv clients-env
|
|
32
|
+
clients-env/bin/pip install 'huggingface-hub==1.33.0' 'langchain-mcp-adapters==0.3.2' 'mcp>=1.20,<2'
|
|
33
|
+
PYTHONPATH=src clients-env/bin/python examples/client_registries.py "$PWD/fixture-env/bin/mcp-page-probe"
|
|
34
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Probe two installed client registries against the separately installed fixture command."""
|
|
2
|
+
import argparse
|
|
3
|
+
import asyncio
|
|
4
|
+
|
|
5
|
+
from huggingface_hub.inference._mcp.mcp_client import MCPClient
|
|
6
|
+
from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
7
|
+
|
|
8
|
+
from mcp_page_probe import assert_discovery
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def run(command):
|
|
12
|
+
args = ["serve", "--empty-middle"]
|
|
13
|
+
async with MCPClient(model="local-probe") as client:
|
|
14
|
+
await client.add_mcp_server("stdio", command=command, args=args)
|
|
15
|
+
|
|
16
|
+
async def hf_names():
|
|
17
|
+
return [tool.function.name for tool in client.available_tools]
|
|
18
|
+
|
|
19
|
+
async def hf_invoke(name, arguments):
|
|
20
|
+
response = await client.sessions[name].call_tool(name, arguments)
|
|
21
|
+
return response.content[0].text
|
|
22
|
+
|
|
23
|
+
print("Hugging Face", await assert_discovery(hf_names, hf_invoke))
|
|
24
|
+
|
|
25
|
+
adapter = MultiServerMCPClient({"probe": {"transport":"stdio", "command":command, "args":args}})
|
|
26
|
+
tools = await adapter.get_tools()
|
|
27
|
+
async def lc_names():
|
|
28
|
+
return [tool.name for tool in tools]
|
|
29
|
+
|
|
30
|
+
async def lc_invoke(name, arguments):
|
|
31
|
+
tool = next(t for t in tools if t.name == name)
|
|
32
|
+
result = await tool.ainvoke(arguments)
|
|
33
|
+
return result if isinstance(result, str) else result[0]["text"]
|
|
34
|
+
|
|
35
|
+
print("LangChain", await assert_discovery(lc_names, lc_invoke))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
40
|
+
parser.add_argument("fixture_command", help="Absolute path to server environment's mcp-page-probe")
|
|
41
|
+
asyncio.run(run(parser.parse_args().fixture_command))
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mcp-page-probe"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Test MCP client discovery and invocation of tools beyond the first page."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{name = "Rion Hwang"}]
|
|
14
|
+
dependencies = ["mcp>=2.3,<3"]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
[project.scripts]
|
|
18
|
+
mcp-page-probe = "mcp_page_probe.cli:main"
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Repository = "https://github.com/RionHwang0/mcp-page-probe"
|
|
22
|
+
|
|
23
|
+
[tool.hatch.build.targets.wheel]
|
|
24
|
+
packages = ["src/mcp_page_probe"]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Black-box assertions for discovery and invocation from a client's tool registry."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from uuid import uuid4
|
|
7
|
+
|
|
8
|
+
FIRST = "probe_first"
|
|
9
|
+
LAST = "probe_later"
|
|
10
|
+
PREFIX = "mcp-page-probe:"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def fixture_command(empty_middle=False):
|
|
14
|
+
args = ["-m", "mcp_page_probe.cli", "serve"]
|
|
15
|
+
return [sys.executable, *args, *(["--empty-middle"] if empty_middle else [])]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class ProbeResult:
|
|
20
|
+
tools: tuple[str, ...]
|
|
21
|
+
called: str
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
async def assert_discovery(list_names, invoke):
|
|
25
|
+
"""list_names() returns app-visible names; invoke(name, args) returns text."""
|
|
26
|
+
names = tuple(await list_names())
|
|
27
|
+
for name in (FIRST, LAST):
|
|
28
|
+
if names.count(name) != 1:
|
|
29
|
+
raise AssertionError(f"Expected exactly one {name!r} in discovered tools: {names}")
|
|
30
|
+
nonce = uuid4().hex
|
|
31
|
+
reply = await invoke(LAST, {"nonce": nonce})
|
|
32
|
+
if reply != PREFIX + nonce:
|
|
33
|
+
raise AssertionError("Later-page tool did not return its expected response")
|
|
34
|
+
return ProbeResult(names, LAST)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def check_sdk(empty_middle=False):
|
|
38
|
+
from mcp import Client
|
|
39
|
+
from mcp.client.stdio import StdioServerParameters
|
|
40
|
+
command, *args = fixture_command(empty_middle)
|
|
41
|
+
async with Client(StdioServerParameters(command=command, args=args)) as client:
|
|
42
|
+
async def discover():
|
|
43
|
+
names, cursors = [], set()
|
|
44
|
+
cursor = None
|
|
45
|
+
while True:
|
|
46
|
+
page = await client.list_tools(cursor=cursor)
|
|
47
|
+
names.extend(t.name for t in page.tools)
|
|
48
|
+
cursor = page.next_cursor
|
|
49
|
+
if cursor is None:
|
|
50
|
+
return names
|
|
51
|
+
if cursor in cursors:
|
|
52
|
+
raise AssertionError("Server repeated a cursor")
|
|
53
|
+
cursors.add(cursor)
|
|
54
|
+
|
|
55
|
+
async def invoke(name, params):
|
|
56
|
+
result = await client.call_tool(name, params)
|
|
57
|
+
if result.is_error:
|
|
58
|
+
raise AssertionError(str(result.content))
|
|
59
|
+
return result.content[0].text
|
|
60
|
+
|
|
61
|
+
return await assert_discovery(discover, invoke)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import asyncio
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import asdict
|
|
5
|
+
|
|
6
|
+
from . import check_sdk
|
|
7
|
+
from .server import serve
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
parser = argparse.ArgumentParser(description="Test MCP discovery across tool list pages.")
|
|
12
|
+
parser.add_argument("action", choices=["serve", "check"])
|
|
13
|
+
parser.add_argument("--empty-middle", action="store_true", help="Add an empty page with a nonempty cursor")
|
|
14
|
+
args = parser.parse_args()
|
|
15
|
+
if args.action == "serve":
|
|
16
|
+
asyncio.run(serve(args.empty_middle))
|
|
17
|
+
else:
|
|
18
|
+
print(json.dumps(asdict(asyncio.run(check_sdk(args.empty_middle)))))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
main()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from mcp import types
|
|
2
|
+
from mcp.server.lowlevel import Server
|
|
3
|
+
from mcp.server.stdio import stdio_server
|
|
4
|
+
|
|
5
|
+
from . import FIRST, LAST, PREFIX
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def serve(empty_middle=False):
|
|
9
|
+
schema = {"type":"object", "properties":{"nonce":{"type":"string"}}, "required":["nonce"],
|
|
10
|
+
"additionalProperties":False}
|
|
11
|
+
async def listing(ctx, params):
|
|
12
|
+
cursor = getattr(params, "cursor", None)
|
|
13
|
+
if cursor is None:
|
|
14
|
+
return types.ListToolsResult(
|
|
15
|
+
tools=[types.Tool(name=FIRST, inputSchema=schema)], nextCursor="middle" if empty_middle else "last")
|
|
16
|
+
if empty_middle and cursor == "middle":
|
|
17
|
+
return types.ListToolsResult(tools=[], nextCursor="last")
|
|
18
|
+
if cursor == "last":
|
|
19
|
+
return types.ListToolsResult(tools=[types.Tool(name=LAST, inputSchema=schema)])
|
|
20
|
+
raise ValueError("Unknown fixture cursor")
|
|
21
|
+
|
|
22
|
+
async def call(ctx, params):
|
|
23
|
+
args = params.arguments or {}
|
|
24
|
+
if params.name not in (LAST, FIRST) or not isinstance(args.get("nonce"), str):
|
|
25
|
+
return types.CallToolResult(isError=True, content=[types.TextContent(type="text", text="Invalid call")])
|
|
26
|
+
return types.CallToolResult(content=[types.TextContent(type="text", text=PREFIX + args["nonce"])])
|
|
27
|
+
|
|
28
|
+
server = Server("mcp-page-probe", on_list_tools=listing, on_call_tool=call)
|
|
29
|
+
async with stdio_server() as (reader, writer):
|
|
30
|
+
await server.run(reader, writer, server.create_initialization_options())
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import pytest
|
|
3
|
+
from mcp_page_probe import FIRST, assert_discovery, check_sdk
|
|
4
|
+
|
|
5
|
+
@pytest.mark.parametrize("empty", [True, False])
|
|
6
|
+
def test_stdio(empty):
|
|
7
|
+
assert asyncio.run(check_sdk(empty)).called == "probe_later"
|
|
8
|
+
|
|
9
|
+
def test_reject_first_page_only():
|
|
10
|
+
async def listing():
|
|
11
|
+
return [FIRST]
|
|
12
|
+
with pytest.raises(AssertionError, match="probe_later"):
|
|
13
|
+
asyncio.run(assert_discovery(listing, None))
|