2
2
3
3
from __future__ import annotations
4
4
5
- from mcp .server .fastmcp import FastMCP
5
+ from mcp .server .fastmcp import FastMCP # pylint: disable=import-error
6
6
7
7
from gitingest .entrypoint import ingest_async
8
8
from gitingest .utils .logging_config import get_logger
@@ -21,6 +21,7 @@ async def ingest_repository(
21
21
include_patterns : list [str ] | None = None ,
22
22
exclude_patterns : list [str ] | None = None ,
23
23
branch : str | None = None ,
24
+ * ,
24
25
include_gitignored : bool = False ,
25
26
include_submodules : bool = False ,
26
27
token : str | None = None ,
@@ -57,9 +58,12 @@ async def ingest_repository(
57
58
token = token ,
58
59
output = None , # Don't write to file, return content instead
59
60
)
61
+ except Exception :
62
+ logger .exception ("Error during ingestion" )
63
+ return "Error ingesting repository: An internal error occurred"
60
64
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 }
63
67
64
68
## Summary
65
69
{ summary }
@@ -76,21 +80,15 @@ async def ingest_repository(
76
80
*Generated by Gitingest MCP Server*
77
81
"""
78
82
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
-
85
83
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 :
87
85
"""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 )
89
87
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
94
92
95
93
tcp_app = FastAPI (title = "Gitingest MCP Server" , description = "MCP server over HTTP/SSE" )
96
94
@@ -104,15 +102,15 @@ async def start_mcp_server_tcp(host: str = "0.0.0.0", port: int = 8001):
104
102
)
105
103
106
104
@tcp_app .get ("/health" )
107
- async def health_check ():
105
+ async def health_check ()-> dict [ str , str ] :
108
106
"""Health check endpoint."""
109
107
return {"status" : "healthy" , "transport" : "http" , "version" : "1.0" }
110
108
111
109
@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
113
111
"""Handle MCP messages via HTTP POST."""
114
112
try :
115
- logger .info (f "Received MCP message: { message } " )
113
+ logger .info ("Received MCP message: %s" , message )
116
114
117
115
# Handle different MCP message types
118
116
if message .get ("method" ) == "initialize" :
@@ -183,8 +181,8 @@ async def handle_message(message: dict):
183
181
},
184
182
},
185
183
)
186
- except Exception as e :
187
- logger .exception ("Tool execution failed: %s" , e )
184
+ except Exception :
185
+ logger .exception ("Tool execution failed" )
188
186
return JSONResponse (
189
187
{
190
188
"jsonrpc" : "2.0" ,
@@ -220,8 +218,8 @@ async def handle_message(message: dict):
220
218
},
221
219
)
222
220
223
- except Exception as e :
224
- logger .exception ("Error handling MCP message: %s" , e )
221
+ except Exception :
222
+ logger .exception ("Error handling MCP message" )
225
223
return JSONResponse (
226
224
{
227
225
"jsonrpc" : "2.0" ,
0 commit comments