100+ AI Agents, Agent Skills and RAG Apps - Free and Open Source.
feat: Update GitHub MCP Agent to use official GitHub MCP Server via Docker
Shubhamsabooe55a2eb5e6dc
diff --git a/mcp_ai_agents/github_mcp_agent/README.md b/mcp_ai_agents/github_mcp_agent/README.mdindex 47cf29f9..7bf03dda 100644--- a/mcp_ai_agents/github_mcp_agent/README.md+++ b/mcp_ai_agents/github_mcp_agent/README.md@@ -2,6 +2,8 @@A Streamlit application that allows you to explore and analyze GitHub repositories using natural language queries through the Model Context Protocol (MCP).+**β¨ Now using the official [GitHub MCP Server](https://github.com/github/github-mcp-server) from GitHub!**+## Features- **Natural Language Interface**: Ask questions about repositories in plain English@@ -15,11 +17,11 @@ A Streamlit application that allows you to explore and analyze GitHub repositori### Requirements- Python 3.8+-- Node.js and npm (for MCP GitHub server)- - This is a critical requirement! The app uses `npx` to run the MCP GitHub server- - Download and install from [nodejs.org](https://nodejs.org/)-- GitHub Personal Access Token with appropriate permissions+- Docker (for official GitHub MCP server)+ - Download and install from [docker.com](https://www.docker.com/get-started)+ - Make sure Docker is running before starting the app- OpenAI API Key+- GitHub Personal Access Token### Installation@@ -34,35 +36,26 @@ A Streamlit application that allows you to explore and analyze GitHub repositoripip install -r requirements.txt```-3. Verify Node.js and npm are installed:+3. Verify Docker is installed and running:```bash- node --version- npm --version- npx --version+ docker --version+ docker ps```- All of these commands should return version numbers. If they don't, please install Node.js.--4. Set up your API keys:- - Set OpenAI API Key as an environment variable:- ```bash- export OPENAI_API_KEY=your-openai-api-key- ```- - GitHub token will be entered directly in the app interface-5. Create a GitHub Personal Access Token:- - Visit https://github.com/settings/tokens- - Create a new token with `repo` and `user` scopes- - Save the token somewhere secure+4. Get your API keys:+ - **OpenAI API Key**: Get from [platform.openai.com/api-keys](https://platform.openai.com/api-keys)+ - **GitHub Token**: Create at [github.com/settings/tokens](https://github.com/settings/tokens) with `repo` scope### Running the App1. Start the Streamlit app:```bash- streamlit run app.py+ streamlit run github_agent.py```2. In the app interface:- - Enter your GitHub token in the sidebar+ - Enter your OpenAI API key+ - Enter your GitHub token- Specify a repository to analyze- Select a query type or write your own- Click "Run Query"diff --git a/mcp_ai_agents/github_mcp_agent/github_agent.py b/mcp_ai_agents/github_mcp_agent/github_agent.pyindex 212e5f2c..0e0066ed 100644--- a/mcp_ai_agents/github_mcp_agent/github_agent.py+++ b/mcp_ai_agents/github_mcp_agent/github_agent.py@@ -7,19 +7,21 @@ from agno.tools.mcp import MCPToolsfrom mcp import ClientSession, StdioServerParametersfrom mcp.client.stdio import stdio_client-# Page configst.set_page_config(page_title="π GitHub MCP Agent", page_icon="π", layout="wide")-# Title and descriptionst.markdown("<h1 class='main-header'>π GitHub MCP Agent</h1>", unsafe_allow_html=True)st.markdown("Explore GitHub repositories with natural language using the Model Context Protocol")-# Setup sidebar for API keywith st.sidebar:st.header("π Authentication")++ openai_key = st.text_input("OpenAI API Key", type="password",+ help="Required for the AI agent to interpret queries and format results")+ if openai_key:+ os.environ["OPENAI_API_KEY"] = openai_key+github_token = st.text_input("GitHub Token", type="password",help="Create a token with repo scope at github.com/settings/tokens")-if github_token:os.environ["GITHUB_TOKEN"] = github_token@@ -41,7 +43,6 @@ with st.sidebar:st.markdown("---")st.caption("Note: Always specify the repository in your query if not already selected in the main input.")-# Query inputcol1, col2 = st.columns([3, 1])with col1:repo = st.text_input("Repository", value="Shubhamsaboo/awesome-llm-apps", help="Format: owner/repo")@@ -50,7 +51,6 @@ with col2:"Issues", "Pull Requests", "Repository Activity", "Custom"])-# Create predefined queries based on typeif query_type == "Issues":query_template = f"Find issues labeled as bugs in {repo}"elif query_type == "Pull Requests":@@ -63,25 +63,34 @@ else:query = st.text_area("Your Query", value=query_template,placeholder="What would you like to know about this repository?")-# Main function to run agentasync def run_github_agent(message):if not os.getenv("GITHUB_TOKEN"):return "Error: GitHub token not provided"+ if not os.getenv("OPENAI_API_KEY"):+ return "Error: OpenAI API key not provided"+try:server_params = StdioServerParameters(- command="npx",- args=["-y", "@modelcontextprotocol/server-github"],+ command="docker",+ args=[+ "run", "-i", "--rm",+ "-e", "GITHUB_PERSONAL_ACCESS_TOKEN",+ "-e", "GITHUB_TOOLSETS",+ "ghcr.io/github/github-mcp-server"+ ],+ env={+ **os.environ,+ "GITHUB_PERSONAL_ACCESS_TOKEN": os.getenv('GITHUB_TOKEN'),+ "GITHUB_TOOLSETS": "repos,issues,pull_requests"+ })- # Create client sessionasync with stdio_client(server_params) as (read, write):async with ClientSession(read, write) as session:- # Initialize MCP toolkitmcp_tools = MCPTools(session=session)await mcp_tools.initialize()- # Create agentagent = Agent(tools=[mcp_tools],instructions=dedent("""\@@ -93,24 +102,25 @@ async def run_github_agent(message):- Include links to relevant GitHub pages when helpful"""),markdown=True,- show_tool_calls=True,)- # Run agent- response = await agent.arun(message)+ response = await asyncio.wait_for(agent.arun(message), timeout=120.0)return response.content++ except asyncio.TimeoutError:+ return "Error: Request timed out after 120 seconds"except Exception as e:return f"Error: {str(e)}"-# Run buttonif st.button("π Run Query", type="primary", use_container_width=True):- if not github_token:+ if not openai_key:+ st.error("Please enter your OpenAI API key in the sidebar")+ elif not github_token:st.error("Please enter your GitHub token in the sidebar")elif not query:st.error("Please enter a query")else:with st.spinner("Analyzing GitHub repository..."):- # Ensure the repository is explicitly mentioned in the queryif repo and repo not in query:full_query = f"{query} in {repo}"else:@@ -118,32 +128,30 @@ if st.button("π Run Query", type="primary", use_container_width=True):result = asyncio.run(run_github_agent(full_query))- # Display results in a nice containerst.markdown("### Results")st.markdown(result)-# Display help text for first-time usersif 'result' not in locals():st.markdown("""<div class='info-box'><h4>How to use this app:</h4><ol>- <li>Enter your GitHub token in the sidebar</li>+ <li>Enter your <strong>OpenAI API key</strong> in the sidebar (powers the AI agent)</li>+ <li>Enter your <strong>GitHub token</strong> in the sidebar</li><li>Specify a repository (e.g., Shubhamsaboo/awesome-llm-apps)</li><li>Select a query type or write your own</li><li>Click 'Run Query' to see results</li></ol>- <p><strong>Important Notes:</strong></p>+ <p><strong>How it works:</strong></p><ul>- <li>The Model Context Protocol (MCP) provides real-time access to GitHub repositories</li>- <li>Queries work best when they focus on specific aspects like issues, PRs, or repository info</li>- <li>More specific queries yield better results</li>- <li>This app requires Node.js to be installed (for the npx command)</li>+ <li>Uses the official GitHub MCP server via Docker for real-time access to GitHub API</li>+ <li>AI Agent (powered by OpenAI) interprets your queries and calls appropriate GitHub APIs</li>+ <li>Results are formatted in readable markdown with insights and links</li>+ <li>Queries work best when focused on specific aspects like issues, PRs, or repository info</li></ul></div>""",unsafe_allow_html=True)-# Footerst.markdown("---")-st.write("Built with Streamlit, Agno, and Model Context Protocol β€οΈ")\ No newline at end of file+st.write("Built with Streamlit, Agno, and Model Context Protocol β€οΈ")