Skip to content

Commit af947ee

Browse files
committed
fix(server): make FastMCP-2.x start correctly
• Replace deprecated `lifespan_kwargs=` with functools.partial • Drop extra asyncio layer – call `server.run()` directly • Add missing `functools` import Now `python -m kicad_mcp.server` and `kicad-mcp` block and run cleanly.
1 parent d7c2692 commit af947ee

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

kicad_mcp/server.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import signal
77
import logging
8+
import functools
89
from typing import Callable
910
from fastmcp import FastMCP
1011

@@ -127,9 +128,11 @@ def create_server() -> FastMCP:
127128
# Always print this now, as we rely on CLI
128129
logging.info(f"KiCad Python module setup removed; relying on kicad-cli for external operations.")
129130

131+
# Build a lifespan callable with the kwarg baked in (FastMCP 2.x dropped lifespan_kwargs)
132+
lifespan_factory = functools.partial(kicad_lifespan, kicad_modules_available=kicad_modules_available)
133+
130134
# Initialize FastMCP server
131-
# Pass the availability flag (always False now) to the lifespan context
132-
mcp = FastMCP("KiCad", lifespan=kicad_lifespan, lifespan_kwargs={"kicad_modules_available": kicad_modules_available})
135+
mcp = FastMCP("KiCad", lifespan=lifespan_factory)
133136
logging.info(f"Created FastMCP server instance with lifespan management")
134137

135138
# Register resources
@@ -207,15 +210,15 @@ def setup_logging() -> None:
207210
)
208211

209212

210-
async def main() -> None:
211-
"""Main server entry point."""
213+
def main() -> None:
214+
"""Start the KiCad MCP server (blocking)."""
212215
setup_logging()
213216
logging.info("Starting KiCad MCP server...")
214217

215218
server = create_server()
216219

217220
try:
218-
await server.run()
221+
server.run() # FastMCP manages its own event loop
219222
except KeyboardInterrupt:
220223
logging.info("Server interrupted by user")
221224
except Exception as e:
@@ -225,5 +228,4 @@ async def main() -> None:
225228

226229

227230
if __name__ == "__main__":
228-
import asyncio
229-
asyncio.run(main())
231+
main()

0 commit comments

Comments
 (0)