Skip to content

Commit dcb5f0d

Browse files
HanSur94claude
andcommitted
docs: add docstrings to server.py (init, lifespan, main, bg tasks)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6807ed2 commit dcb5f0d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/matlab_mcp/server.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ class MatlabMCPServer:
6666
"""
6767

6868
def __init__(self, config: AppConfig) -> None:
69+
"""Initialize server state and all sub-components.
70+
71+
Creates the engine pool, job tracker, executor, session manager,
72+
security validator, and (when monitoring is enabled) the metrics
73+
collector. The metrics store is wired up later during the
74+
server lifespan.
75+
"""
6976
self.config = config
7077
# Collector and store always initialised (None when disabled)
7178
self.collector: Optional[Any] = None
@@ -150,6 +157,16 @@ def create_server(config: AppConfig) -> FastMCP:
150157

151158
@asynccontextmanager
152159
async def lifespan(mcp: FastMCP): # type: ignore[type-arg]
160+
"""Manage server startup and graceful shutdown.
161+
162+
On startup: creates directories, starts the engine pool, wires
163+
the monitoring subsystem, and launches background tasks for
164+
health checks and session/job cleanup.
165+
166+
On shutdown: stops the metrics collector, closes the store,
167+
cancels background tasks, drains running jobs, and stops the
168+
engine pool.
169+
"""
153170
# Security warning for SSE without proxy auth
154171
if (
155172
config.server.transport == "sse"
@@ -238,6 +255,7 @@ async def lifespan(mcp: FastMCP): # type: ignore[type-arg]
238255

239256
# Background task: periodic health checks
240257
async def health_check_loop() -> None:
258+
"""Periodically run engine health checks at the configured interval."""
241259
interval = config.pool.health_check_interval
242260
while True:
243261
try:
@@ -254,6 +272,7 @@ async def health_check_loop() -> None:
254272

255273
# Background task: session + job cleanup
256274
async def cleanup_loop() -> None:
275+
"""Periodically expire idle sessions, prune old jobs, and trim metrics."""
257276
while True:
258277
try:
259278
await asyncio.sleep(60)
@@ -657,7 +676,13 @@ async def get_error_log(ctx: Context, limit: int = 20) -> dict:
657676

658677

659678
def main() -> None:
660-
"""CLI entry point. Load config, set up logging, and run the server."""
679+
"""CLI entry point for the MATLAB MCP Server.
680+
681+
Parses ``--config`` and ``--transport`` arguments, loads the
682+
configuration, configures logging (stderr + file), prints a
683+
startup banner, and runs the FastMCP server in the selected
684+
transport mode (stdio or SSE).
685+
"""
661686
import argparse
662687

663688
parser = argparse.ArgumentParser(description="MATLAB MCP Server")
328 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)