forked from AOSSIE-Org/Devr.AI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_mcp_server.py
More file actions
88 lines (71 loc) · 2.78 KB
/
github_mcp_server.py
File metadata and controls
88 lines (71 loc) · 2.78 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import os
import logging
from dotenv import load_dotenv, find_dotenv
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from .github_mcp_service import GitHubMCPService
from typing import Optional
dotenv_path = find_dotenv(usecwd=True)
if dotenv_path:
load_dotenv(dotenv_path=dotenv_path)
else:
load_dotenv()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI(title="GitHub MCP Server", version="1.0.0")
# Load env vars
GITHUB_ORG = os.getenv("GITHUB_ORG")
if not GITHUB_ORG:
logger.warning("GITHUB_ORG not set in .env — defaulting to manual owner input")
github_service: Optional[GitHubMCPService] = None
try:
token = os.getenv("GITHUB_TOKEN") or os.getenv("GH_TOKEN")
if not token:
logger.warning("GITHUB_TOKEN/GH_TOKEN not set; GitHub API calls may be rate-limited or fail.")
github_service = GitHubMCPService(token=token)
logger.info("GitHub service initialized successfully")
except Exception as e:
logger.error(f"Failed to initialize GitHub service: {e}")
github_service = None
class RepoInfoRequest(BaseModel):
repo: str
class RepoInfoResponse(BaseModel):
status: str
data: dict
error: str = None
@app.get("/health")
async def health_check():
"""Health check endpoint"""
return {"status": "healthy", "service": "github-mcp"}
class OrgInfoRequest(BaseModel):
org: str
@app.post("/list_org_repos")
async def list_org_repos(request: OrgInfoRequest):
try:
if not github_service:
raise HTTPException(status_code=500, detail="GitHub service not available")
result = github_service.list_org_repos(request.org)
if "error" in result:
return {"status": "error", "data": {}, "error": result["error"]}
return {"status": "success", "data": result}
except Exception as e:
logger.error(f"Error listing org repos: {e}")
raise HTTPException(status_code=500, detail=str(e))
@app.post("/github_support")
async def get_github_supp(request: RepoInfoRequest):
"""Get repo details, using fixed org from env"""
if not github_service:
raise HTTPException(status_code=500, detail="GitHub service not available")
if not GITHUB_ORG:
raise HTTPException(status_code=500, detail="GITHUB_ORG not configured in .env")
try:
result = github_service.repo_query(GITHUB_ORG, request.repo)
if "error" in result:
return RepoInfoResponse(status="error", data={}, error=result["error"])
return RepoInfoResponse(status="success", data=result)
except Exception as e:
logger.error(f"Error getting repo info: {e}")
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8001)