Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,26 +16,45 @@ async def startup_event():
|
|
| 16 |
# Get the token from an environment variable on the Hugging Face Space
|
| 17 |
# This is a more secure way to handle the token
|
| 18 |
token = os.environ.get("GITHUB_PERSONAL_ACCESS_TOKEN")
|
|
|
|
|
|
|
| 19 |
if not token:
|
| 20 |
logger.error("GITHUB_PERSONAL_ACCESS_TOKEN environment variable not set")
|
| 21 |
return
|
| 22 |
|
| 23 |
logger.info("Starting subprocess with token: %s", token[:10] + "...")
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
async def log_stderr():
|
| 35 |
if proc and proc.stderr:
|
|
|
|
| 36 |
while not proc.stderr.at_eof():
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
@app.post("/")
|
| 41 |
async def proxy(request: Request):
|
|
@@ -88,4 +107,4 @@ async def shutdown_event():
|
|
| 88 |
logger.info("Shutting down subprocess...")
|
| 89 |
proc.kill()
|
| 90 |
await proc.wait()
|
| 91 |
-
logger.info("Subprocess shut down")
|
|
|
|
| 16 |
# Get the token from an environment variable on the Hugging Face Space
|
| 17 |
# This is a more secure way to handle the token
|
| 18 |
token = os.environ.get("GITHUB_PERSONAL_ACCESS_TOKEN")
|
| 19 |
+
logger.info("Attempting to start subprocess...")
|
| 20 |
+
logger.info("Token environment variable exists: %s", token is not None)
|
| 21 |
if not token:
|
| 22 |
logger.error("GITHUB_PERSONAL_ACCESS_TOKEN environment variable not set")
|
| 23 |
return
|
| 24 |
|
| 25 |
logger.info("Starting subprocess with token: %s", token[:10] + "...")
|
| 26 |
+
try:
|
| 27 |
+
proc = await asyncio.create_subprocess_exec(
|
| 28 |
+
'/usr/local/bin/github-mcp-server', 'stdio',
|
| 29 |
+
stdin=asyncio.subprocess.PIPE,
|
| 30 |
+
stdout=asyncio.subprocess.PIPE,
|
| 31 |
+
stderr=asyncio.subprocess.PIPE,
|
| 32 |
+
env={"GITHUB_PERSONAL_ACCESS_TOKEN": token}
|
| 33 |
+
)
|
| 34 |
+
logger.info("Subprocess created successfully with PID: %s", proc.pid)
|
| 35 |
+
# Test if subprocess is actually running
|
| 36 |
+
if proc.returncode is None:
|
| 37 |
+
logger.info("Subprocess appears to be running")
|
| 38 |
+
else:
|
| 39 |
+
logger.warning("Subprocess may have exited immediately with code: %s", proc.returncode)
|
| 40 |
+
asyncio.create_task(log_stderr())
|
| 41 |
+
except Exception as e:
|
| 42 |
+
logger.error("Failed to create subprocess: %s", str(e))
|
| 43 |
+
raise
|
| 44 |
|
| 45 |
async def log_stderr():
|
| 46 |
if proc and proc.stderr:
|
| 47 |
+
logger.info("Starting stderr logging task")
|
| 48 |
while not proc.stderr.at_eof():
|
| 49 |
+
try:
|
| 50 |
+
line = await proc.stderr.readline()
|
| 51 |
+
if line:
|
| 52 |
+
logger.debug("github-mcp-server stderr: %s", line.decode().strip())
|
| 53 |
+
else:
|
| 54 |
+
logger.debug("Empty line from stderr")
|
| 55 |
+
except Exception as e:
|
| 56 |
+
logger.error("Error reading stderr: %s", str(e))
|
| 57 |
+
break
|
| 58 |
|
| 59 |
@app.post("/")
|
| 60 |
async def proxy(request: Request):
|
|
|
|
| 107 |
logger.info("Shutting down subprocess...")
|
| 108 |
proc.kill()
|
| 109 |
await proc.wait()
|
| 110 |
+
logger.info("Subprocess shut down")
|