File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11from typing import Annotated , Tuple
2+ from importlib .metadata import version
23from urllib .parse import urlparse , urlunparse
34
45import markdownify
2021from protego import Protego
2122from 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+
2329DEFAULT_USER_AGENT_AUTONOMOUS = "ModelContextProtocol/1.0 (Autonomous; +https://github.com/modelcontextprotocol/servers)"
2430DEFAULT_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
Original file line number Diff line number Diff 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# --------------------------------------------------------------------------
Original file line number Diff line number Diff line change 11import logging
2+ from importlib .metadata import version
23from pathlib import Path
34from typing import Any , Optional
45from mcp .server import Server
1314from git .exc import BadName
1415from pydantic import BaseModel , Field
1516
17+ # The version this server reports in serverInfo, read from the installed
18+ # distribution's metadata (pyproject.toml) so it cannot drift from the
19+ # published version (#360). Without it the SDK reports its own `mcp` version.
20+ SERVER_VERSION = version ("mcp-server-git" )
21+
1622# Default number of context lines to show in diff output
1723DEFAULT_CONTEXT_LINES = 3
1824
@@ -337,7 +343,7 @@ async def serve(repository: Path | None) -> None:
337343 logger .error (f"{ repository } is not a valid Git repository" )
338344 return
339345
340- server = Server ("mcp-git" )
346+ server = Server ("mcp-git" , version = SERVER_VERSION )
341347
342348 @server .list_tools ()
343349 async def list_tools () -> list [Tool ]:
Original file line number Diff line number Diff line change @@ -58,13 +58,15 @@ def staged_paths(repo: git.Repo) -> set[str]:
5858# --------------------------------------------------------------------------
5959
6060
61- # KNOWN BUG #360: pins current (wrong) behavior; the fix changes this assertion.
62- async def test_initialize_reports_sdk_version_as_server_version (repo : git .Repo ):
63- # Pins #360: serverInfo.version is the `mcp` SDK's version, not this
64- # package's, because serve() builds `Server("mcp-git")` without a version.
61+ async def test_initialize_reports_package_version_as_server_version (repo : git .Repo ):
62+ # #360: serverInfo.version is this package's version (from pyproject.toml
63+ # via the installed metadata), not the `mcp` SDK's.
6564 async with connect (root_of (repo ), initialize = False ) as session :
6665 init = wire (await session .initialize ())
67- assert init ["serverInfo" ] == {"name" : "mcp-git" , "version" : version ("mcp" )}
66+ assert init ["serverInfo" ] == {
67+ "name" : "mcp-git" ,
68+ "version" : version ("mcp-server-git" ),
69+ }
6870 assert version ("mcp" ) != version ("mcp-server-git" )
6971 assert init ["capabilities" ] == {
7072 "experimental" : {},
Original file line number Diff line number Diff line change 11from datetime import datetime , timedelta
2+ from importlib .metadata import version
23from enum import Enum
34import json
45from typing import Sequence
2122
2223from pydantic import BaseModel
2324
25+ # The version this server reports in serverInfo, read from the installed
26+ # distribution's metadata (pyproject.toml) so it cannot drift from the
27+ # published version (#360). Without it the SDK reports its own `mcp` version.
28+ SERVER_VERSION = version ("mcp-server-time" )
29+
2430
2531class TimeTools (str , Enum ):
2632 GET_CURRENT_TIME = "get_current_time"
@@ -131,7 +137,7 @@ def convert_time(
131137
132138
133139async def serve (local_timezone : str | None = None ) -> None :
134- server = Server ("mcp-time" )
140+ server = Server ("mcp-time" , version = SERVER_VERSION )
135141 time_server = TimeServer ()
136142 local_tz = str (get_local_tz (local_timezone ))
137143
Original file line number Diff line number Diff line change @@ -120,16 +120,17 @@ def handler_error(message: str) -> dict[str, Any]:
120120# ---------------------------------------------------------------------------
121121
122122
123- # KNOWN BUG #360: pins current (wrong) behavior; the fix changes this assertion.
124123async def test_initialize_reports_server_info_and_capabilities () -> None :
125124 async with serving ("UTC" ) as session :
126125 init = wire (await session .initialize ())
127126
128- # Characterizes #360: `Server("mcp-time")` is constructed without a
129- # version, so the SDK reports its OWN package version as the server's
130- # version, not mcp-server-time's. A fix will change this assertion.
131- assert init ["serverInfo" ] == {"name" : "mcp-time" , "version" : version ("mcp" )}
132- assert init ["serverInfo" ]["version" ] != version ("mcp-server-time" )
127+ # #360: serverInfo.version is mcp-server-time's own version (from
128+ # pyproject.toml via the installed metadata), not the `mcp` SDK's.
129+ assert init ["serverInfo" ] == {
130+ "name" : "mcp-time" ,
131+ "version" : version ("mcp-server-time" ),
132+ }
133+ assert init ["serverInfo" ]["version" ] != version ("mcp" )
133134 # Only tools are advertised; no resources, prompts or logging.
134135 assert init ["capabilities" ] == {"experimental" : {}, "tools" : {"listChanged" : False }}
135136 assert "instructions" not in init
You can’t perform that action at this time.
0 commit comments