mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 22:16:23 +00:00
MCP: Pass initial instructions to fastmcp constructor
This commit is contained in:
1 parent
0aaeaef64c
commit
770e3658eb
1 file changed
+11
-1
+11
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user