readme.md•1.6 kB
# Data Engineer Agent with MCP Server
In this project I developed an AI agent that can manipulate a database of retail cars using SQL. The agent can add new ads or show the existing cars according to the user preference.
The code is split into three files:
## dp.py
All the code relating to the SQL cursor and the LLM parser are located in this file. The execute_mysql_query runs the query and if it is a select query, it returns the results. The results of this function are passed to format_results_for_llm function to convert into a dict format using column headers for the llm to understand.
## Server.py
This file is our MPC server connected to the database. The tool run_query is responsible for running the query on the database and provides the model with the schema for the database table.
## agent.ipynb
This is the client for the server. I used **LangChain MCP Adapters** to convert the tools in the MCP server to LangChain tools and created a simple react agent. The code demonstrates two examples:
### Example 1
In this example, the user wanted to buy a Toyota and the agent searched the database for Toyota cars and listed the results.
### Example 2
In this example, the user wanted to sell a Ferrari. However, they did not provide enough information to the agent so the agent asked the user to complete the information and once it had enough information to fill every field it needed, it added the add to the database.
## Disclamer
**LangChain MCP Adapters** is a fairly new package so I could not get it to work in a clean way. Maybe future updates can solve its issues.