-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Expand file tree
/
Copy path__init__.py
More file actions
44 lines (38 loc) · 1.17 KB
/
__init__.py
File metadata and controls
44 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import asyncio
import click
import logging
from pathlib import Path
import sys
import signal
from .server import serve
def handle_sigint():
for task in asyncio.all_tasks():
task.cancel()
@click.command()
@click.option(
"--repository",
type=click.Path(exists=True, file_okay=False, dir_okay=True, path_type=Path),
help="Path to Git repository to operate on",
)
@click.option("-v", "--verbose", count=True, default=0)
def main(repository: Path | None, verbose: int = 0) -> None:
"""MCP Git Server - Git functionality for MCP"""
logging_level = logging.WARN
if verbose == 1:
logging_level = logging.INFO
elif verbose > 1:
logging_level = logging.DEBUG
logging.basicConfig(level=logging_level)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
# Set up signal handlers
loop.add_signal_handler(signal.SIGINT, handle_sigint)
loop.add_signal_handler(signal.SIGTERM, handle_sigint)
try:
loop.run_until_complete(serve(repository))
except asyncio.CancelledError:
logging.info("Server shutdown initiated")
finally:
loop.close()
if __name__ == "__main__":
main()