Зміст курсу
Creating Custom AI Agents
Creating Custom AI Agents
Creating Simple MCP Server
You'll build a minimal Model Context Protocol (MCP) server using Python. The server will read data from an Excel file and return it in JSON format. This type of setup allows tools like Claude Desktop or any MCP-compatible client to trigger external logic—like reading a spreadsheet—by sending structured JSON requests. Your goal is to create a Flask-based HTTP endpoint that:
Accepts a file and sheet name via JSON;
Loads the specified Excel sheet;
Returns the first 5 rows in a JSON response.
This structure allows AI to interact with your logic through a clean interface, using context to decide which function to call and what data to request. Start by importing the required libraries and initializing the Flask app:
file1
Next, define a route that listens for POST requests. This route reads the Excel file and sheet specified in the request body.
file1
Reads the incoming JSON request with request.get_json();
Looks for "file" and "sheet" keys. If "sheet" isn’t provided, it defaults to the first sheet;
Opens the Excel file using load_workbook;
Reads up to 5 rows using iter_rows(values_only=True) and converts them into a list of lists;
Returns the rows as a JSON response.
Finally, add the code that starts the Flask server:
file1
Run this script. The server will be available at http://localhost:5000/read_excel
.
file1
This server acts as a basic MCP-compatible tool. When connected to Claude Desktop or any AI agent that understands MCP, your endpoint can be triggered by natural language like:
Claude (or another model) will format a JSON request, send it to your server, and use the returned data in its reply. You're not just building an API you're enabling structured, AI-friendly tooling that bridges natural language and local logic.
Дякуємо за ваш відгук!