Template Explanation
Let's look at how the template code works and review how you will update the code later.
There are three main parts to understand:
The SQLite database and how to update it
The MCP server and how to update it
The client code for testing changes before publishing
The SQLite Database
The template uses an SQLite database to manage custom content for use with the MCP server. One way of loading your own data into a database is by providing a CSV file of your data, like the example provided with ai_news.csv.
We can then convert the CSV file of data into an SQLite database table using the generate_db.py program. Let's break down how this program works and how you can adapt it.
Above we simply provide 1) the CSV filename to read the data from and 2) a name for the SQLite database that will be created. Once you create your own CSV file for a table, you can change these two names appropriately.
Next, let's look at how the database table columns are defined to match the CSV data.
Above we use SQL ( CREATE TABLE ) to properly define the table name and columns. You want this SQL statement to map to the data you are providing in the CSV file. Don't forget to use appropriate data types (e.g. TEXT, INTEGER, etc)
Next, we will again ensure the Python program is mapping to the CSV data to read the data correctly and write it, row by row, to the database table.
Above you will see that 1) the row keys (e.g. release_date in row["release_date"],) match the CSV column labels and 2) the SQL INSERT OR REPLACE INTO statement uses the correct table name and column labels.
If you provide custom CSV file and update the python program correctly, you can then run the generate_db.py program using python generate_db.py in the terminal of Github codespaces (or your programming environment) to make your custom database. If all goes well, you should see a message of success in the terminal.
The MCP Server Code
Let's look at two important parts of the MCP server code (server.py) — 1) we connect to the database and 2) define tools the MCP server will offer an LLM in a chat conversation.
First, we name our MCP server and connect to the SQLite database.
Above the title of the server ("AI and Robotics News Server") is defined. This is description is important, because the LLM will use this title to understand how your server can be used in a chat. When you are ready to adapt the template server provide an appropriate title and correct database filename.
Next, let's look at how a tool is defined. you will want to change the tool definitions to match your database and intended features. Below is a single example.
Above you see the definition of one MCP tool get_latest_stories() that simply 1) connects to the database, 2) retrieves the latest 5 news stories and 3) returns it as a list (array). Notice that a tool should have a very clear description (e.g. Returns the latest 5 stories based on release date.) This description helps the LLM use the appropriate tool at the appropriate time.
Note: An MCP server can have many tools available for the LLM to use as needed. We are just looking at one as an example.
For any tool you create that connects to your database, you will want to carefully contstruct the SQL and use the appropriate Python code to return content to the LLM. You will usually choose to return one of the following types of content that is compatible with JSON: string, dict (e.g. object with key-value pairs), or list (array of items).
Next, get started with developing your MCP server by modifying the template.
Last updated

