|
27 | 27 | _RECIPES = _BINDING.parent / "resources" / "mcp-recipes.yml" |
28 | 28 | _DIGESTS = _TESTS / "vectors" / "mcp-recipes.json" |
29 | 29 | # the Node.js twin pins the same digest: change the file in both packs or in neither |
30 | | -_DIGESTS_SHA256 = "10c70fe179d315cb0932d56cf0bc1e11290eb7c922ff439e5b9e7944df437d53" |
| 30 | +_DIGESTS_SHA256 = "844e729bc41e667892ecd5a6e864568b2c10d4785f0624864c91834074b47aac" |
31 | 31 |
|
32 | 32 | # the module name tests/test_mcp_binding.py loads the binding under: one process executes the |
33 | 33 | # module once, because a second execution would register mermaid.render again with a second function |
@@ -55,7 +55,7 @@ def _load_binding() -> Any: |
55 | 55 | DIGESTS: dict[str, Any] = json.loads(_DIGESTS.read_text(encoding="utf-8")) |
56 | 56 | LIVE = bool(os.environ.get("MCP_RECIPES_LIVE")) |
57 | 57 | RECIPE_SERVERS = ["fetch", "filesystem", "git", "github", "neo4j", "playwright", "time"] |
58 | | -# the servers that list their tools without a credential - the ones the page pins |
| 58 | +# the servers that list their tools without a credential; GitHub's hosted server lists with a token |
59 | 59 | CREDENTIAL_FREE = ["git", "time", "fetch", "filesystem", "playwright"] |
60 | 60 | # a credential the file references but these tests never send gets a placeholder, so the file |
61 | 61 | # loads; a real value already in the environment (the Neo4j run) is kept |
@@ -114,7 +114,8 @@ def test_the_references_resolve_from_the_environment(recipes: dict[str, Any]) -> |
114 | 114 |
|
115 | 115 | def test_every_pinned_server_has_a_recipe_and_tools(recipes: dict[str, Any]) -> None: |
116 | 116 | pinned = DIGESTS["servers"] |
117 | | - assert sorted(pinned) == sorted(CREDENTIAL_FREE + ["neo4j"]) |
| 117 | + assert sorted(pinned) == RECIPE_SERVERS |
| 118 | + assert set(pinned["github"]["read_only_tools"]) <= set(pinned["github"]["tools"]) |
118 | 119 | assert set(pinned) <= set(recipes) |
119 | 120 | for name, server in pinned.items(): |
120 | 121 | assert server["tools"], name |
@@ -163,3 +164,38 @@ async def test_live_neo4j_recipe_digests(recipes: dict[str, Any]) -> None: |
163 | 164 | assert not missing and not changed, ( |
164 | 165 | f"the neo4j recipe rotted - missing {missing}, changed {changed}" |
165 | 166 | ) |
| 167 | + |
| 168 | + |
| 169 | +# --- GitHub's hosted server, live with a token (gated) ----------------------------------------- |
| 170 | + |
| 171 | +GITHUB_LIVE = LIVE and bool(os.environ.get("GITHUB_MCP_TOKEN")) |
| 172 | +GITHUB_REASON = ( |
| 173 | + "set MCP_RECIPES_LIVE=1 and GITHUB_MCP_TOKEN (a fine-grained, read-only token) to list " |
| 174 | + "GitHub's hosted server" |
| 175 | +) |
| 176 | + |
| 177 | + |
| 178 | +@pytest.mark.skipif(not GITHUB_LIVE, reason=GITHUB_REASON) |
| 179 | +@pytest.mark.asyncio |
| 180 | +async def test_live_github_read_only_header_hides_every_write(recipes: dict[str, Any]) -> None: |
| 181 | + # the recipe's default, X-MCP-Readonly true: exactly the pinned read tools, with their digests |
| 182 | + actual = await offered_digests(recipes["github"]) |
| 183 | + pinned = DIGESTS["servers"]["github"] |
| 184 | + expected = {name: pinned["tools"][name] for name in pinned["read_only_tools"]} |
| 185 | + assert actual == expected, "the read-only listing differs from the pinned read tools" |
| 186 | + |
| 187 | + |
| 188 | +@pytest.mark.skipif(not GITHUB_LIVE, reason=GITHUB_REASON) |
| 189 | +@pytest.mark.asyncio |
| 190 | +async def test_live_github_recipe_digests( |
| 191 | + monkeypatch: pytest.MonkeyPatch, recipes: dict[str, Any] |
| 192 | +) -> None: |
| 193 | + # with the writes listed: every pinned tool offered, with its digest |
| 194 | + assert "github" in recipes |
| 195 | + monkeypatch.setenv("GITHUB_MCP_READONLY", "false") |
| 196 | + github = {spec.name: spec for spec in binding.load_servers(str(_RECIPES))}["github"] |
| 197 | + actual = await offered_digests(github) |
| 198 | + missing, changed = rot(actual, DIGESTS["servers"]["github"]["tools"]) |
| 199 | + assert not missing and not changed, ( |
| 200 | + f"the github recipe rotted - missing {missing}, changed {changed}" |
| 201 | + ) |
0 commit comments