harvesthealth commited on
Commit
ffc9d18
·
verified ·
1 Parent(s): f41cc71

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +51 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ from fastapi import FastAPI, Request, Response
3
+
4
+ app = FastAPI()
5
+ proc = None
6
+
7
+ @app.on_event("startup")
8
+ async def startup_event():
9
+ global proc
10
+ proc = await asyncio.create_subprocess_exec(
11
+ '/usr/local/bin/github-mcp-server', 'stdio',
12
+ stdin=asyncio.subprocess.PIPE,
13
+ stdout=asyncio.subprocess.PIPE,
14
+ stderr=asyncio.subprocess.PIPE,
15
+ )
16
+ asyncio.create_task(log_stderr())
17
+
18
+ async def log_stderr():
19
+ if proc and proc.stderr:
20
+ while not proc.stderr.at_eof():
21
+ line = await proc.stderr.readline()
22
+ print(f"github-mcp-server stderr: {line.decode().strip()}")
23
+
24
+ @app.post("/")
25
+ async def proxy(request: Request):
26
+ if not proc or not proc.stdin or not proc.stdout:
27
+ return Response(status_code=500, content="Subprocess not running")
28
+
29
+ body = await request.body()
30
+ proc.stdin.write(body)
31
+ await proc.stdin.drain()
32
+
33
+ response = bytearray()
34
+ while True:
35
+ try:
36
+ chunk = await asyncio.wait_for(proc.stdout.read(1024), timeout=1.0)
37
+ if not chunk:
38
+ break
39
+ response.extend(chunk)
40
+ if chunk.strip().endswith(b'}'):
41
+ break
42
+ except asyncio.TimeoutError:
43
+ break
44
+
45
+ return Response(content=bytes(response))
46
+
47
+ @app.on_event("shutdown")
48
+ async def shutdown_event():
49
+ if proc:
50
+ proc.kill()
51
+ await proc.wait()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ python-jsonrpc-server