From the course: Hands-On AI: Building AI Agents with Model Context Protocol (MCP) and Agent2Agent (A2A)

Execute the HR timeoff agent with MCP

- [Instructor] Let's now proceed to execute the HR timeoff agent system. First, we need to start the MCP server. We can do this by running the timeoff_db_server.py file. We see that the service is started and listening on port 8000. Next, we need to run the MCP client. We do so by running the timeoff_agent.py file. On executing, we see that it is executing the first query, namely, Get the timeoff balance for Alice. It gets the list of tools and the prompt. It is then able to query the database and retrieve the current balance. The value is 15 days. This is the data we used in the seed process for the database. We then create a timeoff request for five days. The process is then repeated. Now the request timeoff tool is created to create a timeoff request. It was able to file the request correctly for five days. When we issue a query for the timeoff balance again, we get only 10 days. This is because the balance is reduced by five based on the previous request. One thing you may notice is that we are creating the React agent for each request, so the list of tools and prompts are fetched again and again. We could also create the React agent once and reuse it for new requests. Let's also inspect the logs of the timeoff DB server. We see multiple POST and GET requests coming in as part of the MCP protocol handshake. We see the request for prompt and the actual tool execution logs. This example demonstrates how MCP would work in an AI agent scenario using HTTP.

Contents