22
33from __future__ import annotations
44
5- from mcp .server .fastmcp import FastMCP
5+ from mcp .server .fastmcp import FastMCP # pylint: disable=import-error
66
77from gitingest .entrypoint import ingest_async
88from gitingest .utils .logging_config import get_logger
@@ -21,6 +21,7 @@ async def ingest_repository(
2121 include_patterns : list [str ] | None = None ,
2222 exclude_patterns : list [str ] | None = None ,
2323 branch : str | None = None ,
24+ * ,
2425 include_gitignored : bool = False ,
2526 include_submodules : bool = False ,
2627 token : str | None = None ,
@@ -57,9 +58,12 @@ async def ingest_repository(
5758 token = token ,
5859 output = None , # Don't write to file, return content instead
5960 )
61+ except Exception :
62+ logger .exception ("Error during ingestion" )
63+ return "Error ingesting repository: An internal error occurred"
6064
61- # Create a structured response
62- response_content = f"""# Repository Analysis: { source }
65+ # Create a structured response and return directly
66+ return f"""# Repository Analysis: { source }
6367
6468## Summary
6569{ summary }
@@ -76,21 +80,15 @@ async def ingest_repository(
7680*Generated by Gitingest MCP Server*
7781"""
7882
79- return response_content
80-
81- except Exception as e :
82- logger .exception ("Error during ingestion: %s" , e )
83- return "Error ingesting repository: An internal error occurred"
84-
8583
86- async def start_mcp_server_tcp (host : str = "0 .0.0.0 " , port : int = 8001 ):
84+ async def start_mcp_server_tcp (host : str = "127 .0.0.1 " , port : int = 8001 ) -> None :
8785 """Start the MCP server with HTTP transport using SSE."""
88- logger .info (f "Starting Gitingest MCP server with HTTP/SSE transport on { host } : { port } " )
86+ logger .info ("Starting Gitingest MCP server with HTTP/SSE transport on %s:%s" , host , port )
8987
90- import uvicorn
91- from fastapi import FastAPI
92- from fastapi .middleware .cors import CORSMiddleware
93- from fastapi .responses import JSONResponse
88+ import uvicorn # noqa: PLC0415 # pylint: disable=import-outside-toplevel
89+ from fastapi import FastAPI # noqa: PLC0415 # pylint: disable=import-outside-toplevel
90+ from fastapi .middleware .cors import CORSMiddleware # noqa: PLC0415 # pylint: disable=import-outside-toplevel
91+ from fastapi .responses import JSONResponse # noqa: PLC0415 # pylint: disable=import-outside-toplevel
9492
9593 tcp_app = FastAPI (title = "Gitingest MCP Server" , description = "MCP server over HTTP/SSE" )
9694
@@ -104,15 +102,15 @@ async def start_mcp_server_tcp(host: str = "0.0.0.0", port: int = 8001):
104102 )
105103
106104 @tcp_app .get ("/health" )
107- async def health_check ():
105+ async def health_check () -> dict [ str , str ] :
108106 """Health check endpoint."""
109107 return {"status" : "healthy" , "transport" : "http" , "version" : "1.0" }
110108
111109 @tcp_app .post ("/message" )
112- async def handle_message (message : dict ):
110+ async def handle_message (message : dict ) -> JSONResponse : # pylint: disable=too-many-return-statements
113111 """Handle MCP messages via HTTP POST."""
114112 try :
115- logger .info (f "Received MCP message: { message } " )
113+ logger .info ("Received MCP message: %s" , message )
116114
117115 # Handle different MCP message types
118116 if message .get ("method" ) == "initialize" :
@@ -183,8 +181,8 @@ async def handle_message(message: dict):
183181 },
184182 },
185183 )
186- except Exception as e :
187- logger .exception ("Tool execution failed: %s" , e )
184+ except Exception :
185+ logger .exception ("Tool execution failed" )
188186 return JSONResponse (
189187 {
190188 "jsonrpc" : "2.0" ,
@@ -220,8 +218,8 @@ async def handle_message(message: dict):
220218 },
221219 )
222220
223- except Exception as e :
224- logger .exception ("Error handling MCP message: %s" , e )
221+ except Exception :
222+ logger .exception ("Error handling MCP message" )
225223 return JSONResponse (
226224 {
227225 "jsonrpc" : "2.0" ,
0 commit comments