adding Git MCP server example
This commit is contained in:
parent
a0c5abce8f
commit
0944390c3f
1 changed files with 48 additions and 0 deletions
48
examples/mcp/git_example/main.py
Normal file
48
examples/mcp/git_example/main.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import asyncio
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from agents import Agent, Runner, trace
|
||||||
|
from agents.mcp import MCPServer, MCPServerStdio
|
||||||
|
|
||||||
|
async def run(mcp_server: MCPServer, directory_path: str):
|
||||||
|
agent = Agent(
|
||||||
|
name="Assistant",
|
||||||
|
instructions=f"Answer questions about the git repository at {directory_path}, use that for repo_path",
|
||||||
|
mcp_servers=[mcp_server],
|
||||||
|
)
|
||||||
|
|
||||||
|
message = f"Who's the most frequent contributor?"
|
||||||
|
print("\n" + "-" * 40)
|
||||||
|
print(f"Running: {message}")
|
||||||
|
result = await Runner.run(starting_agent=agent, input=message)
|
||||||
|
print(result.final_output)
|
||||||
|
|
||||||
|
message = f"Summarize the last change in the repository."
|
||||||
|
print("\n" + "-" * 40)
|
||||||
|
print(f"Running: {message}")
|
||||||
|
result = await Runner.run(starting_agent=agent, input=message)
|
||||||
|
print(result.final_output)
|
||||||
|
|
||||||
|
|
||||||
|
async def main():
|
||||||
|
# Ask the user for the directory path
|
||||||
|
directory_path = input("Please enter the path to the git repository: ")
|
||||||
|
|
||||||
|
async with MCPServerStdio(
|
||||||
|
params={
|
||||||
|
"command": "uvx",
|
||||||
|
"args": [
|
||||||
|
"mcp-server-git"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
) as server:
|
||||||
|
with trace(workflow_name="MCP Git Example"):
|
||||||
|
await run(server, directory_path)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if not shutil.which("uvx"):
|
||||||
|
raise RuntimeError("uvx is not installed. Please install it with `pip install uvx`.")
|
||||||
|
|
||||||
|
asyncio.run(main())
|
||||||
Loading…
Reference in a new issue