mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-19 20:14:17 +02:00
Add version parameter to FastMCP constructor
This commit is contained in:
parent
df78b2171d
commit
42121b2767
2 changed files with 25 additions and 0 deletions
|
|
@ -110,6 +110,7 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
def __init__(
|
||||
self,
|
||||
name: str | None = None,
|
||||
version: str | None = None,
|
||||
instructions: str | None = None,
|
||||
auth: OAuthProvider | None = None,
|
||||
lifespan: (
|
||||
|
|
@ -175,6 +176,7 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
self._has_lifespan = True
|
||||
self._mcp_server = MCPServer[LifespanResultT](
|
||||
name=name or "FastMCP",
|
||||
version=version,
|
||||
instructions=instructions,
|
||||
lifespan=_lifespan_wrapper(self, lifespan),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -321,6 +321,29 @@ async def test_initialize_result_disconnected(fastmcp_server):
|
|||
_ = client.initialize_result
|
||||
|
||||
|
||||
async def test_server_info_custom_version():
|
||||
"""Test that custom version is properly set in serverInfo."""
|
||||
# Test with custom version
|
||||
server_with_version = FastMCP("CustomVersionServer", version="1.2.3")
|
||||
client = Client(transport=FastMCPTransport(server_with_version))
|
||||
|
||||
async with client:
|
||||
result = client.initialize_result
|
||||
assert result.serverInfo.name == "CustomVersionServer"
|
||||
assert result.serverInfo.version == "1.2.3"
|
||||
|
||||
# Test without version (backward compatibility)
|
||||
server_without_version = FastMCP("DefaultVersionServer")
|
||||
client = Client(transport=FastMCPTransport(server_without_version))
|
||||
|
||||
async with client:
|
||||
result = client.initialize_result
|
||||
assert result.serverInfo.name == "DefaultVersionServer"
|
||||
# Should fall back to MCP library version
|
||||
assert result.serverInfo.version is not None
|
||||
assert result.serverInfo.version != "1.2.3" # Should be different from custom version
|
||||
|
||||
|
||||
async def test_client_nested_context_manager(fastmcp_server):
|
||||
"""Test that the client connects and disconnects once in nested context manager."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue