diff --git a/src/mcp/server/fastmcp/server.py b/src/mcp/server/fastmcp/server.py index 55d5a3c..571c7c2 100644 --- a/src/mcp/server/fastmcp/server.py +++ b/src/mcp/server/fastmcp/server.py @@ -86,9 +86,11 @@ class Settings(BaseSettings): class FastMCP: - def __init__(self, name: str | None = None, **settings: Any): + def __init__( + self, name: str | None = None, instructions: str | None = None, **settings: Any + ): self.settings = Settings(**settings) - self._mcp_server = MCPServer(name=name or "FastMCP") + self._mcp_server = MCPServer(name=name or "FastMCP", instructions=instructions) self._tool_manager = ToolManager( warn_on_duplicate_tools=self.settings.warn_on_duplicate_tools ) @@ -110,6 +112,10 @@ def __init__(self, name: str | None = None, **settings: Any): def name(self) -> str: return self._mcp_server.name + @property + def instructions(self) -> str | None: + return self._mcp_server.instructions + def run(self, transport: Literal["stdio", "sse"] = "stdio") -> None: """Run the FastMCP server. Note this is a synchronous function. diff --git a/src/mcp/server/lowlevel/server.py b/src/mcp/server/lowlevel/server.py index 4c5dc04..32ea279 100644 --- a/src/mcp/server/lowlevel/server.py +++ b/src/mcp/server/lowlevel/server.py @@ -101,9 +101,12 @@ def __init__( class Server: - def __init__(self, name: str, version: str | None = None): + def __init__( + self, name: str, version: str | None = None, instructions: str | None = None + ): self.name = name self.version = version + self.instructions = instructions self.request_handlers: dict[ type, Callable[..., Awaitable[types.ServerResult]] ] = { @@ -139,6 +142,7 @@ def pkg_version(package: str) -> str: notification_options or NotificationOptions(), experimental_capabilities or {}, ), + instructions=self.instructions, ) def get_capabilities( diff --git a/src/mcp/server/models.py b/src/mcp/server/models.py index 377ed51..3b5abba 100644 --- a/src/mcp/server/models.py +++ b/src/mcp/server/models.py @@ -14,3 +14,4 @@ class InitializationOptions(BaseModel): server_name: str server_version: str capabilities: ServerCapabilities + instructions: str | None = None diff --git a/src/mcp/server/session.py b/src/mcp/server/session.py index 7a694c9..b71b372 100644 --- a/src/mcp/server/session.py +++ b/src/mcp/server/session.py @@ -135,6 +135,7 @@ async def _received_request( name=self._init_options.server_name, version=self._init_options.server_version, ), + instructions=self._init_options.instructions, ) ) ) diff --git a/tests/client/test_session.py b/tests/client/test_session.py index 7de0473..90de898 100644 --- a/tests/client/test_session.py +++ b/tests/client/test_session.py @@ -51,7 +51,7 @@ async def mock_server(): prompts=None, ), serverInfo=Implementation(name="mock-server", version="0.1.0"), - instructions="The server instructions." + instructions="The server instructions.", ) ) diff --git a/tests/server/fastmcp/test_server.py b/tests/server/fastmcp/test_server.py index f5d4214..6d64043 100644 --- a/tests/server/fastmcp/test_server.py +++ b/tests/server/fastmcp/test_server.py @@ -27,8 +27,9 @@ class TestServer: @pytest.mark.anyio async def test_create_server(self): - mcp = FastMCP() + mcp = FastMCP(instructions="Server instructions") assert mcp.name == "FastMCP" + assert mcp.instructions == "Server instructions" @pytest.mark.anyio async def test_non_ascii_description(self):