Skip to content

Commit 86b66eb

Browse files
committed
fix(server): improve graceful shutdown and fix naming convention
- Rename server from "workflows" to "workflows_mcp" following Python MCP naming convention - Add proper KeyboardInterrupt handling for graceful Ctrl+C shutdown - Add detailed logging for server lifecycle events - Fix WORKFLOWS_TEMPLATE_PATHS separator in README (colon to comma) The shutdown improvements ensure proper cleanup of async resources and lifespan context when server is stopped via SIGINT.
1 parent 52da77f commit 86b66eb

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The plugin automatically configures the MCP server with custom workflow director
5353
"--refresh"
5454
],
5555
"env": {
56-
"WORKFLOWS_TEMPLATE_PATHS": "~/.workflows:./.workflows",
56+
"WORKFLOWS_TEMPLATE_PATHS": "~/.workflows,./.workflows",
5757
"WORKFLOWS_LOG_LEVEL": "INFO",
5858
"WORKFLOWS_MAX_RECURSION_DEPTH": "50"
5959
}

src/workflows_mcp/server.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ async def app_lifespan(_server: FastMCP) -> AsyncIterator[AppContext]:
224224

225225

226226
# Initialize MCP server with lifespan management
227-
mcp = FastMCP("workflows", lifespan=app_lifespan)
227+
# Following Python MCP naming convention: {service}_mcp
228+
mcp = FastMCP("workflows_mcp", lifespan=app_lifespan)
228229

229230

230231
# =============================================================================
@@ -265,8 +266,23 @@ def main() -> None:
265266
stream=sys.stderr,
266267
)
267268

268-
# Run the MCP server
269-
mcp.run() # Defaults to stdio transport
269+
logger.info("Starting MCP server (press Ctrl+C to stop)...")
270+
271+
try:
272+
# Run the MCP server with stdio transport
273+
# anyio.run() (used internally by mcp.run()) handles SIGINT gracefully
274+
# and raises KeyboardInterrupt for clean shutdown
275+
mcp.run()
276+
except KeyboardInterrupt:
277+
# Graceful shutdown via Ctrl+C (SIGINT)
278+
# anyio ensures proper cleanup of async resources and lifespan context
279+
logger.info("Received interrupt signal, shutting down gracefully...")
280+
except Exception as e:
281+
# Unexpected errors
282+
logger.exception(f"Server error: {e}")
283+
sys.exit(1)
284+
285+
logger.info("Server shutdown complete")
270286

271287

272288
# =============================================================================

0 commit comments

Comments
 (0)