Skip to content

Commit dabe327

Browse files
authored
show_server_info
1 parent c897868 commit dabe327

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
6565

6666
# Server settings
6767
debug: bool = False
68-
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "ERROR"
68+
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = "INFO"
6969

7070
# HTTP settings
7171
host: str = "0.0.0.0"
@@ -140,7 +140,7 @@ def name(self) -> str:
140140
def instructions(self) -> str | None:
141141
return self._mcp_server.instructions
142142

143-
def run(self, transport: Literal["stdio", "sse"] = "stdio") -> None:
143+
def run(self, transport: Literal["stdio", "sse"] = "stdio", show_server_info = True) -> None:
144144
"""Run the FastMCP server. Note this is a synchronous function.
145145
146146
Args:
@@ -150,10 +150,29 @@ def run(self, transport: Literal["stdio", "sse"] = "stdio") -> None:
150150
if transport not in TRANSPORTS.__args__: # type: ignore
151151
raise ValueError(f"Unknown transport: {transport}")
152152

153+
run = lambda: self._run(transport, show_server_info)
154+
anyio.run(run)
155+
156+
async def _run(transport: Literal["stdio", "sse"], show_server_info: bool = True):
157+
logger.info(f"Server name: {mcp.name}")
158+
logger.info(f"Server: {mcp.settings.host}:{mcp.settings.port}")
159+
assets = {
160+
'tools': await mcp.list_tools(),
161+
'resources': await mcp.list_resources(),
162+
'prompts': await mcp.list_prompts(),
163+
'resource_templates': await mcp.list_resource_templates()
164+
}
165+
for asset_type, asset_list in assets.items():
166+
if not asset_list:
167+
continue
168+
logger.info(f"{asset_type}:")
169+
for asset in asset_list:
170+
logger.info(f" - {asset.name} - {asset.description}")
171+
logger.info("Server running...")
153172
if transport == "stdio":
154-
anyio.run(self.run_stdio_async)
173+
await self.run_stdio_async()
155174
else: # transport == "sse"
156-
anyio.run(self.run_sse_async)
175+
await self.run_sse_async()
157176

158177
def _setup_handlers(self) -> None:
159178
"""Set up core MCP protocol handlers."""

0 commit comments

Comments
 (0)