Skip to content

Commit 9bea0f4

Browse files
laurigatesclaude
andcommitted
feat: migrate to FastMCP 2.0 framework with modern Python packaging
- Update imports from 'mcp.server.fastmcp' to 'fastmcp' per FastMCP 2.0 migration - Add pyproject.toml for modern Python packaging with hatchling build backend - Implement missing server lifecycle functions: main(), setup_logging(), cleanup_handler() - Add async main() entry point for proper server execution - Update main.py to use async server execution pattern - Add fastmcp>=0.1.0 dependency to replace legacy mcp server imports This establishes the foundation for all subsequent feature additions and ensures compatibility with modern MCP clients and development workflows. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 7019df0 commit 9bea0f4

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

kicad_mcp/server.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import signal
77
import logging
88
from typing import Callable
9-
from mcp.server.fastmcp import FastMCP
9+
from fastmcp import FastMCP
1010

1111
# Import resource handlers
1212
from kicad_mcp.resources.projects import register_project_resources
@@ -186,3 +186,44 @@ def cleanup_temp_dirs():
186186

187187
logging.info(f"Server initialization complete")
188188
return mcp
189+
190+
191+
def setup_signal_handlers() -> None:
192+
"""Setup signal handlers for graceful shutdown."""
193+
# Signal handlers are set up in register_signal_handlers
194+
pass
195+
196+
197+
def cleanup_handler() -> None:
198+
"""Handle cleanup during shutdown."""
199+
run_cleanup_handlers()
200+
201+
202+
def setup_logging() -> None:
203+
"""Configure logging for the server."""
204+
logging.basicConfig(
205+
level=logging.INFO,
206+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
207+
)
208+
209+
210+
async def main() -> None:
211+
"""Main server entry point."""
212+
setup_logging()
213+
logging.info("Starting KiCad MCP server...")
214+
215+
server = create_server()
216+
217+
try:
218+
await server.run()
219+
except KeyboardInterrupt:
220+
logging.info("Server interrupted by user")
221+
except Exception as e:
222+
logging.error(f"Server error: {e}")
223+
finally:
224+
logging.info("Server shutdown complete")
225+
226+
227+
if __name__ == "__main__":
228+
import asyncio
229+
asyncio.run(main())

main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# Must import config BEFORE env potentially overrides it via os.environ
1111
from kicad_mcp.config import KICAD_USER_DIR, ADDITIONAL_SEARCH_PATHS
12-
from kicad_mcp.server import create_server
12+
from kicad_mcp.server import main as server_main
1313
from kicad_mcp.utils.env import load_dotenv
1414

1515
# --- Setup Logging ---
@@ -70,10 +70,10 @@
7070
else:
7171
logging.info(f"No additional search paths configured") # Changed print to logging
7272

73-
# Create and run server
74-
server = create_server()
73+
# Run server
7574
logging.info(f"Running server with stdio transport") # Changed print to logging
76-
server.run(transport='stdio')
75+
import asyncio
76+
asyncio.run(server_main())
7777
except Exception as e:
7878
logging.exception(f"Unhandled exception in main") # Log exception details
7979
raise

pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "kicad-mcp"
7+
version = "0.1.0"
8+
description = "Model Context Protocol (MCP) server for KiCad electronic design automation (EDA) files"
9+
readme = "README.md"
10+
license = { text = "MIT" }
11+
authors = [
12+
{ name = "KiCad MCP Contributors" }
13+
]
14+
requires-python = ">=3.10"
15+
dependencies = [
16+
"mcp[cli]>=1.0.0",
17+
"fastmcp>=0.1.0",
18+
"pandas>=2.0.0",
19+
]
20+
21+
[project.scripts]
22+
kicad-mcp = "kicad_mcp.server:main"
23+
24+
[dependency-groups]
25+
dev = [
26+
"pytest>=7.0.0",
27+
"pytest-asyncio>=0.23.0",
28+
]

0 commit comments

Comments
 (0)