π The fast, Pythonic way to build MCP servers and clients.
feat: Set instructions in code (#1838)
Peter Droogmans39a1e59bfd9a
diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.pyindex d0d749814..132589080 100644--- a/src/fastmcp/server/server.py+++ b/src/fastmcp/server/server.py@@ -329,6 +329,10 @@ class FastMCP(Generic[LifespanResultT]):def instructions(self) -> str | None:return self._mcp_server.instructions+ @instructions.setter+ def instructions(self, value: str | None) -> None:+ self._mcp_server.instructions = value+@propertydef version(self) -> str | None:return self._mcp_server.versiondiff --git a/tests/server/test_server.py b/tests/server/test_server.pyindex 715b8b1a9..af0b9dcd8 100644--- a/tests/server/test_server.py+++ b/tests/server/test_server.py@@ -35,6 +35,12 @@ class TestCreateServer:assert mcp.name.startswith("FastMCP-")assert mcp.instructions == "Server instructions"+ async def test_change_instruction(self):+ mcp = FastMCP(instructions="Server instructions")+ assert mcp.instructions == "Server instructions"+ mcp.instructions = "New instructions"+ assert mcp.instructions == "New instructions"+async def test_non_ascii_description(self):"""Test that FastMCP handles non-ASCII characters in descriptions correctly"""mcp = FastMCP()