diff --git a/src/serena/mcp.py b/src/serena/mcp.py index ff8a11ba..f5f785e0 100644 --- a/src/serena/mcp.py +++ b/src/serena/mcp.py @@ -172,7 +172,8 @@ class SerenaMCPFactory: Settings.model_config = SettingsConfigDict(env_prefix="FASTMCP_") mcp_settings: Settings = Settings(lifespan=self.server_lifespan, host=host, port=port) - mcp = FastMCP(**mcp_settings.model_dump()) + instructions = self._get_initial_instructions() + mcp = FastMCP(**mcp_settings.model_dump(), instructions=instructions) return mcp @asynccontextmanager @@ -181,6 +182,10 @@ class SerenaMCPFactory: """Manage server startup and shutdown lifecycle.""" yield None # ensures MyPy understands we yield None + @abstractmethod + def _get_initial_instructions(self) -> str: + pass + class SerenaMCPFactorySingleProcess(SerenaMCPFactory): """ @@ -207,6 +212,11 @@ class SerenaMCPFactorySingleProcess(SerenaMCPFactory): assert self.agent is not None yield from self.agent.get_exposed_tool_instances() + def _get_initial_instructions(self) -> str: + assert self.agent is not None + # we don't use the tool (which at the time of writing calls this method), since the tool may be disabled by the config + return self.agent.create_system_prompt() + @asynccontextmanager async def server_lifespan(self, mcp_server: FastMCP) -> AsyncIterator[None]: self._set_mcp_tools(mcp_server)