This is a first PR for #159 - adding some validation scripts. I want to get to a place where we are confident that making schema changes is in sync with the rest of our code. Step one is making sure the schemas are in sync with our examples. Step two will be making sure the schemas are in sync with our actual Registry implementation code. This is just for the JSON right now; if we're feeling good about this approach I'll do an analogous change for the OpenAPI schemas as well. I'll also follow with adding usage of these scripts to our CI pipeline so we have automated checks on them with every change. ## Summary - Added CLI validation tools for JSON schemas and examples in `docs/server-json/` - Fixed some minor validation errors found in `examples.md` - Ensures schema consistency and example validity in CI/CD pipelines ## Changes ### New Validation Tools 1. **`tools/validate-schemas`** - Validates that `schema.json` and `registry-schema.json` are valid JSON Schema documents 2. **`tools/validate-examples`** - Validates all JSON examples in `examples.md` against both schemas ### Key Features - ✅ Validates JSON schema syntax and structure - ✅ Validates all examples against both base and registry schemas - ✅ Tracks validation counts to prevent silent failures - ✅ Proper exit codes for CI integration - ✅ Clear error messages for debugging ### Fixes to examples.md - Added missing `repository.id` field in NuGet example - Changed `repository.source` from "gitlab" to "github" in Docker example ### Usage ```bash # From repository root ./tools/validate-schemas.sh ./tools/validate-examples.sh ``` ## Testing I ran these scripts locally with minor (breaking) changes, which they each correctly reported. As submitted, they are both passing. 🤖 Co-authored with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Charles Lowell <10964656+chlowell@users.noreply.github.com>
53 lines
1.9 KiB
Go
53 lines
1.9 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/modelcontextprotocol/registry/internal/model"
|
|
)
|
|
|
|
// Common database errors
|
|
var (
|
|
ErrNotFound = errors.New("record not found")
|
|
ErrAlreadyExists = errors.New("record already exists")
|
|
ErrInvalidInput = errors.New("invalid input")
|
|
ErrDatabase = errors.New("database error")
|
|
ErrInvalidVersion = errors.New("invalid version: cannot publish older version after newer version")
|
|
)
|
|
|
|
// Database defines the interface for database operations on MCPRegistry entries
|
|
type Database interface {
|
|
// List retrieves all MCPRegistry entries with optional filtering
|
|
List(ctx context.Context, filter map[string]any, cursor string, limit int) ([]*model.Server, string, error)
|
|
// GetByID retrieves a single ServerDetail by it's ID
|
|
GetByID(ctx context.Context, id string) (*model.ServerDetail, error)
|
|
// Publish adds a new ServerDetail to the database
|
|
Publish(ctx context.Context, serverDetail *model.ServerDetail) error
|
|
// ImportSeed imports initial data from a seed file
|
|
ImportSeed(ctx context.Context, seedFilePath string) error
|
|
// Close closes the database connection
|
|
Close() error
|
|
}
|
|
|
|
// ConnectionType represents the type of database connection
|
|
type ConnectionType string
|
|
|
|
const (
|
|
// ConnectionTypeMemory represents an in-memory database connection
|
|
ConnectionTypeMemory ConnectionType = "memory"
|
|
// ConnectionTypeMongoDB represents a MongoDB database connection
|
|
ConnectionTypeMongoDB ConnectionType = "mongodb"
|
|
)
|
|
|
|
// ConnectionInfo provides information about the database connection
|
|
type ConnectionInfo struct {
|
|
// Type indicates the type of database connection
|
|
Type ConnectionType
|
|
// IsConnected indicates whether the database is currently connected
|
|
IsConnected bool
|
|
// Raw provides access to the underlying connection object, which will vary by implementation
|
|
// For MongoDB, this will be *mongo.Client
|
|
// For MemoryDB, this will be map[string]*model.MCPRegistry
|
|
Raw any
|
|
}
|