A Template MCP Server

by Alexander-Nestor-Bergmann

265 downloads Not rated yet MIT license
GitHub

About

A Template MCP Server is an example implementation of a Model Context Protocol (MCP) server that demonstrates how to connect AI agents and services (like Claude) to external data sources. It uses a PostgreSQL database backend to manage user data and exposes simple tools for user…

Details

License
MIT license

Explore

- Defines and exposes custom tools via the MCP standard.
- Handles requests from MCP clients and translates them into database operations.
- Returns structured results or errors to the client.
- Includes four example tools: add, list, find, and delete users.
- Uses async PostgreSQL connection via SQLAlchemy with asyncpg driver.
- Configurable via environment variables (e.g., DB_URL, DB_HOST, DB_PORT).

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name A Template MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Python 3.10+
Access to a PostgreSQL database. The server needs connection details.
Docker (recommended for running the server easily).
uv (for local development dependency management).

python -m venv .venv
source .venv/bin/activate # or .\.venv\Scripts\activate on Windows

uv pip install -e .[dev]

2.  Set Environment Variables: Ensure the required DB_URL is set in your shell environment or is present in a .env file in the root directory (dotenv is used).
3. Run the Server:
bash
uv run python sqlmcp/server.py
```
(The server will use host/port from environment variables or defaults)

To illustrate how tools are defined and exposed, this server implements the following example functions for interacting with the user database:

add_user: Adds a new user to the database.
Parameters: name (string), email (string)
Returns: Confirmation message (string) or error.
get_all_users: Retrieves a list of all users from the database.
Parameters: None
Returns: List of user objects (each a dictionary with id, name, email) or error.
find_user_by_email: Finds a specific user by their email address.
Parameters: email (string)
Returns: A single user object (dictionary) or an error if not found.
delete_user_by_email: Deletes a user from the database based on their email address.
Parameters: email (string)
Returns: Confirmation message (string) or error.

These tools serve as concrete examples of the kinds of operations an MCP server might provide access to.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "a template mcp server": {
            "agents-mcp-demo": {
                "command": "docker",
                "args": [
                    "build",
                    "-t",
                    "sql-mcp-demo-server",
                    "--build-arg",
                    "PORT=${DB_PORT:-8051}",
                    "."
                ]
            }
        }
    }
}

McpServers

{
    "agents-mcp-demo": {
        "command": "docker",
        "args": [
            "build",
            "-t",
            "sql-mcp-demo-server",
            "--build-arg",
            "PORT=${DB_PORT:-8051}",
            "."
        ]
    }
}

This repository serves as a template, demonstrating how to implement an MCP (Model Context Protocol) server - an open standard designed to connect AI agents and services (like Claude) to tools and data sources. The primary goal of this repository is to illustrate how to build, configure, and run a basic MCP server. The tools are simplified examples and not intended for production use.

This specific example server uses a simple PostgreSQL database backend to manage user data, showcasing how MCP can bridge the gap between AI agents and external resources.

Overview

The server acts as a secure gateway between an MCP client (e.g., an AI agent) and an external data source (in this case, a toy PostgreSQL database containing a users table). It demonstrates how to:

Define and expose custom tools via the MCP standard.
Handle requests from an MCP client.
Translate those requests into operations on the backend resource (e.g., database queries).
Return structured results or errors back to the client.

The demo users table used in this example has the following structure:
id (integer, primary key)
name (text)
email (text, unique)

Example Tools Exposed by the Server

To illustrate how tools are defined and exposed, this server implements the following example functions for interacting with the user database:

add_user: Adds a new user to the database.
Parameters: name (string), email (string)
Returns: Confirmation message (string) or error.
get_all_users: Retrieves a list of all users from the database.
Parameters: None
Returns: List of user objects (each a dictionary with id, name, email) or error.
find_user_by_email: Finds a specific user by their email address.
Parameters: email (string)
Returns: A single user object (dictionary) or an error if not found.
delete_user_by_email: Deletes a user from the database based on their email address.
Parameters: email (string)
Returns: Confirmation message (string) or error.

These tools serve as concrete examples of the kinds of operations an MCP server might provide access to.

Prerequisites

Python 3.10+
Access to a PostgreSQL database. The server needs connection details.
Docker (recommended for running the server easily).

  • uv (for local development dependency management).


Configuration

Environment variables are used to configure the database connection and server settings. Copy the .env.example file to .env and update the values:

```bash
cp .env.example .env

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.