-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: FastMCP server migration refactor part 1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||
|
/improve |
| def sync_main() -> None: | ||
| """ | ||
| Synchronous entry point for the MCP server. | ||
| This function is used as the script entry point in pyproject.toml. | ||
| """ | ||
| try: | ||
| asyncio.run(main()) | ||
| except KeyboardInterrupt: | ||
| logger.info("Server stopped by user") | ||
| sys.exit(0) | ||
| except Exception as e: | ||
| logger.error(f"Fatal error: {e}") | ||
| sys.exit(1) | ||
| """Synchronous entry point for the FastMCP server (stdio by default).""" | ||
| # FastMCP defaults to stdio transport, preserving original behavior | ||
| mcp.run() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Wrap the mcp.run() call in sync_main with a try...except block to gracefully handle KeyboardInterrupt for shutdown and catch other potential exceptions. [general, importance: 7]
| def sync_main() -> None: | |
| """ | |
| Synchronous entry point for the MCP server. | |
| This function is used as the script entry point in pyproject.toml. | |
| """ | |
| try: | |
| asyncio.run(main()) | |
| except KeyboardInterrupt: | |
| logger.info("Server stopped by user") | |
| sys.exit(0) | |
| except Exception as e: | |
| logger.error(f"Fatal error: {e}") | |
| sys.exit(1) | |
| """Synchronous entry point for the FastMCP server (stdio by default).""" | |
| # FastMCP defaults to stdio transport, preserving original behavior | |
| mcp.run() | |
| def sync_main() -> None: | |
| """Synchronous entry point for the FastMCP server (stdio by default).""" | |
| try: | |
| mcp.run() | |
| except KeyboardInterrupt: | |
| # Graceful shutdown | |
| return | |
| except Exception as e: | |
| # Emit a minimal error and non-zero exit for critical failures | |
| raise SystemExit(f"Server terminated due to error: {e}") |
User description
The changes implement a migration from a manual MCP server implementation to FastMCP, consisting of:
PR Type
Enhancement
Description
Migrated from manual MCP server to FastMCP framework
Reduced server implementation from 236 to 79 lines
Added structured output capabilities with Pydantic validation
Preserved CLI entrypoint and tool behavior
Diagram Walkthrough
File Walkthrough
server.py
Complete server rewrite using FastMCP frameworksrc/workshop_mcp/server.py
implementation
WorkshopMCPServerto functional decoratorapproach
pyproject.toml
Added FastMCP and Pydantic dependenciespyproject.toml
fastmcp = "^2.10.0"dependency for new frameworkpydantic = "^2.8.0"for structured data validation