Skip to content

Commit a1a8e86

Browse files
cliffhallclaude
andcommitted
fix(fetch,git,time): report the package version in serverInfo
Each Python server built Server("mcp-<name>") without a version, so the SDK filled serverInfo.version with its own `mcp` package version. Pass the distribution's version, read with importlib.metadata from the installed metadata that pyproject.toml produces, so the reported version tracks the published one (the same idea as the TypeScript servers' version.ts, which read package.json). Flip the three pinning tests to the correct behavior and drop their KNOWN BUG modelcontextprotocol#360 markers. Part of Wave 5 of modelcontextprotocol#5004. Closes modelcontextprotocol#360 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 142bb84 commit a1a8e86

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎src/mcp_server_fetch/server.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from typing import Annotated, Tuple
2+
from importlib.metadata import version
23
from urllib.parse import urlparse, urlunparse
34

45
import markdownify
@@ -20,6 +21,11 @@
2021
from protego import Protego
2122
from pydantic import BaseModel, Field, AnyUrl
2223

24+
# The version this server reports in serverInfo, read from the installed
25+
# distribution's metadata (pyproject.toml) so it cannot drift from the
26+
# published version (#360). Without it the SDK reports its own `mcp` version.
27+
SERVER_VERSION = version("mcp-server-fetch")
28+
2329
DEFAULT_USER_AGENT_AUTONOMOUS = "ModelContextProtocol/1.0 (Autonomous; +https://github.com/modelcontextprotocol/servers)"
2430
DEFAULT_USER_AGENT_MANUAL = "ModelContextProtocol/1.0 (User-Specified; +https://github.com/modelcontextprotocol/servers)"
2531

@@ -202,7 +208,7 @@ async def serve(
202208
ignore_robots_txt: Whether to ignore robots.txt restrictions
203209
proxy_url: Optional proxy URL to use for requests
204210
"""
205-
server = Server("mcp-fetch")
211+
server = Server("mcp-fetch", version=SERVER_VERSION)
206212
user_agent_autonomous = custom_user_agent or DEFAULT_USER_AGENT_AUTONOMOUS
207213
user_agent_manual = custom_user_agent or DEFAULT_USER_AGENT_MANUAL
208214

‎tests/test_protocol.py‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,13 @@ async def test_initialize_advertises_tools_and_prompts(web: FakeWeb) -> None:
9292
assert "resources" not in data["capabilities"]
9393

9494

95-
# KNOWN BUG #360: pins current (wrong) behavior; the fix changes this assertion.
96-
async def test_server_version_is_the_sdk_version(web: FakeWeb) -> None:
97-
# Characterizes #360: serverInfo.version is the `mcp` SDK's version, not
98-
# this package's, because Server("mcp-fetch") is given no version.
95+
async def test_server_version_is_the_package_version(web: FakeWeb) -> None:
96+
# #360: serverInfo.version is this package's version (from pyproject.toml
97+
# via the installed metadata), not the `mcp` SDK's.
9998
async with connect() as (_, init):
10099
data = wire(init)
101-
assert data["serverInfo"]["version"] == version("mcp")
102-
assert data["serverInfo"]["version"] != version("mcp-server-fetch")
100+
assert data["serverInfo"]["version"] == version("mcp-server-fetch")
101+
assert data["serverInfo"]["version"] != version("mcp")
103102

104103

105104
# --------------------------------------------------------------------------

0 commit comments

Comments
 (0)