server.py•1.32 kB
from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP
from db import *
import os
from dotenv import load_dotenv
load_dotenv()
# Initialize FastMCP server
mcp = FastMCP("car_retail_company database")
@mcp.tool()
async def run_query(query:str):
"""
runs the query on car_retail_company database.
the database has one table called cars.
the following is the database schema:
'
cars (
car_id INT AUTO_INCREMENT PRIMARY KEY,
brand VARCHAR(50) NOT NULL,
model VARCHAR(50) NOT NULL,
color VARCHAR(30) NOT NULL,
car_condition ENUM('new', 'used', 'certified_pre_owned') NOT NULL,
mileage INT NOT NULL,
price DECIMAL(10, 2) NOT NULL,
owner_email VARCHAR(100) NOT NULL,
date_added TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX (brand),
INDEX (model),
INDEX (price)
'
Parameters:
- query: the query which is run on the database
returns:
dict: A structured response with metadata and formatted data
"""
results, description = execute_mysql_query(query)
return str(format_results_for_llm(query,results, description))
if __name__ == "__main__":
# Initialize and run the server
mcp.run(transport='stdio')