Example Guide:
This guide demonstrates how to create an AI agent that can perform actions on GitHub, such as starring a repository, using OpenAI’s tool-calling feature and Universal MCP tools. This example is based onexamples/github.py.
Objective
Build an agent that can, when asked to “Star the repository username/repo_name”:- Understand the request involves a GitHub action.
- Identify the correct GitHub tool (e.g.,
github_star_repository). - Extract the repository name.
- Call the tool to star the repository.
- Confirm the action to the user.
Steps
-
Set up the GitHub Application:
Load the
githubapplication from Universal MCP, likely usingapp_from_slugand configuring its integration (e.g.,AgentRIntegrationfor credentials managed by AgentR).Self-note: The examplegithub.pyusestool_names=["github_star_repository"]andtags=["repository"]. The actual available tools and their tags depend on thegithubapp’s implementation. -
Initialize OpenAI Client and ToolManager:
-
Get Tools in OpenAI Format:
Retrieve the list of tools formatted for the OpenAI API.
-
Prepare Conversation and Make Initial API Call:
-
Handle Tool Calls:
If
response_message.tool_callsexists, iterate through them, execute the tools usingtool_manager.call_tool, and append results.Thegithub.pyexample directly processes the tool call and prints the result without necessarily sending it back to the model for a final summarization, but the structure for doing so is shown above.
How It Works
- The user’s request (“Star the repository…”) is sent to the OpenAI model along with the definitions of available GitHub tools (obtained from MCP).
- The OpenAI model identifies that the
github_star_repositorytool is appropriate and determines the arguments (e.g.,ownerandrepo, or a combinedrepository_full_namedepending on the tool’s schema). - The application code receives the
tool_callsobject. - It uses the
function_nameandfunction_argumentsto invoke the corresponding MCP tool viatool_manager.call_tool(). - The
githubMCP Application handles the actual API interaction with GitHub. - The result of the tool call is then processed (either printed or sent back to the LLM for a more conversational response).