03_GitHubMCP.py 762 B

123456789101112131415161718192021222324252627282930313233
  1. """
  2. GitHub MCP 服务示例
  3. 注意:需要设置环境变量
  4. Windows: $env:GITHUB_PERSONAL_ACCESS_TOKEN="your_token_here"
  5. Linux/macOS: export GITHUB_PERSONAL_ACCESS_TOKEN="your_token_here"
  6. """
  7. from hello_agents.tools import MCPTool
  8. # 创建 GitHub MCP 工具
  9. github_tool = MCPTool(
  10. server_command=["npx", "-y", "@modelcontextprotocol/server-github"]
  11. )
  12. # 1. 列出可用工具
  13. print("📋 可用工具:")
  14. result = github_tool.run({"action": "list_tools"})
  15. print(result)
  16. # 2. 搜索仓库
  17. print("\n🔍 搜索仓库:")
  18. result = github_tool.run({
  19. "action": "call_tool",
  20. "tool_name": "search_repositories",
  21. "arguments": {
  22. "query": "AI agents language:python",
  23. "page": 1,
  24. "perPage": 3
  25. }
  26. })
  27. print(result)