GitHub MCP agent
Using the GitHub MCP server to create an Agent that can explore, analyze and provide insights about GitHub repositories:
1"""🐙 MCP GitHub Agent - Your Personal GitHub Explorer!23This example shows how to create a GitHub agent that uses MCP to explore,4analyze, and provide insights about GitHub repositories. The agent leverages the Model5Context Protocol (MCP) to interact with GitHub, allowing it to answer questions6about issues, pull requests, repository details and more.78Example prompts to try:9- "List open issues in the repository"10- "Show me recent pull requests"11- "What are the repository statistics?"12- "Find issues labeled as bugs"13- "Show me contributor activity"1415Run: `uv pip install kern-ai mcp openai` to install the dependencies16Environment variables needed:17- Create a GitHub personal access token following these steps:18 - https://github.com/modelcontextprotocol/servers/tree/main/src/github#setup19- export GITHUB_TOKEN: Your GitHub personal access token20"""2122import asyncio23import os24from textwrap import dedent2526from kern.agent import Agent27from kern.tools.mcp import MCPTools28from mcp import StdioServerParameters293031async def run_agent(message: str) -> None:32 """Run the GitHub agent with the given message."""3334 # Initialize the MCP server35 server_params = StdioServerParameters(36 command="npx",37 args=["-y", "@modelcontextprotocol/server-github"],38 )3940 # Create a client session to connect to the MCP server41 async with MCPTools(server_params=server_params) as mcp_tools:42 agent = Agent(43 tools=[mcp_tools],44 instructions=dedent("""\45 You are a GitHub assistant. Help users explore repositories and their activity.4647 - Use headings to organize your responses48 - Be concise and focus on relevant information\49 """),50 markdown=True,51 )5253 # Run the agent54 await agent.aprint_response(message, stream=True)555657# Example usage58if __name__ == "__main__":59 # Pull request example60 asyncio.run(61 run_agent(62 "Tell me about Kern. Github repo: https://github.com/kern-ai/kern. You can read the README for more information."63 )64 )656667# More example prompts to explore:68"""69Issue queries:701. "Find issues needing attention"712. "Show me issues by label"723. "What issues are being actively discussed?"734. "Find related issues"745. "Analyze issue resolution patterns"7576Pull request queries:771. "What PRs need review?"782. "Show me recent merged PRs"793. "Find PRs with conflicts"804. "What features are being developed?"815. "Analyze PR review patterns"8283Repository queries:841. "Show repository health metrics"852. "What are the contribution guidelines?"863. "Find documentation gaps"874. "Analyze code quality trends"885. "Show repository activity patterns"89"""