sample-mcp
The Sample MCP Server is designed to connect to a PostgreSQL database, providing features for managing accounts, categories, and transactions. Built with Go and GORM, it supports Docker for development and testing, and uses Mage for build automation.
Overview
A sample MCP (Model Context Protocol) server that connects to a PostgreSQL database. It uses Go with GORM for database operations and PostgreSQL for data storage.
Features
- Account management (create, read, update, delete)
- Category management (create, read, update, delete)
- Transaction tracking (create, read, update, delete)
- Transaction aggregation (sum, count by account)
Project Structure
compose/
- Docker Compose configuration for local developmentdb/
- Database related codeentity/
- Data model definitionsmigrations/
- Database migration scriptsrepository/
- Data access layer implementations
pkg/
- Shared packages and utilitiesvendor/
- Vendored dependencies
Data Model
- Account: Represents financial accounts with ID, name, and type
- Category: Represents transaction categories with ID, name, and type
- Transaction: Represents financial transactions with amount, date, description, and relationships to accounts and categories
Prerequisites
- Go 1.24 or higher (as specified in go.mod)
- Mage build tool
- Docker and Docker Compose
- PostgreSQL (or use the provided Docker setup)
Getting Started
Setup with Docker
- Clone the repository
- Start the PostgreSQL database
- Build and run the application
Development Mode
To start the application in development mode:
Testing
- Running Unit Tests
- Running Integration Tests
Build Commands
mage build
- Build the application using GoReleasermage compilebuild
- Build using standard Go buildmage test
- Run unit testsmage integrationtest
- Run integration testsmage lint
- Run lintermage dev
- Build and start Docker services
Configuration
Configuration File
The application can be configured using a config.yml
file. A sample configuration file is provided in config.yml.sample
.
Environment Variable
Specify the path to the configuration file using the MCP_SERVER_CONFIG
environment variable.
Database Configuration
The PostgreSQL database is configured with default settings for type, host, port, user, password, database, timeout, max idle connections, and max open connections.
License
This project is licensed under the MIT License.