Skip to content

Commit 0c2e0bc

Browse files
committed
Updating initialization and Implementation to match specs update (add title and description)
1 parent 4afc49e commit 0c2e0bc

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ class FastMCP(Generic[LifespanResultT]):
143143
def __init__( # noqa: PLR0913
144144
self,
145145
name: str | None = None,
146+
title: str | None = None,
147+
description: str | None = None,
146148
instructions: str | None = None,
147149
website_url: str | None = None,
148150
icons: list[Icon] | None = None,
@@ -192,6 +194,8 @@ def __init__( # noqa: PLR0913
192194

193195
self._mcp_server = MCPServer(
194196
name=name or "FastMCP",
197+
title=title,
198+
description=description,
195199
instructions=instructions,
196200
website_url=website_url,
197201
icons=icons,
@@ -233,6 +237,14 @@ def __init__( # noqa: PLR0913
233237
def name(self) -> str:
234238
return self._mcp_server.name
235239

240+
@property
241+
def title(self) -> str | None:
242+
return self._mcp_server.title
243+
244+
@property
245+
def description(self) -> str | None:
246+
return self._mcp_server.description
247+
236248
@property
237249
def instructions(self) -> str | None:
238250
return self._mcp_server.instructions

src/mcp/server/lowlevel/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ def __init__(
135135
self,
136136
name: str,
137137
version: str | None = None,
138+
title: str | None = None,
139+
description: str | None = None,
138140
instructions: str | None = None,
139141
website_url: str | None = None,
140142
icons: list[types.Icon] | None = None,
@@ -145,6 +147,8 @@ def __init__(
145147
):
146148
self.name = name
147149
self.version = version
150+
self.title = title
151+
self.description = description
148152
self.instructions = instructions
149153
self.website_url = website_url
150154
self.icons = icons
@@ -176,6 +180,8 @@ def pkg_version(package: str) -> str:
176180
return InitializationOptions(
177181
server_name=self.name,
178182
server_version=self.version if self.version else pkg_version("mcp"),
183+
title=self.title,
184+
description=self.description,
179185
capabilities=self.get_capabilities(
180186
notification_options or NotificationOptions(),
181187
experimental_capabilities or {},

src/mcp/server/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
class InitializationOptions(BaseModel):
1515
server_name: str
1616
server_version: str
17+
title: str | None = None
18+
description: str | None = None
1719
capabilities: ServerCapabilities
1820
instructions: str | None = None
1921
website_url: str | None = None

src/mcp/server/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ async def _received_request(self, responder: RequestResponder[types.ClientReques
155155
capabilities=self._init_options.capabilities,
156156
serverInfo=types.Implementation(
157157
name=self._init_options.server_name,
158+
title=self._init_options.title,
159+
description=self._init_options.description,
158160
version=self._init_options.server_version,
159161
websiteUrl=self._init_options.website_url,
160162
icons=self._init_options.icons,

src/mcp/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ class Implementation(BaseMetadata):
233233

234234
version: str
235235

236+
title: str | None = None
237+
"""An optional human-readable title for this implementation."""
238+
239+
description: str | None = None
240+
"""An optional human-readable description of what this implementation does."""
241+
236242
websiteUrl: str | None = None
237243
"""An optional URL of the website for this implementation."""
238244

tests/server/fastmcp/test_server.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ class TestServer:
3535
@pytest.mark.anyio
3636
async def test_create_server(self):
3737
mcp = FastMCP(
38+
title="FastMCP Server",
39+
description="Server description",
3840
instructions="Server instructions",
3941
website_url="https://example.com/mcp_server",
4042
version="1.0",
4143
icons=[Icon(src="https://example.com/icon.png", mimeType="image/png", sizes=["48x48", "96x96"])],
4244
)
4345
assert mcp.name == "FastMCP"
46+
assert mcp.title == "FastMCP Server"
47+
assert mcp.description == "Server description"
4448
assert mcp.instructions == "Server instructions"
4549
assert mcp.website_url == "https://example.com/mcp_server"
4650
assert mcp.version == "1.0"

tests/server/fastmcp/test_title.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@
1010
from mcp.types import Prompt, Resource, ResourceTemplate, Tool, ToolAnnotations
1111

1212

13+
@pytest.mark.anyio
14+
async def test_server_name_title_description_version():
15+
"""Test that server title and description are set and retrievable correctly."""
16+
mcp = FastMCP(
17+
name="TestServer",
18+
title="Test Server Title",
19+
description="This is a test server description.",
20+
version="1.0",
21+
)
22+
23+
assert mcp.title == "Test Server Title"
24+
assert mcp.description == "This is a test server description."
25+
assert mcp.version == "1.0"
26+
27+
# Start server and connect client
28+
async with create_connected_server_and_client_session(mcp._mcp_server) as client:
29+
init_result = await client.initialize()
30+
assert init_result.serverInfo.name == "TestServer"
31+
assert init_result.serverInfo.title == "Test Server Title"
32+
assert init_result.serverInfo.description == "This is a test server description."
33+
assert init_result.serverInfo.version == "1.0"
34+
35+
1336
@pytest.mark.anyio
1437
async def test_tool_title_precedence():
1538
"""Test that tool title precedence works correctly: title > annotations.title > name."""

0 commit comments

Comments
 (0)