<!-- Provide a brief summary of your changes -->
Add support for specifying database type (MongoDB or in-memory
database).
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
The README states that MCP Registry supports both MongoDB and in-memory
databases, but does not provide the capability to specify which database
type to use.
5d9171bdcc/README.md (L19)
This PR addresses this limitation by adding explicit database type
configuration through the `DATABASE_TYPE` environment variable, allowing
users to choose between `mongodb` and `memory` database types in a
standardized way.
## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Yes
```console
$ export MCP_REGISTRY_DATABASE_TYPE="memory"
$ ./scripts/test_endpoints.sh
Testing health endpoint: http://localhost:8080/v0/health
Status Code: 200
Response:
{
"status": "ok",
"github_client_id": ""
}
Health check successful
-------------------------------------
Testing servers endpoint: http://localhost:8080/v0/servers
Status Code: 200
Response Summary:
Total registries: 0
servers Names:
Pagination Metadata:
{}
servers Details:
{
"servers": [],
"metadata": {}
}
servers request successful
-------------------------------------
Testing ping endpoint: http://localhost:8080/v0/ping
Status Code: 200
Response:
{
"status": "ok",
"version": "dev"
}
Ping successful
-------------------------------------
All tests passed successfully!
```
## Breaking Changes
<!-- Will users need to update their code or configurations? -->
No
## 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)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] 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
<!-- Add any other context, implementation notes, or design decisions
-->
Close #63
---------
Co-authored-by: Avinash Sridhar <sridharavinash@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
39 lines
1.3 KiB
Go
39 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
env "github.com/caarlos0/env/v11"
|
|
)
|
|
|
|
type DatabaseType string
|
|
|
|
const (
|
|
DatabaseTypeMongoDB DatabaseType = "mongodb"
|
|
DatabaseTypeMemory DatabaseType = "memory"
|
|
)
|
|
|
|
// Config holds the application configuration
|
|
type Config struct {
|
|
ServerAddress string `env:"SERVER_ADDRESS" envDefault:":8080"`
|
|
DatabaseType DatabaseType `env:"DATABASE_TYPE" envDefault:"mongodb"`
|
|
DatabaseURL string `env:"DATABASE_URL" envDefault:"mongodb://localhost:27017"`
|
|
DatabaseName string `env:"DATABASE_NAME" envDefault:"mcp-registry"`
|
|
CollectionName string `env:"COLLECTION_NAME" envDefault:"servers_v2"`
|
|
LogLevel string `env:"LOG_LEVEL" envDefault:"info"`
|
|
SeedFilePath string `env:"SEED_FILE_PATH" envDefault:"data/seed.json"`
|
|
SeedImport bool `env:"SEED_IMPORT" envDefault:"true"`
|
|
Version string `env:"VERSION" envDefault:"dev"`
|
|
GithubClientID string `env:"GITHUB_CLIENT_ID" envDefault:""`
|
|
GithubClientSecret string `env:"GITHUB_CLIENT_SECRET" envDefault:""`
|
|
}
|
|
|
|
// NewConfig creates a new configuration with default values
|
|
func NewConfig() *Config {
|
|
var cfg Config
|
|
err := env.ParseWithOptions(&cfg, env.Options{
|
|
Prefix: "MCP_REGISTRY_",
|
|
})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &cfg
|
|
}
|