Skip to content

Commit d929b92

Browse files
committed
add @Lifespan decorator and bump joern version
1 parent 49b76b3 commit d929b92

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y \
1111
&& rm -rf /var/lib/apt/lists/*
1212

1313
# Set Joern version
14-
ENV JOERN_VERSION=4.0.478
14+
ENV JOERN_VERSION=4.0.499
1515
ENV JOERN_HOME=/opt/joern
1616

1717
# Download and install Joern from joernio/joern GitHub releases

main.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
import signal
1313
import shutil
1414
import socket
15-
from contextlib import asynccontextmanager
16-
1715
from fastmcp import FastMCP
16+
from fastmcp.server.lifespan import lifespan
1817
from starlette.responses import JSONResponse
1918

2019
from src.config import load_config
@@ -84,16 +83,16 @@ def signal_handler(signum, frame):
8483
logger.debug("Signal handlers registered for SIGTERM and SIGINT")
8584

8685

87-
@asynccontextmanager
88-
async def lifespan(mcp: FastMCP):
86+
@lifespan
87+
async def app_lifespan(server: FastMCP):
8988
"""Startup and shutdown logic for the FastMCP server"""
9089
# Load configuration
9190
config = load_config("config.yaml")
9291
setup_logging(config.server.log_level)
9392
logger.info("Starting CodeBadger Server")
9493

9594
# Setup signal handlers for graceful shutdown
96-
_setup_signal_handlers(mcp)
95+
_setup_signal_handlers(server)
9796

9897
# Ensure required directories exist
9998
os.makedirs(config.storage.workspace_root, exist_ok=True)
@@ -148,26 +147,25 @@ async def lifespan(mcp: FastMCP):
148147
)
149148

150149
# Register MCP tools now that services are initialized
151-
register_tools(mcp, services)
150+
register_tools(server, services)
152151

153152
logger.info("All services initialized")
154153
logger.info("CodeBadger Server is ready")
155154

156-
yield
157-
158-
# Shutdown
159-
await _graceful_shutdown()
160-
logger.info("CodeBadger Server shutdown complete")
155+
yield services
161156

162157
except Exception as e:
163158
logger.error(f"Error during server lifecycle: {e}", exc_info=True)
164159
raise
160+
finally:
161+
await _graceful_shutdown()
162+
logger.info("CodeBadger Server shutdown complete")
165163

166164

167165
# Initialize FastMCP server
168166
mcp = FastMCP(
169167
"CodeBadger Server",
170-
lifespan=lifespan
168+
lifespan=app_lifespan
171169
)
172170

173171
# Note: Tools are registered inside the lifespan function

0 commit comments

Comments
 (0)