Refactor database implementation to use PostgreSQL instead of MongoDB (#289)

Fixes #228

## Motivation and Context

See #19

## How Has This Been Tested?

- Run locally
- Run in docker compose
- Run infra in minikube
- Unit and integration tests all passing :)

## Breaking Changes

Yes: users will not be able to access any data they used to have in
custom mongodb. We are accepting this breaking change, given the
registry is in experimental development status.

## Types of changes
<!-- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [x] I have read the [MCP
Documentation](https://modelcontextprotocol.io)
- [x] My code follows the repository's style guidelines
- [x] New and existing tests pass locally
- [x] I have added appropriate error handling
- [x] I have added or updated documentation as needed

## Additional context

I have not implemented connection pooling support for simplicity, and
because cloudnative-pg already provides built-in connection pooling with
pgBouncer so if we want it later we can switch to this endpoint easily.
This commit is contained in:
adam jones 2025-08-22 01:40:28 +01:00 • committed by GitHub
commit ebaf4c9c99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,7 +24,7 @@ The MCP Registry service provides a centralized repository for MCP server entrie
- Health check endpoint for service monitoring
- Support for various environment configurations
- Graceful shutdown handling
- MongoDB and in-memory database support
- PostgreSQL and in-memory database support
- Comprehensive API documentation
- Pagination support for listing registry entries
- Seed data export/import composability with HTTP support
@ -35,7 +35,7 @@ The MCP Registry service provides a centralized repository for MCP server entrie
### Prerequisites
- Go 1.24.x (required - check with `go version`)
- MongoDB
- PostgreSQL
- Docker (optional, but recommended for development)
For development:
@ -46,14 +46,13 @@ For development:
## Running
The easiest way to get the registry running is uses docker compose. This will setup the MCP Registry service, import the seed data and run MongoDB in a local Docker environment.
The easiest way to get the registry running is uses docker compose. This will setup the MCP Registry service, import the seed data and run PostgreSQL in a local Docker environment.
```bash
# Run the registry and MongoDB with docker compose
make dev-compose
```
This will start the MCP Registry service and MongoDB with Docker, running at [`localhost:8080`](http://localhost:8080).
This will start the MCP Registry service running at [`localhost:8080`](http://localhost:8080).
## Building
@ -63,15 +62,15 @@ If you prefer to run the service locally without Docker, you can build and run i
# Build a registry executable
make build
```
This will create the `registry` binary in the current directory. You'll need to have MongoDB running locally or with Docker.
This will create the `registry` binary in the current directory.
To run the service locally:
```bash
# Run registry locally (requires MongoDB)
# Run registry locally
make dev-local
```
By default, the service will run on [`localhost:8080`](http://localhost:8080).
By default, the service will run on [`localhost:8080`](http://localhost:8080). You'll need to use the in-memory database or have PostgreSQL running.
To build the CLI tool for publishing MCP servers to the registry:
@ -95,11 +94,12 @@ Key development commands:
```bash
# Development
make dev-compose # Start development environment with Docker Compose
make dev-local # Run registry locally (requires MongoDB)
make dev-local # Run registry locally
# Build targets
make build # Build the registry application
make publisher # Build the publisher tool
make migrate # Build the database migration tool
# Testing
make test-unit # Run unit tests with coverage report
@ -156,7 +156,7 @@ This will prevent commits that fail linting or have formatting issues.
│ ├── api/ # HTTP server and request handlers (routing)
│ ├── auth/ # GitHub OAuth integration
│ ├── config/ # Configuration management
│ ├── database/ # Data persistence abstraction (MongoDB and in-memory)
│ ├── database/ # Data persistence abstraction
│ ├── model/ # Data models and domain structures
│ └── service/ # Business logic implementation
├── pkg/ # Public libraries
@ -175,9 +175,9 @@ This will prevent commits that fail linting or have formatting issues.
5. JSON responses returned to clients
### Key Interfaces
- **Database Interface** (`internal/database/database.go`) - Abstracts data persistence with MongoDB and memory implementations
- **Database Interface** (`internal/database/database.go`) - Abstracts data persistence with PostgreSQL and in-memory implementations
- **RegistryService** (`internal/service/service.go`) - Business logic abstraction over database
- **Auth Service** (`internal/auth/auth.go`) - GitHub OAuth token validation
- **Auth Service** (`internal/auth/jwt.go`) - Registry token creation and validation
### Authentication Flow
Publishing requires GitHub OAuth validation: