|
| 1 | +import asyncio |
| 2 | +import shutil |
| 3 | + |
| 4 | +from agents import Agent, Runner, trace |
| 5 | +from agents.mcp import MCPServer, MCPServerStdio |
| 6 | + |
| 7 | + |
| 8 | +async def run(mcp_server: MCPServer, directory_path: str): |
| 9 | + agent = Agent( |
| 10 | + name="Assistant", |
| 11 | + instructions=f"Answer questions about the git repository at {directory_path}, use that for repo_path", |
| 12 | + mcp_servers=[mcp_server], |
| 13 | + ) |
| 14 | + |
| 15 | + message = "Who's the most frequent contributor?" |
| 16 | + print("\n" + "-" * 40) |
| 17 | + print(f"Running: {message}") |
| 18 | + result = await Runner.run(starting_agent=agent, input=message) |
| 19 | + print(result.final_output) |
| 20 | + |
| 21 | + message = "Summarize the last change in the repository." |
| 22 | + print("\n" + "-" * 40) |
| 23 | + print(f"Running: {message}") |
| 24 | + result = await Runner.run(starting_agent=agent, input=message) |
| 25 | + print(result.final_output) |
| 26 | + |
| 27 | + |
| 28 | +async def main(): |
| 29 | + # Ask the user for the directory path |
| 30 | + directory_path = input("Please enter the path to the git repository: ") |
| 31 | + |
| 32 | + async with MCPServerStdio( |
| 33 | + params={ |
| 34 | + "command": "uvx", |
| 35 | + "args": [ |
| 36 | + "mcp-server-git" |
| 37 | + ] |
| 38 | + } |
| 39 | + ) as server: |
| 40 | + with trace(workflow_name="MCP Git Example"): |
| 41 | + await run(server, directory_path) |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == "__main__": |
| 45 | + if not shutil.which("uvx"): |
| 46 | + raise RuntimeError("uvx is not installed. Please install it with `pip install uvx`.") |
| 47 | + |
| 48 | + asyncio.run(main()) |
0 commit comments