Implement flattened _meta format for server extensions (#331)
## Summary This PR implements the flattened `_meta` format for server extensions as discussed in #284, replacing the confusing wrapper format with a clean single-file approach. **Before (wrapper format):** ```json { "server": { "name": "my-server", "description": "..." }, "x-publisher": { "build_info": "..." }, "x-io.modelcontextprotocol.registry": { "id": "...", "published_at": "..." } } ``` **After (flattened format):** ```json { "name": "my-server", "description": "...", "_meta": { "publisher": { "build_info": "..." }, "io.modelcontextprotocol.registry": { "id": "...", "published_at": "..." } } } ``` ## Key Changes - **Flattened Format**: Single `ServerJSON` file with structured `_meta` field - **Better DX**: Publishers maintain one file instead of separate server.json + extensions.json - **MCP Compliance**: Uses standard `_meta` mechanism instead of `x-*` prefixes - **Simplified Database**: PostgreSQL now uses simple `id, value` table structure - **Type Safety**: Structured `ServerMeta` with known extension fields ## Database Migration Added migration `003_simplify_to_key_value.sql` that drops the complex relational structure and creates a simple key-value table. This significantly simplifies database management. ## Testing - All core tests passing (validators, service layer) - Schema validation working for all 10 examples - Seed data successfully migrated (396 entries) - Publishing functionality verified Fixes #284
This commit is contained in:
parent
be036a45ea
commit
218b0b422d
31 changed files with 19375 additions and 19670 deletions
|
|
@ -11,10 +11,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
"github.com/modelcontextprotocol/registry/pkg/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func InitCommand() error {
|
func InitCommand() error {
|
||||||
// Check if server.json already exists
|
// Check if server.json already exists
|
||||||
if _, err := os.Stat("server.json"); err == nil {
|
if _, err := os.Stat("server.json"); err == nil {
|
||||||
|
|
@ -266,7 +266,7 @@ func createServerJSON(
|
||||||
name, description, version, repoURL, repoSource,
|
name, description, version, repoURL, repoSource,
|
||||||
packageType, packageIdentifier, packageVersion string,
|
packageType, packageIdentifier, packageVersion string,
|
||||||
envVars []model.KeyValueInput,
|
envVars []model.KeyValueInput,
|
||||||
) model.ServerJSON {
|
) apiv0.ServerJSON {
|
||||||
// Determine registry type and base URL
|
// Determine registry type and base URL
|
||||||
var registryType, registryBaseURL string
|
var registryType, registryBaseURL string
|
||||||
switch packageType {
|
switch packageType {
|
||||||
|
|
@ -297,7 +297,7 @@ func createServerJSON(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create server structure
|
// Create server structure
|
||||||
return model.ServerJSON{
|
return apiv0.ServerJSON{
|
||||||
Schema: "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json",
|
Schema: "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json",
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: description,
|
Description: description,
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func PublishCommand(args []string) error {
|
func PublishCommand(args []string) error {
|
||||||
|
|
@ -30,7 +32,7 @@ func PublishCommand(args []string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate JSON
|
// Validate JSON
|
||||||
var serverJSON map[string]any
|
var serverJSON apiv0.ServerJSON
|
||||||
if err := json.Unmarshal(serverData, &serverJSON); err != nil {
|
if err := json.Unmarshal(serverData, &serverJSON); err != nil {
|
||||||
return fmt.Errorf("invalid server.json: %w", err)
|
return fmt.Errorf("invalid server.json: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -73,26 +75,14 @@ func PublishCommand(args []string) error {
|
||||||
|
|
||||||
func publishToRegistry(registryURL string, serverData []byte, token string) error {
|
func publishToRegistry(registryURL string, serverData []byte, token string) error {
|
||||||
// Parse the server JSON data
|
// Parse the server JSON data
|
||||||
var serverDetails map[string]any
|
var serverJSON apiv0.ServerJSON
|
||||||
err := json.Unmarshal(serverData, &serverDetails)
|
err := json.Unmarshal(serverData, &serverJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing server.json file: %w", err)
|
return fmt.Errorf("error parsing server.json file: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the publish request payload
|
|
||||||
var publishReq map[string]any
|
|
||||||
if _, hasServerField := serverDetails["server"]; hasServerField {
|
|
||||||
// Already in PublishRequest format
|
|
||||||
publishReq = serverDetails
|
|
||||||
} else {
|
|
||||||
// Wrap in server field
|
|
||||||
publishReq = map[string]any{
|
|
||||||
"server": serverDetails,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert to JSON
|
// Convert to JSON
|
||||||
jsonData, err := json.Marshal(publishReq)
|
jsonData, err := json.Marshal(serverJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error serializing request: %w", err)
|
return fmt.Errorf("error serializing request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/modelcontextprotocol/registry/internal/database"
|
"github.com/modelcontextprotocol/registry/internal/database"
|
||||||
"github.com/modelcontextprotocol/registry/internal/service"
|
"github.com/modelcontextprotocol/registry/internal/service"
|
||||||
"github.com/modelcontextprotocol/registry/internal/telemetry"
|
"github.com/modelcontextprotocol/registry/internal/telemetry"
|
||||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -46,7 +46,7 @@ func main() {
|
||||||
// Initialize services based on environment
|
// Initialize services based on environment
|
||||||
switch cfg.DatabaseType {
|
switch cfg.DatabaseType {
|
||||||
case config.DatabaseTypeMemory:
|
case config.DatabaseTypeMemory:
|
||||||
db = database.NewMemoryDB(map[string]*model.ServerJSON{})
|
db = database.NewMemoryDB(map[string]*apiv0.ServerJSON{})
|
||||||
registryService = service.NewRegistryServiceWithDB(db)
|
registryService = service.NewRegistryServiceWithDB(db)
|
||||||
case config.DatabaseTypePostgreSQL:
|
case config.DatabaseTypePostgreSQL:
|
||||||
// Use PostgreSQL for real registry service
|
// Use PostgreSQL for real registry service
|
||||||
|
|
|
||||||
35776
data/seed.json
35776
data/seed.json
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -370,6 +370,23 @@
|
||||||
"items": {
|
"items": {
|
||||||
"$ref": "#/$defs/Remote"
|
"$ref": "#/$defs/Remote"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"_meta": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Extension metadata using reverse DNS namespacing for vendor-specific data",
|
||||||
|
"additionalProperties": true,
|
||||||
|
"properties": {
|
||||||
|
"publisher": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Publisher-provided metadata for downstream registries",
|
||||||
|
"additionalProperties": true
|
||||||
|
},
|
||||||
|
"io.modelcontextprotocol.registry": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Official MCP registry metadata (read-only, added by registry)",
|
||||||
|
"additionalProperties": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ServerResponse'
|
$ref: '#/components/schemas/ServerDetail'
|
||||||
'404':
|
'404':
|
||||||
description: Server not found
|
description: Server not found
|
||||||
content:
|
content:
|
||||||
|
|
@ -81,54 +81,54 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/PublishRequest'
|
$ref: '#/components/schemas/ServerDetail'
|
||||||
examples:
|
examples:
|
||||||
basic_server:
|
basic_server:
|
||||||
summary: Basic server with NPM package
|
summary: Basic server with NPM package
|
||||||
value:
|
value:
|
||||||
server:
|
name: "io.modelcontextprotocol/filesystem"
|
||||||
name: "io.modelcontextprotocol/filesystem"
|
description: "Node.js server implementing Model Context Protocol (MCP) for filesystem operations."
|
||||||
description: "Node.js server implementing Model Context Protocol (MCP) for filesystem operations."
|
status: "active"
|
||||||
status: "active"
|
repository:
|
||||||
repository:
|
url: "https://github.com/modelcontextprotocol/servers"
|
||||||
url: "https://github.com/modelcontextprotocol/servers"
|
source: "github"
|
||||||
source: "github"
|
version_detail:
|
||||||
version_detail:
|
version: "1.0.2"
|
||||||
|
packages:
|
||||||
|
- registry_type: "npm"
|
||||||
|
registry_base_url: "https://registry.npmjs.org"
|
||||||
|
identifier: "@modelcontextprotocol/server-filesystem"
|
||||||
version: "1.0.2"
|
version: "1.0.2"
|
||||||
packages:
|
_meta:
|
||||||
- registry_type: "npm"
|
publisher:
|
||||||
registry_base_url: "https://registry.npmjs.org"
|
tool: "publisher-cli"
|
||||||
identifier: "@modelcontextprotocol/server-filesystem"
|
version: "1.2.3"
|
||||||
version: "1.0.2"
|
build_info:
|
||||||
x-publisher:
|
commit: "abc123def456"
|
||||||
tool: "publisher-cli"
|
timestamp: "2023-12-01T10:30:00Z"
|
||||||
version: "1.2.3"
|
|
||||||
build_info:
|
|
||||||
commit: "abc123def456"
|
|
||||||
timestamp: "2023-12-01T10:30:00Z"
|
|
||||||
example_org_server:
|
example_org_server:
|
||||||
summary: Server with example.com organization extensions
|
summary: Server with example.com organization extensions
|
||||||
value:
|
value:
|
||||||
server:
|
name: "com.example/demo-server"
|
||||||
name: "com.example/demo-server"
|
description: "Example MCP server demonstrating publisher extensions."
|
||||||
description: "Example MCP server demonstrating publisher extensions."
|
status: "active"
|
||||||
status: "active"
|
repository:
|
||||||
repository:
|
url: "https://github.com/example/mcp-demo"
|
||||||
url: "https://github.com/example/mcp-demo"
|
source: "github"
|
||||||
source: "github"
|
version_detail:
|
||||||
version_detail:
|
version: "1.0.0"
|
||||||
|
packages:
|
||||||
|
- registry_type: "npm"
|
||||||
|
registry_base_url: "https://registry.npmjs.org"
|
||||||
|
identifier: "@example/mcp-demo-server"
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
packages:
|
_meta:
|
||||||
- registry_type: "npm"
|
publisher:
|
||||||
registry_base_url: "https://registry.npmjs.org"
|
contact_email: "maintainer@example.com"
|
||||||
identifier: "@example/mcp-demo-server"
|
build_metadata:
|
||||||
version: "1.0.0"
|
commit: "abc123"
|
||||||
x-publisher:
|
timestamp: "2024-01-15T10:30:00Z"
|
||||||
contact_email: "maintainer@example.com"
|
com.example:
|
||||||
build_metadata:
|
|
||||||
commit: "abc123"
|
|
||||||
timestamp: "2024-01-15T10:30:00Z"
|
|
||||||
x-com.example:
|
|
||||||
marketplace_icon: "https://example.com/icon.png"
|
marketplace_icon: "https://example.com/icon.png"
|
||||||
category: ["software_development"]
|
category: ["software_development"]
|
||||||
documentation_url: "https://docs.example.org"
|
documentation_url: "https://docs.example.org"
|
||||||
|
|
@ -139,7 +139,7 @@ paths:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/ServerResponse'
|
$ref: '#/components/schemas/ServerDetail'
|
||||||
'401':
|
'401':
|
||||||
description: Unauthorized - Invalid or missing authentication token
|
description: Unauthorized - Invalid or missing authentication token
|
||||||
content:
|
content:
|
||||||
|
|
@ -261,7 +261,7 @@ components:
|
||||||
servers:
|
servers:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/ServerResponse'
|
$ref: '#/components/schemas/ServerDetail'
|
||||||
metadata:
|
metadata:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
@ -484,82 +484,53 @@ components:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Remote'
|
$ref: '#/components/schemas/Remote'
|
||||||
|
_meta:
|
||||||
ServerResponse:
|
type: object
|
||||||
description: API response format for MCP servers, including registry metadata and publisher extensions
|
description: Extension metadata using reverse DNS namespacing
|
||||||
type: object
|
properties:
|
||||||
required:
|
publisher:
|
||||||
- server
|
type: object
|
||||||
- x-io.modelcontextprotocol.registry
|
description: Publisher-specific metadata and build information
|
||||||
properties:
|
additionalProperties: true
|
||||||
server:
|
example:
|
||||||
$ref: '#/components/schemas/ServerDetail'
|
tool: "publisher-cli"
|
||||||
description: The core MCP server specification
|
version: "1.2.3"
|
||||||
x-io.modelcontextprotocol.registry:
|
build_info:
|
||||||
type: object
|
commit: "abc123def456"
|
||||||
description: Registry-specific metadata managed by the MCP registry system
|
timestamp: "2023-12-01T10:30:00Z"
|
||||||
required:
|
pipeline_id: "build-789"
|
||||||
- id
|
io.modelcontextprotocol.registry:
|
||||||
- published_at
|
type: object
|
||||||
- updated_at
|
description: Registry-specific metadata managed by the MCP registry system
|
||||||
- is_latest
|
required:
|
||||||
properties:
|
- id
|
||||||
id:
|
- published_at
|
||||||
type: string
|
- updated_at
|
||||||
format: uuid
|
- is_latest
|
||||||
description: Unique registry identifier for this server entry
|
properties:
|
||||||
example: "550e8400-e29b-41d4-a716-446655440000"
|
id:
|
||||||
published_at:
|
type: string
|
||||||
type: string
|
format: uuid
|
||||||
format: date-time
|
description: Unique registry identifier for this server entry
|
||||||
description: Timestamp when the server was first published to the registry
|
example: "550e8400-e29b-41d4-a716-446655440000"
|
||||||
example: "2023-12-01T10:30:00Z"
|
published_at:
|
||||||
updated_at:
|
type: string
|
||||||
type: string
|
format: date-time
|
||||||
format: date-time
|
description: Timestamp when the server was first published to the registry
|
||||||
description: Timestamp when the server entry was last updated
|
example: "2023-12-01T10:30:00Z"
|
||||||
example: "2023-12-01T11:00:00Z"
|
updated_at:
|
||||||
is_latest:
|
type: string
|
||||||
type: boolean
|
format: date-time
|
||||||
description: Whether this is the latest version of the server
|
description: Timestamp when the server entry was last updated
|
||||||
example: true
|
example: "2023-12-01T11:00:00Z"
|
||||||
release_date:
|
is_latest:
|
||||||
type: string
|
type: boolean
|
||||||
format: date-time
|
description: Whether this is the latest version of the server
|
||||||
description: Release date of the server version
|
example: true
|
||||||
example: "2023-12-01T10:30:00Z"
|
release_date:
|
||||||
additionalProperties: false
|
type: string
|
||||||
x-publisher:
|
format: date-time
|
||||||
type: object
|
description: Release date of the server version
|
||||||
description: Publisher-specific metadata and build information attached during publishing
|
example: "2023-12-01T10:30:00Z"
|
||||||
additionalProperties: true
|
additionalProperties: false
|
||||||
example:
|
additionalProperties: true
|
||||||
tool: "publisher-cli"
|
|
||||||
version: "1.2.3"
|
|
||||||
build_info:
|
|
||||||
commit: "abc123def456"
|
|
||||||
timestamp: "2023-12-01T10:30:00Z"
|
|
||||||
pipeline_id: "build-789"
|
|
||||||
additionalProperties: false
|
|
||||||
|
|
||||||
PublishRequest:
|
|
||||||
description: Request format for publishing MCP servers to the registry
|
|
||||||
type: object
|
|
||||||
required:
|
|
||||||
- server
|
|
||||||
properties:
|
|
||||||
server:
|
|
||||||
$ref: '#/components/schemas/ServerDetail'
|
|
||||||
description: The MCP server specification to publish
|
|
||||||
x-publisher:
|
|
||||||
type: object
|
|
||||||
description: Publisher-specific metadata and build information
|
|
||||||
additionalProperties: true
|
|
||||||
example:
|
|
||||||
tool: "publisher-cli"
|
|
||||||
version: "1.2.3"
|
|
||||||
build_info:
|
|
||||||
commit: "abc123def456"
|
|
||||||
timestamp: "2023-12-01T10:30:00Z"
|
|
||||||
pipeline_id: "build-789"
|
|
||||||
additionalProperties: false
|
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ import (
|
||||||
|
|
||||||
// EditServerInput represents the input for editing a server
|
// EditServerInput represents the input for editing a server
|
||||||
type EditServerInput struct {
|
type EditServerInput struct {
|
||||||
Authorization string `header:"Authorization" doc:"Registry JWT token with edit permissions" required:"true"`
|
Authorization string `header:"Authorization" doc:"Registry JWT token with edit permissions" required:"true"`
|
||||||
ID string `path:"id" doc:"Server ID (UUID)" format:"uuid"`
|
ID string `path:"id" doc:"Server ID (UUID)" format:"uuid"`
|
||||||
Body apiv0.PublishRequest `body:""`
|
Body apiv0.ServerJSON `body:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterEditEndpoints registers the edit endpoint
|
// RegisterEditEndpoints registers the edit endpoint
|
||||||
|
|
@ -38,7 +38,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
||||||
Security: []map[string][]string{
|
Security: []map[string][]string{
|
||||||
{"bearer": {}},
|
{"bearer": {}},
|
||||||
},
|
},
|
||||||
}, func(ctx context.Context, input *EditServerInput) (*Response[apiv0.ServerRecord], error) {
|
}, func(ctx context.Context, input *EditServerInput) (*Response[apiv0.ServerJSON], error) {
|
||||||
// Extract bearer token
|
// Extract bearer token
|
||||||
const bearerPrefix = "Bearer "
|
const bearerPrefix = "Bearer "
|
||||||
authHeader := input.Authorization
|
authHeader := input.Authorization
|
||||||
|
|
@ -63,7 +63,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify edit permissions for this server using the existing server name
|
// Verify edit permissions for this server using the existing server name
|
||||||
if !jwtManager.HasPermission(currentServer.Server.Name, auth.PermissionActionEdit, claims.Permissions) {
|
if !jwtManager.HasPermission(currentServer.Name, auth.PermissionActionEdit, claims.Permissions) {
|
||||||
return nil, huma.Error403Forbidden("You do not have edit permissions for this server")
|
return nil, huma.Error403Forbidden("You do not have edit permissions for this server")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,12 +73,12 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent renaming servers
|
// Prevent renaming servers
|
||||||
if currentServer.Server.Name != input.Body.Server.Name {
|
if currentServer.Name != input.Body.Name {
|
||||||
return nil, huma.Error400BadRequest("Cannot rename server")
|
return nil, huma.Error400BadRequest("Cannot rename server")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent undeleting servers - once deleted, they stay deleted
|
// Prevent undeleting servers - once deleted, they stay deleted
|
||||||
if currentServer.Server.Status == model.StatusDeleted && input.Body.Server.Status != model.StatusDeleted {
|
if currentServer.Status == model.StatusDeleted && input.Body.Status != model.StatusDeleted {
|
||||||
return nil, huma.Error400BadRequest("Cannot change status of deleted server. Deleted servers cannot be undeleted.")
|
return nil, huma.Error400BadRequest("Cannot change status of deleted server. Deleted servers cannot be undeleted.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ func RegisterEditEndpoints(api huma.API, registry service.RegistryService, cfg *
|
||||||
return nil, huma.Error400BadRequest("Failed to edit server", err)
|
return nil, huma.Error400BadRequest("Failed to edit server", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Response[apiv0.ServerRecord]{
|
return &Response[apiv0.ServerJSON]{
|
||||||
Body: *updatedServer,
|
Body: *updatedServer,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -45,40 +45,34 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Updated test server",
|
||||||
Description: "Updated test server",
|
Status: model.StatusDeprecated,
|
||||||
Status: model.StatusDeprecated,
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/domdomegg/test-server",
|
||||||
URL: "https://github.com/domdomegg/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "domdomegg/test-server",
|
||||||
ID: "domdomegg/test-server",
|
},
|
||||||
},
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.1",
|
||||||
Version: "1.0.1",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
// Current server (not deleted)
|
// Current server (not deleted)
|
||||||
currentServer := &apiv0.ServerRecord{
|
currentServer := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Original server",
|
||||||
Description: "Original server",
|
Status: model.StatusActive,
|
||||||
Status: model.StatusActive,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||||
|
|
||||||
expectedResponse := &apiv0.ServerRecord{
|
expectedResponse := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Updated test server",
|
||||||
Description: "Updated test server",
|
Status: model.StatusDeprecated,
|
||||||
Status: model.StatusDeprecated,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("v0.PublishRequest")).Return(expectedResponse, nil)
|
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("v0.ServerJSON")).Return(expectedResponse, nil)
|
||||||
},
|
},
|
||||||
expectedStatus: http.StatusOK,
|
expectedStatus: http.StatusOK,
|
||||||
},
|
},
|
||||||
|
|
@ -86,36 +80,32 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
name: "missing authorization header",
|
name: "missing authorization header",
|
||||||
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
authHeader: "",
|
authHeader: "",
|
||||||
requestBody: apiv0.PublishRequest{},
|
requestBody: apiv0.ServerJSON{},
|
||||||
setupMocks: func(_ *MockRegistryService) {},
|
setupMocks: func(_ *MockRegistryService) {},
|
||||||
expectedStatus: 422,
|
expectedStatus: 422,
|
||||||
expectedError: "required header parameter is missing",
|
expectedError: "required header parameter is missing",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid authorization header format",
|
name: "invalid authorization header format",
|
||||||
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
authHeader: "InvalidFormat token123",
|
authHeader: "InvalidFormat token123",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Test server",
|
||||||
Description: "Test server",
|
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
||||||
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(_ *MockRegistryService) {},
|
setupMocks: func(_ *MockRegistryService) {},
|
||||||
expectedStatus: http.StatusUnauthorized,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
expectedError: "Unauthorized",
|
expectedError: "Unauthorized",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid token",
|
name: "invalid token",
|
||||||
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
serverID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
authHeader: "Bearer invalid-token",
|
authHeader: "Bearer invalid-token",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Test server",
|
||||||
Description: "Test server",
|
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
||||||
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(_ *MockRegistryService) {},
|
setupMocks: func(_ *MockRegistryService) {},
|
||||||
expectedStatus: http.StatusUnauthorized,
|
expectedStatus: http.StatusUnauthorized,
|
||||||
|
|
@ -135,20 +125,16 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Updated test server",
|
||||||
Description: "Updated test server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
// Need to mock GetByID since we check permissions against existing server name
|
// Need to mock GetByID since we check permissions against existing server name
|
||||||
currentServer := &apiv0.ServerRecord{
|
currentServer := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Original server",
|
||||||
Description: "Original server",
|
Status: model.StatusActive,
|
||||||
Status: model.StatusActive,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||||
},
|
},
|
||||||
|
|
@ -169,21 +155,17 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.other/test-server",
|
||||||
Name: "io.github.other/test-server",
|
Description: "Updated test server",
|
||||||
Description: "Updated test server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
// Need to mock GetByID since we check permissions against existing server name
|
// Need to mock GetByID since we check permissions against existing server name
|
||||||
// This test case shows a different scenario: existing server is "other" but user only has perms for "domdomegg"
|
// This test case shows a different scenario: existing server is "other" but user only has perms for "domdomegg"
|
||||||
currentServer := &apiv0.ServerRecord{
|
currentServer := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.other/test-server",
|
||||||
Name: "io.github.other/test-server",
|
Description: "Original server",
|
||||||
Description: "Original server",
|
Status: model.StatusActive,
|
||||||
Status: model.StatusActive,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||||
},
|
},
|
||||||
|
|
@ -204,11 +186,9 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Updated test server",
|
||||||
Description: "Updated test server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(nil, database.ErrNotFound)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(nil, database.ErrNotFound)
|
||||||
|
|
@ -230,23 +210,19 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Updated test server",
|
||||||
Description: "Updated test server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
// Current server (not deleted)
|
// Current server (not deleted)
|
||||||
currentServer := &apiv0.ServerRecord{
|
currentServer := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Original server",
|
||||||
Description: "Original server",
|
Status: model.StatusActive,
|
||||||
Status: model.StatusActive,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||||
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("v0.PublishRequest")).Return(nil, errors.New("database error"))
|
registry.On("EditServer", "550e8400-e29b-41d4-a716-446655440001", mock.AnythingOfType("v0.ServerJSON")).Return(nil, errors.New("database error"))
|
||||||
},
|
},
|
||||||
expectedStatus: http.StatusBadRequest,
|
expectedStatus: http.StatusBadRequest,
|
||||||
expectedError: "Bad Request",
|
expectedError: "Bad Request",
|
||||||
|
|
@ -265,20 +241,16 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "invalid-name-format", // Missing namespace/name format
|
||||||
Name: "invalid-name-format", // Missing namespace/name format
|
Description: "Test server",
|
||||||
Description: "Test server",
|
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
||||||
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
currentServer := &apiv0.ServerRecord{
|
currentServer := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Original server",
|
||||||
Description: "Original server",
|
Status: model.StatusActive,
|
||||||
Status: model.StatusActive,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||||
},
|
},
|
||||||
|
|
@ -299,21 +271,17 @@ func TestEditServerEndpoint(t *testing.T) {
|
||||||
})
|
})
|
||||||
return "Bearer " + token
|
return "Bearer " + token
|
||||||
}(),
|
}(),
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Trying to undelete server",
|
||||||
Description: "Trying to undelete server",
|
Status: model.StatusActive,
|
||||||
Status: model.StatusActive,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
// Current server is deleted
|
// Current server is deleted
|
||||||
currentServer := &apiv0.ServerRecord{
|
currentServer := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Original server",
|
||||||
Description: "Original server",
|
Status: model.StatusDeleted,
|
||||||
Status: model.StatusDeleted,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
registry.On("GetByID", "550e8400-e29b-41d4-a716-446655440001").Return(currentServer, nil)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ import (
|
||||||
|
|
||||||
// PublishServerInput represents the input for publishing a server
|
// PublishServerInput represents the input for publishing a server
|
||||||
type PublishServerInput struct {
|
type PublishServerInput struct {
|
||||||
Authorization string `header:"Authorization" doc:"Registry JWT token (obtained from /v0/auth/token/github)" required:"true"`
|
Authorization string `header:"Authorization" doc:"Registry JWT token (obtained from /v0/auth/token/github)" required:"true"`
|
||||||
Body apiv0.PublishRequest `body:""`
|
Body apiv0.ServerJSON `body:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterPublishEndpoint registers the publish endpoint
|
// RegisterPublishEndpoint registers the publish endpoint
|
||||||
|
|
@ -34,7 +34,7 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
||||||
Security: []map[string][]string{
|
Security: []map[string][]string{
|
||||||
{"bearer": {}},
|
{"bearer": {}},
|
||||||
},
|
},
|
||||||
}, func(ctx context.Context, input *PublishServerInput) (*Response[apiv0.ServerRecord], error) {
|
}, func(ctx context.Context, input *PublishServerInput) (*Response[apiv0.ServerJSON], error) {
|
||||||
// Extract bearer token
|
// Extract bearer token
|
||||||
const bearerPrefix = "Bearer "
|
const bearerPrefix = "Bearer "
|
||||||
authHeader := input.Authorization
|
authHeader := input.Authorization
|
||||||
|
|
@ -55,7 +55,7 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that the token has permission to publish the server
|
// Verify that the token has permission to publish the server
|
||||||
if !jwtManager.HasPermission(input.Body.Server.Name, auth.PermissionActionPublish, claims.Permissions) {
|
if !jwtManager.HasPermission(input.Body.Name, auth.PermissionActionPublish, claims.Permissions) {
|
||||||
return nil, huma.Error403Forbidden("You do not have permission to publish this server")
|
return nil, huma.Error403Forbidden("You do not have permission to publish this server")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,8 +65,8 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
|
||||||
return nil, huma.Error400BadRequest("Failed to publish server", err)
|
return nil, huma.Error400BadRequest("Failed to publish server", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the published server in extension wrapper format
|
// Return the published server in flattened format
|
||||||
return &Response[apiv0.ServerRecord]{
|
return &Response[apiv0.ServerJSON]{
|
||||||
Body: *publishedServer,
|
Body: *publishedServer,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -54,18 +54,16 @@ func TestPublishIntegration(t *testing.T) {
|
||||||
v0.RegisterPublishEndpoint(api, registryService, testConfig)
|
v0.RegisterPublishEndpoint(api, registryService, testConfig)
|
||||||
|
|
||||||
t.Run("successful publish with GitHub auth", func(t *testing.T) {
|
t.Run("successful publish with GitHub auth", func(t *testing.T) {
|
||||||
publishReq := apiv0.PublishRequest{
|
publishReq := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.testuser/test-mcp-server",
|
||||||
Name: "io.github.testuser/test-mcp-server",
|
Description: "A test MCP server for integration testing",
|
||||||
Description: "A test MCP server for integration testing",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/testuser/test-mcp-server",
|
||||||
URL: "https://github.com/testuser/test-mcp-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "testuser/test-mcp-server",
|
||||||
ID: "testuser/test-mcp-server",
|
},
|
||||||
},
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,27 +90,25 @@ func TestPublishIntegration(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response apiv0.ServerRecord
|
var response apiv0.ServerJSON
|
||||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, publishReq.Server.Name, response.Server.Name)
|
assert.Equal(t, publishReq.Name, response.Name)
|
||||||
assert.Equal(t, publishReq.Server.VersionDetail.Version, response.Server.VersionDetail.Version)
|
assert.Equal(t, publishReq.VersionDetail.Version, response.VersionDetail.Version)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("successful publish with none auth (no prefix)", func(t *testing.T) {
|
t.Run("successful publish with none auth (no prefix)", func(t *testing.T) {
|
||||||
publishReq := apiv0.PublishRequest{
|
publishReq := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "com.example/test-mcp-server-no-auth",
|
||||||
Name: "com.example/test-mcp-server-no-auth",
|
Description: "A test MCP server without authentication",
|
||||||
Description: "A test MCP server without authentication",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server",
|
||||||
URL: "https://github.com/example/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server",
|
||||||
ID: "example/test-server",
|
},
|
||||||
},
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -138,18 +134,16 @@ func TestPublishIntegration(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, http.StatusOK, rr.Code)
|
assert.Equal(t, http.StatusOK, rr.Code)
|
||||||
|
|
||||||
var response apiv0.ServerRecord
|
var response apiv0.ServerJSON
|
||||||
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
err = json.Unmarshal(rr.Body.Bytes(), &response)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, publishReq.Server.Name, response.Server.Name)
|
assert.Equal(t, publishReq.Name, response.Name)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("publish fails with missing authorization header", func(t *testing.T) {
|
t.Run("publish fails with missing authorization header", func(t *testing.T) {
|
||||||
publishReq := apiv0.PublishRequest{
|
publishReq := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "test-server",
|
||||||
Name: "test-server",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(publishReq)
|
body, err := json.Marshal(publishReq)
|
||||||
|
|
@ -167,12 +161,10 @@ func TestPublishIntegration(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("publish fails with invalid token", func(t *testing.T) {
|
t.Run("publish fails with invalid token", func(t *testing.T) {
|
||||||
publishReq := apiv0.PublishRequest{
|
publishReq := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Test server",
|
||||||
Description: "Test server",
|
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
||||||
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := json.Marshal(publishReq)
|
body, err := json.Marshal(publishReq)
|
||||||
|
|
@ -190,18 +182,16 @@ func TestPublishIntegration(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("publish fails when permission denied", func(t *testing.T) {
|
t.Run("publish fails when permission denied", func(t *testing.T) {
|
||||||
publishReq := apiv0.PublishRequest{
|
publishReq := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.other/test-server",
|
||||||
Name: "io.github.other/test-server",
|
Description: "A test server",
|
||||||
Description: "A test server",
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
},
|
||||||
},
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server",
|
||||||
URL: "https://github.com/example/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server",
|
||||||
ID: "example/test-server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,33 +29,33 @@ type MockRegistryService struct {
|
||||||
mock.Mock
|
mock.Mock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockRegistryService) List(cursor string, limit int) ([]apiv0.ServerRecord, string, error) {
|
func (m *MockRegistryService) List(cursor string, limit int) ([]apiv0.ServerJSON, string, error) {
|
||||||
args := m.Called(cursor, limit)
|
args := m.Called(cursor, limit)
|
||||||
return args.Get(0).([]apiv0.ServerRecord), args.String(1), args.Error(2)
|
return args.Get(0).([]apiv0.ServerJSON), args.String(1), args.Error(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockRegistryService) GetByID(id string) (*apiv0.ServerRecord, error) {
|
func (m *MockRegistryService) GetByID(id string) (*apiv0.ServerJSON, error) {
|
||||||
args := m.Called(id)
|
args := m.Called(id)
|
||||||
if args.Get(0) == nil {
|
if args.Get(0) == nil {
|
||||||
return nil, args.Error(1)
|
return nil, args.Error(1)
|
||||||
}
|
}
|
||||||
return args.Get(0).(*apiv0.ServerRecord), args.Error(1)
|
return args.Get(0).(*apiv0.ServerJSON), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockRegistryService) Publish(request apiv0.PublishRequest) (*apiv0.ServerRecord, error) {
|
func (m *MockRegistryService) Publish(request apiv0.ServerJSON) (*apiv0.ServerJSON, error) {
|
||||||
args := m.Called(request)
|
args := m.Called(request)
|
||||||
if args.Get(0) == nil {
|
if args.Get(0) == nil {
|
||||||
return nil, args.Error(1)
|
return nil, args.Error(1)
|
||||||
}
|
}
|
||||||
return args.Get(0).(*apiv0.ServerRecord), args.Error(1)
|
return args.Get(0).(*apiv0.ServerJSON), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockRegistryService) EditServer(id string, request apiv0.PublishRequest) (*apiv0.ServerRecord, error) {
|
func (m *MockRegistryService) EditServer(id string, request apiv0.ServerJSON) (*apiv0.ServerJSON, error) {
|
||||||
args := m.Called(id, request)
|
args := m.Called(id, request)
|
||||||
if args.Get(0) == nil {
|
if args.Get(0) == nil {
|
||||||
return nil, args.Error(1)
|
return nil, args.Error(1)
|
||||||
}
|
}
|
||||||
return args.Get(0).(*apiv0.ServerRecord), args.Error(1)
|
return args.Get(0).(*apiv0.ServerJSON), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to generate a valid JWT token for testing
|
// Helper function to generate a valid JWT token for testing
|
||||||
|
|
@ -88,18 +88,16 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "successful publish with GitHub auth",
|
name: "successful publish with GitHub auth",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.example/test-server",
|
||||||
Name: "io.github.example/test-server",
|
Description: "A test server",
|
||||||
Description: "A test server",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server",
|
||||||
URL: "https://github.com/example/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server",
|
||||||
ID: "example/test-server",
|
},
|
||||||
},
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tokenClaims: &auth.JWTClaims{
|
tokenClaims: &auth.JWTClaims{
|
||||||
|
|
@ -110,24 +108,22 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
registry.On("Publish", mock.AnythingOfType("v0.PublishRequest")).Return(&apiv0.ServerRecord{}, nil)
|
registry.On("Publish", mock.AnythingOfType("v0.ServerJSON")).Return(&apiv0.ServerJSON{}, nil)
|
||||||
},
|
},
|
||||||
expectedStatus: http.StatusOK,
|
expectedStatus: http.StatusOK,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "successful publish with no auth (AuthMethodNone)",
|
name: "successful publish with no auth (AuthMethodNone)",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "example/test-server",
|
||||||
Name: "example/test-server",
|
Description: "A test server without auth",
|
||||||
Description: "A test server without auth",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server",
|
||||||
URL: "https://github.com/example/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server",
|
||||||
ID: "example/test-server",
|
},
|
||||||
},
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tokenClaims: &auth.JWTClaims{
|
tokenClaims: &auth.JWTClaims{
|
||||||
|
|
@ -137,13 +133,13 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
registry.On("Publish", mock.AnythingOfType("v0.PublishRequest")).Return(&apiv0.ServerRecord{}, nil)
|
registry.On("Publish", mock.AnythingOfType("v0.ServerJSON")).Return(&apiv0.ServerJSON{}, nil)
|
||||||
},
|
},
|
||||||
expectedStatus: http.StatusOK,
|
expectedStatus: http.StatusOK,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "missing authorization header",
|
name: "missing authorization header",
|
||||||
requestBody: apiv0.PublishRequest{},
|
requestBody: apiv0.ServerJSON{},
|
||||||
authHeader: "", // Empty auth header
|
authHeader: "", // Empty auth header
|
||||||
setupMocks: func(_ *MockRegistryService) {},
|
setupMocks: func(_ *MockRegistryService) {},
|
||||||
expectedStatus: http.StatusUnprocessableEntity,
|
expectedStatus: http.StatusUnprocessableEntity,
|
||||||
|
|
@ -151,12 +147,10 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid authorization header format",
|
name: "invalid authorization header format",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.domdomegg/test-server",
|
||||||
Name: "io.github.domdomegg/test-server",
|
Description: "Test server",
|
||||||
Description: "Test server",
|
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
||||||
VersionDetail: model.VersionDetail{Version: "1.0.0"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
authHeader: "InvalidFormat",
|
authHeader: "InvalidFormat",
|
||||||
setupMocks: func(_ *MockRegistryService) {},
|
setupMocks: func(_ *MockRegistryService) {},
|
||||||
|
|
@ -165,13 +159,11 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid token",
|
name: "invalid token",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "test-server",
|
||||||
Name: "test-server",
|
Description: "A test server",
|
||||||
Description: "A test server",
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authHeader: "Bearer invalidToken",
|
authHeader: "Bearer invalidToken",
|
||||||
|
|
@ -181,18 +173,16 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "permission denied",
|
name: "permission denied",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "io.github.other/test-server",
|
||||||
Name: "io.github.other/test-server",
|
Description: "A test server",
|
||||||
Description: "A test server",
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
},
|
||||||
},
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server",
|
||||||
URL: "https://github.com/example/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server",
|
||||||
ID: "example/test-server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tokenClaims: &auth.JWTClaims{
|
tokenClaims: &auth.JWTClaims{
|
||||||
|
|
@ -207,18 +197,16 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "registry service error",
|
name: "registry service error",
|
||||||
requestBody: apiv0.PublishRequest{
|
requestBody: apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "example/test-server",
|
||||||
Name: "example/test-server",
|
Description: "A test server",
|
||||||
Description: "A test server",
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
},
|
||||||
},
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server",
|
||||||
URL: "https://github.com/example/test-server",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server",
|
||||||
ID: "example/test-server",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
tokenClaims: &auth.JWTClaims{
|
tokenClaims: &auth.JWTClaims{
|
||||||
|
|
@ -228,7 +216,7 @@ func TestPublishEndpoint(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
registry.On("Publish", mock.AnythingOfType("v0.PublishRequest")).Return(nil, errors.New("cannot publish duplicate version"))
|
registry.On("Publish", mock.AnythingOfType("v0.ServerJSON")).Return(nil, errors.New("cannot publish duplicate version"))
|
||||||
},
|
},
|
||||||
expectedStatus: http.StatusBadRequest,
|
expectedStatus: http.StatusBadRequest,
|
||||||
expectedError: "Failed to publish server",
|
expectedError: "Failed to publish server",
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ type ListServersInput struct {
|
||||||
|
|
||||||
// ListServersBody represents the paginated server list response body
|
// ListServersBody represents the paginated server list response body
|
||||||
type ListServersBody struct {
|
type ListServersBody struct {
|
||||||
Servers []apiv0.ServerRecord `json:"servers" doc:"List of MCP servers with extensions"`
|
Servers []apiv0.ServerJSON `json:"servers" doc:"List of MCP servers with extensions"`
|
||||||
Metadata *Metadata `json:"metadata,omitempty" doc:"Pagination metadata"`
|
Metadata *Metadata `json:"metadata,omitempty" doc:"Pagination metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServerDetailInput represents the input for getting server details
|
// ServerDetailInput represents the input for getting server details
|
||||||
|
|
@ -85,7 +85,7 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
|
||||||
Summary: "Get MCP server details",
|
Summary: "Get MCP server details",
|
||||||
Description: "Get detailed information about a specific MCP server",
|
Description: "Get detailed information about a specific MCP server",
|
||||||
Tags: []string{"servers"},
|
Tags: []string{"servers"},
|
||||||
}, func(_ context.Context, input *ServerDetailInput) (*Response[apiv0.ServerRecord], error) {
|
}, func(_ context.Context, input *ServerDetailInput) (*Response[apiv0.ServerJSON], error) {
|
||||||
// Get the server details from the registry service
|
// Get the server details from the registry service
|
||||||
serverDetail, err := registry.GetByID(input.ID)
|
serverDetail, err := registry.GetByID(input.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -95,7 +95,7 @@ func RegisterServersEndpoints(api huma.API, registry service.RegistryService) {
|
||||||
return nil, huma.Error500InternalServerError("Failed to get server details", err)
|
return nil, huma.Error500InternalServerError("Failed to get server details", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Response[apiv0.ServerRecord]{
|
return &Response[apiv0.ServerJSON]{
|
||||||
Body: *serverDetail,
|
Body: *serverDetail,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -24,55 +24,15 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
queryParams string
|
queryParams string
|
||||||
setupMocks func(*MockRegistryService)
|
setupMocks func(*MockRegistryService)
|
||||||
expectedStatus int
|
expectedStatus int
|
||||||
expectedServers []apiv0.ServerRecord
|
expectedServers []apiv0.ServerJSON
|
||||||
expectedMeta *v0.Metadata
|
expectedMeta *v0.Metadata
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "successful list with default parameters",
|
name: "successful list with default parameters",
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
servers := []apiv0.ServerRecord{
|
servers := []apiv0.ServerJSON{
|
||||||
{
|
{
|
||||||
Server: model.ServerJSON{
|
|
||||||
Name: "test-server-1",
|
|
||||||
Description: "First test server",
|
|
||||||
Repository: model.Repository{
|
|
||||||
URL: "https://github.com/example/test-server-1",
|
|
||||||
Source: "github",
|
|
||||||
ID: "example/test-server-1",
|
|
||||||
},
|
|
||||||
VersionDetail: model.VersionDetail{
|
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
|
||||||
ID: "550e8400-e29b-41d4-a716-446655440001",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Server: model.ServerJSON{
|
|
||||||
Name: "test-server-2",
|
|
||||||
Description: "Second test server",
|
|
||||||
Repository: model.Repository{
|
|
||||||
URL: "https://github.com/example/test-server-2",
|
|
||||||
Source: "github",
|
|
||||||
ID: "example/test-server-2",
|
|
||||||
},
|
|
||||||
VersionDetail: model.VersionDetail{
|
|
||||||
Version: "2.0.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
|
||||||
ID: "550e8400-e29b-41d4-a716-446655440002",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
registry.Mock.On("List", "", 30).Return(servers, "", nil)
|
|
||||||
},
|
|
||||||
expectedStatus: http.StatusOK,
|
|
||||||
expectedServers: []apiv0.ServerRecord{
|
|
||||||
{
|
|
||||||
Server: model.ServerJSON{
|
|
||||||
Name: "test-server-1",
|
Name: "test-server-1",
|
||||||
Description: "First test server",
|
Description: "First test server",
|
||||||
Repository: model.Repository{
|
Repository: model.Repository{
|
||||||
|
|
@ -83,13 +43,13 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
VersionDetail: model.VersionDetail{
|
VersionDetail: model.VersionDetail{
|
||||||
Version: "1.0.0",
|
Version: "1.0.0",
|
||||||
},
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
{
|
||||||
ID: "550e8400-e29b-41d4-a716-446655440001",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Server: model.ServerJSON{
|
|
||||||
Name: "test-server-2",
|
Name: "test-server-2",
|
||||||
Description: "Second test server",
|
Description: "Second test server",
|
||||||
Repository: model.Repository{
|
Repository: model.Repository{
|
||||||
|
|
@ -100,9 +60,49 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
VersionDetail: model.VersionDetail{
|
VersionDetail: model.VersionDetail{
|
||||||
Version: "2.0.0",
|
Version: "2.0.0",
|
||||||
},
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: "550e8400-e29b-41d4-a716-446655440002",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
}
|
||||||
ID: "550e8400-e29b-41d4-a716-446655440002",
|
registry.Mock.On("List", "", 30).Return(servers, "", nil)
|
||||||
|
},
|
||||||
|
expectedStatus: http.StatusOK,
|
||||||
|
expectedServers: []apiv0.ServerJSON{
|
||||||
|
{
|
||||||
|
Name: "test-server-1",
|
||||||
|
Description: "First test server",
|
||||||
|
Repository: model.Repository{
|
||||||
|
URL: "https://github.com/example/test-server-1",
|
||||||
|
Source: "github",
|
||||||
|
ID: "example/test-server-1",
|
||||||
|
},
|
||||||
|
VersionDetail: model.VersionDetail{
|
||||||
|
Version: "1.0.0",
|
||||||
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: "550e8400-e29b-41d4-a716-446655440001",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "test-server-2",
|
||||||
|
Description: "Second test server",
|
||||||
|
Repository: model.Repository{
|
||||||
|
URL: "https://github.com/example/test-server-2",
|
||||||
|
Source: "github",
|
||||||
|
ID: "example/test-server-2",
|
||||||
|
},
|
||||||
|
VersionDetail: model.VersionDetail{
|
||||||
|
Version: "2.0.0",
|
||||||
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: "550e8400-e29b-41d4-a716-446655440002",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -111,32 +111,8 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
name: "successful list with cursor and limit",
|
name: "successful list with cursor and limit",
|
||||||
queryParams: "?cursor=550e8400-e29b-41d4-a716-446655440000&limit=10",
|
queryParams: "?cursor=550e8400-e29b-41d4-a716-446655440000&limit=10",
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
servers := []apiv0.ServerRecord{
|
servers := []apiv0.ServerJSON{
|
||||||
{
|
{
|
||||||
Server: model.ServerJSON{
|
|
||||||
Name: "test-server-3",
|
|
||||||
Description: "Third test server",
|
|
||||||
Repository: model.Repository{
|
|
||||||
URL: "https://github.com/example/test-server-3",
|
|
||||||
Source: "github",
|
|
||||||
ID: "example/test-server-3",
|
|
||||||
},
|
|
||||||
VersionDetail: model.VersionDetail{
|
|
||||||
Version: "1.5.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
|
||||||
ID: "550e8400-e29b-41d4-a716-446655440003",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
nextCursor := uuid.New().String()
|
|
||||||
registry.Mock.On("List", mock.AnythingOfType("string"), 10).Return(servers, nextCursor, nil)
|
|
||||||
},
|
|
||||||
expectedStatus: http.StatusOK,
|
|
||||||
expectedServers: []apiv0.ServerRecord{
|
|
||||||
{
|
|
||||||
Server: model.ServerJSON{
|
|
||||||
Name: "test-server-3",
|
Name: "test-server-3",
|
||||||
Description: "Third test server",
|
Description: "Third test server",
|
||||||
Repository: model.Repository{
|
Repository: model.Repository{
|
||||||
|
|
@ -147,9 +123,33 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
VersionDetail: model.VersionDetail{
|
VersionDetail: model.VersionDetail{
|
||||||
Version: "1.5.0",
|
Version: "1.5.0",
|
||||||
},
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: "550e8400-e29b-41d4-a716-446655440003",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
}
|
||||||
ID: "550e8400-e29b-41d4-a716-446655440003",
|
nextCursor := uuid.New().String()
|
||||||
|
registry.Mock.On("List", mock.AnythingOfType("string"), 10).Return(servers, nextCursor, nil)
|
||||||
|
},
|
||||||
|
expectedStatus: http.StatusOK,
|
||||||
|
expectedServers: []apiv0.ServerJSON{
|
||||||
|
{
|
||||||
|
Name: "test-server-3",
|
||||||
|
Description: "Third test server",
|
||||||
|
Repository: model.Repository{
|
||||||
|
URL: "https://github.com/example/test-server-3",
|
||||||
|
Source: "github",
|
||||||
|
ID: "example/test-server-3",
|
||||||
|
},
|
||||||
|
VersionDetail: model.VersionDetail{
|
||||||
|
Version: "1.5.0",
|
||||||
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: "550e8400-e29b-41d4-a716-446655440003",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
@ -196,7 +196,7 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "registry service error",
|
name: "registry service error",
|
||||||
setupMocks: func(registry *MockRegistryService) {
|
setupMocks: func(registry *MockRegistryService) {
|
||||||
registry.Mock.On("List", "", 30).Return([]apiv0.ServerRecord{}, "", errors.New("database connection error"))
|
registry.Mock.On("List", "", 30).Return([]apiv0.ServerJSON{}, "", errors.New("database connection error"))
|
||||||
},
|
},
|
||||||
expectedStatus: http.StatusInternalServerError,
|
expectedStatus: http.StatusInternalServerError,
|
||||||
expectedError: "Failed to get registry list",
|
expectedError: "Failed to get registry list",
|
||||||
|
|
@ -233,8 +233,8 @@ func TestServersListEndpoint(t *testing.T) {
|
||||||
|
|
||||||
// Parse response body
|
// Parse response body
|
||||||
var resp struct {
|
var resp struct {
|
||||||
Servers []apiv0.ServerRecord `json:"servers"`
|
Servers []apiv0.ServerJSON `json:"servers"`
|
||||||
Metadata *v0.Metadata `json:"metadata,omitempty"`
|
Metadata *v0.Metadata `json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
err := json.NewDecoder(w.Body).Decode(&resp)
|
err := json.NewDecoder(w.Body).Decode(&resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -268,28 +268,28 @@ func TestServersDetailEndpoint(t *testing.T) {
|
||||||
serverID string
|
serverID string
|
||||||
setupMocks func(*MockRegistryService, string)
|
setupMocks func(*MockRegistryService, string)
|
||||||
expectedStatus int
|
expectedStatus int
|
||||||
expectedServer *apiv0.ServerRecord
|
expectedServer *apiv0.ServerJSON
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "successful get server detail",
|
name: "successful get server detail",
|
||||||
serverID: uuid.New().String(),
|
serverID: uuid.New().String(),
|
||||||
setupMocks: func(registry *MockRegistryService, serverID string) {
|
setupMocks: func(registry *MockRegistryService, serverID string) {
|
||||||
serverDetail := &apiv0.ServerRecord{
|
serverDetail := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "test-server-detail",
|
||||||
Name: "test-server-detail",
|
Description: "Test server detail",
|
||||||
Description: "Test server detail",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server-detail",
|
||||||
URL: "https://github.com/example/test-server-detail",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server-detail",
|
||||||
ID: "example/test-server-detail",
|
|
||||||
},
|
|
||||||
VersionDetail: model.VersionDetail{
|
|
||||||
Version: "2.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
VersionDetail: model.VersionDetail{
|
||||||
ID: serverID,
|
Version: "2.0.0",
|
||||||
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: serverID,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
registry.Mock.On("GetByID", serverID).Return(serverDetail, nil)
|
registry.Mock.On("GetByID", serverID).Return(serverDetail, nil)
|
||||||
|
|
@ -352,12 +352,12 @@ func TestServersDetailEndpoint(t *testing.T) {
|
||||||
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
|
assert.Equal(t, "application/json", w.Header().Get("Content-Type"))
|
||||||
|
|
||||||
// Parse response body
|
// Parse response body
|
||||||
var serverDetailResp apiv0.ServerRecord
|
var serverDetailResp apiv0.ServerJSON
|
||||||
err := json.NewDecoder(w.Body).Decode(&serverDetailResp)
|
err := json.NewDecoder(w.Body).Decode(&serverDetailResp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Check that we got a valid response
|
// Check that we got a valid response
|
||||||
assert.NotEmpty(t, serverDetailResp.Server.Name)
|
assert.NotEmpty(t, serverDetailResp.Name)
|
||||||
} else if tc.expectedError != "" {
|
} else if tc.expectedError != "" {
|
||||||
// Check error message for non-200 responses
|
// Check error message for non-200 responses
|
||||||
assert.Contains(t, w.Body.String(), tc.expectedError)
|
assert.Contains(t, w.Body.String(), tc.expectedError)
|
||||||
|
|
@ -376,30 +376,27 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
||||||
|
|
||||||
// Test data
|
// Test data
|
||||||
serverID := uuid.New().String()
|
serverID := uuid.New().String()
|
||||||
servers := []apiv0.ServerRecord{
|
servers := []apiv0.ServerJSON{
|
||||||
{
|
{
|
||||||
Server: model.ServerJSON{
|
Name: "integration-test-server",
|
||||||
Name: "integration-test-server",
|
Description: "Integration test server",
|
||||||
Description: "Integration test server",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/integration-test",
|
||||||
URL: "https://github.com/example/integration-test",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/integration-test",
|
||||||
ID: "example/integration-test",
|
|
||||||
},
|
|
||||||
VersionDetail: model.VersionDetail{
|
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
VersionDetail: model.VersionDetail{
|
||||||
ID: serverID,
|
Version: "1.0.0",
|
||||||
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: serverID,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
serverDetail := &apiv0.ServerRecord{
|
serverDetail := &servers[0]
|
||||||
Server: servers[0].Server,
|
|
||||||
XIOModelContextProtocolRegistry: servers[0].XIOModelContextProtocolRegistry,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup mocks
|
// Setup mocks
|
||||||
mockRegistry.Mock.On("List", "", 30).Return(servers, "", nil)
|
mockRegistry.Mock.On("List", "", 30).Return(servers, "", nil)
|
||||||
|
|
@ -439,7 +436,7 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
||||||
|
|
||||||
// Parse response body
|
// Parse response body
|
||||||
var listResp struct {
|
var listResp struct {
|
||||||
Servers []apiv0.ServerRecord `json:"servers"`
|
Servers []apiv0.ServerJSON `json:"servers"`
|
||||||
}
|
}
|
||||||
err = json.NewDecoder(resp.Body).Decode(&listResp)
|
err = json.NewDecoder(resp.Body).Decode(&listResp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
@ -470,7 +467,7 @@ func TestServersEndpointsIntegration(t *testing.T) {
|
||||||
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
|
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
|
||||||
|
|
||||||
// Parse response body
|
// Parse response body
|
||||||
var serverDetailResp apiv0.ServerRecord
|
var serverDetailResp apiv0.ServerJSON
|
||||||
err = json.NewDecoder(resp.Body).Decode(&serverDetailResp)
|
err = json.NewDecoder(resp.Body).Decode(&serverDetailResp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,21 +20,21 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func mockServerEndpoint(registry *MockRegistryService, serverID string) {
|
func mockServerEndpoint(registry *MockRegistryService, serverID string) {
|
||||||
serverDetail := &apiv0.ServerRecord{
|
serverDetail := &apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "test-server-detail",
|
||||||
Name: "test-server-detail",
|
Description: "Test server detail",
|
||||||
Description: "Test server detail",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/example/test-server-detail",
|
||||||
URL: "https://github.com/example/test-server-detail",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "example/test-server-detail",
|
||||||
ID: "example/test-server-detail",
|
|
||||||
},
|
|
||||||
VersionDetail: model.VersionDetail{
|
|
||||||
Version: "2.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
VersionDetail: model.VersionDetail{
|
||||||
ID: serverID,
|
Version: "2.0.0",
|
||||||
|
},
|
||||||
|
Meta: &apiv0.ServerMeta{
|
||||||
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
|
ID: serverID,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
registry.Mock.On("GetByID", serverID).Return(serverDetail, nil)
|
registry.Mock.On("GetByID", serverID).Return(serverDetail, nil)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Common database errors
|
// Common database errors
|
||||||
|
|
@ -21,16 +20,16 @@ var (
|
||||||
// Database defines the interface for database operations with extension wrapper architecture
|
// Database defines the interface for database operations with extension wrapper architecture
|
||||||
type Database interface {
|
type Database interface {
|
||||||
// List retrieves all ServerRecord entries with optional filtering
|
// List retrieves all ServerRecord entries with optional filtering
|
||||||
List(ctx context.Context, filter map[string]any, cursor string, limit int) ([]*apiv0.ServerRecord, string, error)
|
List(ctx context.Context, filter map[string]any, cursor string, limit int) ([]*apiv0.ServerJSON, string, error)
|
||||||
// GetByID retrieves a single ServerRecord by its ID
|
// GetByID retrieves a single ServerRecord by its ID
|
||||||
GetByID(ctx context.Context, id string) (*apiv0.ServerRecord, error)
|
GetByID(ctx context.Context, id string) (*apiv0.ServerJSON, error)
|
||||||
// Publish adds a new server to the database with separated server.json and extensions
|
// Publish adds a new server to the database with separated server.json and extensions
|
||||||
// The registryMetadata contains metadata determined by the service layer (e.g., is_latest, timestamps)
|
// The registryMetadata contains metadata determined by the service layer (e.g., is_latest, timestamps)
|
||||||
Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerRecord, error)
|
Publish(ctx context.Context, serverDetail apiv0.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerJSON, error)
|
||||||
// UpdateLatestFlag updates the is_latest flag for a specific server record
|
// UpdateLatestFlag updates the is_latest flag for a specific server record
|
||||||
UpdateLatestFlag(ctx context.Context, id string, isLatest bool) error
|
UpdateLatestFlag(ctx context.Context, id string, isLatest bool) error
|
||||||
// UpdateServer updates an existing server record with new server details
|
// UpdateServer updates an existing server record with new server details
|
||||||
UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerRecord, error)
|
UpdateServer(ctx context.Context, id string, serverDetail apiv0.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerJSON, error)
|
||||||
// ImportSeed imports initial data from a seed file
|
// ImportSeed imports initial data from a seed file
|
||||||
ImportSeed(ctx context.Context, seedFilePath string) error
|
ImportSeed(ctx context.Context, seedFilePath string) error
|
||||||
// Close closes the database connection
|
// Close closes the database connection
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// 2. Direct HTTP URLs to seed.json files - expects extension wrapper format
|
// 2. Direct HTTP URLs to seed.json files - expects extension wrapper format
|
||||||
// 3. Registry root URLs (automatically appends /v0/servers and paginates)
|
// 3. Registry root URLs (automatically appends /v0/servers and paginates)
|
||||||
// Only the extension wrapper format is supported (array of ServerResponse objects)
|
// Only the extension wrapper format is supported (array of ServerResponse objects)
|
||||||
func ReadSeedFile(ctx context.Context, path string) ([]*apiv0.ServerRecord, error) {
|
func ReadSeedFile(ctx context.Context, path string) ([]*apiv0.ServerJSON, error) {
|
||||||
var data []byte
|
var data []byte
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
@ -41,30 +41,30 @@ func ReadSeedFile(ctx context.Context, path string) ([]*apiv0.ServerRecord, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse extension wrapper format (only supported format)
|
// Parse extension wrapper format (only supported format)
|
||||||
var serverResponses []apiv0.ServerRecord
|
var serverResponses []apiv0.ServerJSON
|
||||||
if err := json.Unmarshal(data, &serverResponses); err != nil {
|
if err := json.Unmarshal(data, &serverResponses); err != nil {
|
||||||
return nil, fmt.Errorf("failed to parse seed data as extension wrapper format: %w", err)
|
return nil, fmt.Errorf("failed to parse seed data as extension wrapper format: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(serverResponses) == 0 {
|
if len(serverResponses) == 0 {
|
||||||
return []*apiv0.ServerRecord{}, nil
|
return []*apiv0.ServerJSON{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate servers and collect warnings instead of failing the whole batch
|
// Validate servers and collect warnings instead of failing the whole batch
|
||||||
var validRecords []*apiv0.ServerRecord
|
var validRecords []*apiv0.ServerJSON
|
||||||
var invalidServers []string
|
var invalidServers []string
|
||||||
var validationFailures []string
|
var validationFailures []string
|
||||||
|
|
||||||
for _, response := range serverResponses {
|
for _, response := range serverResponses {
|
||||||
if err := validators.ValidateServerJSON(&response.Server); err != nil {
|
if err := validators.ValidateServerJSON(&response); err != nil {
|
||||||
// Log warning and track invalid server instead of failing
|
// Log warning and track invalid server instead of failing
|
||||||
invalidServers = append(invalidServers, response.Server.Name)
|
invalidServers = append(invalidServers, response.Name)
|
||||||
validationFailures = append(validationFailures, fmt.Sprintf("Server '%s': %v", response.Server.Name, err))
|
validationFailures = append(validationFailures, fmt.Sprintf("Server '%s': %v", response.Name, err))
|
||||||
log.Printf("Warning: Skipping invalid server '%s': %v", response.Server.Name, err)
|
log.Printf("Warning: Skipping invalid server '%s': %v", response.Name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert valid ServerResponse to ServerRecord
|
// Convert valid ServerJSON to ServerRecord
|
||||||
record := convertServerResponseToRecord(response)
|
record := convertServerResponseToRecord(response)
|
||||||
validRecords = append(validRecords, record)
|
validRecords = append(validRecords, record)
|
||||||
}
|
}
|
||||||
|
|
@ -102,8 +102,8 @@ func fetchFromHTTP(ctx context.Context, url string) ([]byte, error) {
|
||||||
return io.ReadAll(resp.Body)
|
return io.ReadAll(resp.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv0.ServerRecord, error) {
|
func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv0.ServerJSON, error) {
|
||||||
var allRecords []*apiv0.ServerRecord
|
var allRecords []*apiv0.ServerJSON
|
||||||
cursor := ""
|
cursor := ""
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
@ -122,7 +122,7 @@ func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv0.ServerR
|
||||||
}
|
}
|
||||||
|
|
||||||
var response struct {
|
var response struct {
|
||||||
Servers []apiv0.ServerRecord `json:"servers"`
|
Servers []apiv0.ServerJSON `json:"servers"`
|
||||||
Metadata *struct {
|
Metadata *struct {
|
||||||
NextCursor string `json:"next_cursor,omitempty"`
|
NextCursor string `json:"next_cursor,omitempty"`
|
||||||
} `json:"metadata,omitempty"`
|
} `json:"metadata,omitempty"`
|
||||||
|
|
@ -148,19 +148,8 @@ func fetchFromRegistryAPI(ctx context.Context, baseURL string) ([]*apiv0.ServerR
|
||||||
return allRecords, nil
|
return allRecords, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertServerResponseToRecord(response apiv0.ServerRecord) *apiv0.ServerRecord {
|
func convertServerResponseToRecord(response apiv0.ServerJSON) *apiv0.ServerJSON {
|
||||||
// The registry extensions are already properly typed, so we can use them directly
|
// The response is already in the correct flattened format
|
||||||
registryMetadata := response.XIOModelContextProtocolRegistry
|
// Just return a pointer to it
|
||||||
|
return &response
|
||||||
// Publisher extensions
|
|
||||||
publisherExtensions := response.XPublisher
|
|
||||||
if publisherExtensions == nil {
|
|
||||||
publisherExtensions = make(map[string]interface{})
|
|
||||||
}
|
|
||||||
|
|
||||||
return &apiv0.ServerRecord{
|
|
||||||
Server: response.Server,
|
|
||||||
XIOModelContextProtocolRegistry: registryMetadata,
|
|
||||||
XPublisher: publisherExtensions,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,30 +18,30 @@ import (
|
||||||
func TestReadSeedFile_LocalFile(t *testing.T) {
|
func TestReadSeedFile_LocalFile(t *testing.T) {
|
||||||
// Create a temporary seed file in extension wrapper format
|
// Create a temporary seed file in extension wrapper format
|
||||||
tempFile := "/tmp/test_seed.json"
|
tempFile := "/tmp/test_seed.json"
|
||||||
seedData := []apiv0.ServerRecord{
|
seedData := []apiv0.ServerJSON{
|
||||||
{
|
{
|
||||||
Server: model.ServerJSON{
|
Name: "com.example/test-server-1",
|
||||||
Name: "com.example/test-server-1",
|
Description: "Test server 1",
|
||||||
Description: "Test server 1",
|
Repository: model.Repository{
|
||||||
Repository: model.Repository{
|
URL: "https://github.com/test/repo1",
|
||||||
URL: "https://github.com/test/repo1",
|
Source: "github",
|
||||||
Source: "github",
|
ID: "123",
|
||||||
ID: "123",
|
},
|
||||||
},
|
VersionDetail: model.VersionDetail{
|
||||||
VersionDetail: model.VersionDetail{
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
},
|
||||||
},
|
Remotes: []model.Remote{
|
||||||
Remotes: []model.Remote{
|
{
|
||||||
{
|
URL: "https://example.com/remote",
|
||||||
URL: "https://example.com/remote",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
Meta: &apiv0.ServerMeta{
|
||||||
ID: "test-id-1",
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
ID: "test-id-1",
|
||||||
IsLatest: true,
|
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
ReleaseDate: "2023-01-01T00:00:00Z",
|
IsLatest: true,
|
||||||
|
ReleaseDate: "2023-01-01T00:00:00Z",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -66,27 +66,27 @@ func TestReadSeedFile_LocalFile(t *testing.T) {
|
||||||
result, err := database.ReadSeedFile(context.Background(), tempFile)
|
result, err := database.ReadSeedFile(context.Background(), tempFile)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, result, 1)
|
assert.Len(t, result, 1)
|
||||||
assert.Equal(t, "com.example/test-server-1", result[0].Server.Name)
|
assert.Equal(t, "com.example/test-server-1", result[0].Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadSeedFile_DirectHTTPURL(t *testing.T) {
|
func TestReadSeedFile_DirectHTTPURL(t *testing.T) {
|
||||||
// Create a test HTTP server that serves seed JSON directly in extension wrapper format
|
// Create a test HTTP server that serves seed JSON directly in extension wrapper format
|
||||||
seedData := []apiv0.ServerRecord{
|
seedData := []apiv0.ServerJSON{
|
||||||
{
|
{
|
||||||
Server: model.ServerJSON{
|
Name: "com.example/test-server-1",
|
||||||
Name: "com.example/test-server-1",
|
Description: "Test server 1",
|
||||||
Description: "Test server 1",
|
Remotes: []model.Remote{
|
||||||
Remotes: []model.Remote{
|
{
|
||||||
{
|
URL: "https://example.com/remote",
|
||||||
URL: "https://example.com/remote",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
Meta: &apiv0.ServerMeta{
|
||||||
ID: "test-id-1",
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
ID: "test-id-1",
|
||||||
IsLatest: true,
|
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
ReleaseDate: "2023-01-01T00:00:00Z",
|
IsLatest: true,
|
||||||
|
ReleaseDate: "2023-01-01T00:00:00Z",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -103,53 +103,53 @@ func TestReadSeedFile_DirectHTTPURL(t *testing.T) {
|
||||||
result, err := database.ReadSeedFile(context.Background(), server.URL+"/seed.json")
|
result, err := database.ReadSeedFile(context.Background(), server.URL+"/seed.json")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Len(t, result, 1)
|
assert.Len(t, result, 1)
|
||||||
assert.Equal(t, "com.example/test-server-1", result[0].Server.Name)
|
assert.Equal(t, "com.example/test-server-1", result[0].Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadSeedFile_RegistryURL(t *testing.T) {
|
func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
// Create mock registry responses
|
// Create mock registry responses
|
||||||
server1 := apiv0.ServerRecord{
|
server1 := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "Test Server 1",
|
||||||
Name: "Test Server 1",
|
Description: "First test server",
|
||||||
Description: "First test server",
|
Packages: []model.Package{
|
||||||
Packages: []model.Package{
|
{
|
||||||
{
|
RegistryType: "npm",
|
||||||
RegistryType: "npm",
|
RegistryBaseURL: "https://registry.npmjs.org",
|
||||||
RegistryBaseURL: "https://registry.npmjs.org",
|
Identifier: "test-package-1",
|
||||||
Identifier: "test-package-1",
|
Version: "1.0.0",
|
||||||
Version: "1.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
Meta: &apiv0.ServerMeta{
|
||||||
ID: "server-1",
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
ID: "server-1",
|
||||||
IsLatest: true,
|
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
ReleaseDate: "2023-01-01T00:00:00Z",
|
IsLatest: true,
|
||||||
|
ReleaseDate: "2023-01-01T00:00:00Z",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
server2 := apiv0.ServerRecord{
|
server2 := apiv0.ServerJSON{
|
||||||
Server: model.ServerJSON{
|
Name: "Test Server 2",
|
||||||
Name: "Test Server 2",
|
Description: "Second test server",
|
||||||
Description: "Second test server",
|
Packages: []model.Package{
|
||||||
Packages: []model.Package{
|
{
|
||||||
{
|
RegistryType: "npm",
|
||||||
RegistryType: "npm",
|
RegistryBaseURL: "https://registry.npmjs.org",
|
||||||
RegistryBaseURL: "https://registry.npmjs.org",
|
Identifier: "test-package-2",
|
||||||
Identifier: "test-package-2",
|
Version: "2.0.0",
|
||||||
Version: "2.0.0",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
Meta: &apiv0.ServerMeta{
|
||||||
ID: "server-2",
|
IOModelContextProtocolRegistry: &apiv0.RegistryExtensions{
|
||||||
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
ID: "server-2",
|
||||||
IsLatest: true,
|
PublishedAt: time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
ReleaseDate: "2023-01-01T00:00:00Z",
|
IsLatest: true,
|
||||||
|
ReleaseDate: "2023-01-01T00:00:00Z",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
serverDetail1 := model.ServerJSON{
|
serverDetail1 := apiv0.ServerJSON{
|
||||||
Name: "Test Server 1",
|
Name: "Test Server 1",
|
||||||
Description: "First test server",
|
Description: "First test server",
|
||||||
Packages: []model.Package{
|
Packages: []model.Package{
|
||||||
|
|
@ -161,7 +161,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
serverDetail2 := model.ServerJSON{
|
serverDetail2 := apiv0.ServerJSON{
|
||||||
Name: "Test Server 2",
|
Name: "Test Server 2",
|
||||||
Description: "Second test server",
|
Description: "Second test server",
|
||||||
Packages: []model.Package{
|
Packages: []model.Package{
|
||||||
|
|
@ -187,8 +187,8 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PaginatedResponse struct {
|
type PaginatedResponse struct {
|
||||||
Servers []apiv0.ServerRecord `json:"servers"`
|
Servers []apiv0.ServerJSON `json:"servers"`
|
||||||
Metadata *Metadata `json:"metadata,omitempty"`
|
Metadata *Metadata `json:"metadata,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var response PaginatedResponse
|
var response PaginatedResponse
|
||||||
|
|
@ -196,7 +196,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
case "":
|
case "":
|
||||||
// First page
|
// First page
|
||||||
response = PaginatedResponse{
|
response = PaginatedResponse{
|
||||||
Servers: []apiv0.ServerRecord{server1},
|
Servers: []apiv0.ServerJSON{server1},
|
||||||
Metadata: &Metadata{
|
Metadata: &Metadata{
|
||||||
NextCursor: "next-cursor-1",
|
NextCursor: "next-cursor-1",
|
||||||
Count: 1,
|
Count: 1,
|
||||||
|
|
@ -205,7 +205,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
case "next-cursor-1":
|
case "next-cursor-1":
|
||||||
// Second page
|
// Second page
|
||||||
response = PaginatedResponse{
|
response = PaginatedResponse{
|
||||||
Servers: []apiv0.ServerRecord{server2},
|
Servers: []apiv0.ServerJSON{server2},
|
||||||
Metadata: &Metadata{
|
Metadata: &Metadata{
|
||||||
Count: 1,
|
Count: 1,
|
||||||
// No NextCursor means end of pagination
|
// No NextCursor means end of pagination
|
||||||
|
|
@ -214,7 +214,7 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
default:
|
default:
|
||||||
// No more pages
|
// No more pages
|
||||||
response = PaginatedResponse{
|
response = PaginatedResponse{
|
||||||
Servers: []apiv0.ServerRecord{},
|
Servers: []apiv0.ServerJSON{},
|
||||||
Metadata: &Metadata{},
|
Metadata: &Metadata{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -249,20 +249,20 @@ func TestReadSeedFile_RegistryURL(t *testing.T) {
|
||||||
assert.Len(t, result, 2)
|
assert.Len(t, result, 2)
|
||||||
|
|
||||||
// Verify the servers were imported correctly
|
// Verify the servers were imported correctly
|
||||||
assert.Equal(t, "Test Server 1", result[0].Server.Name)
|
assert.Equal(t, "Test Server 1", result[0].Name)
|
||||||
assert.Equal(t, "Test Server 2", result[1].Server.Name)
|
assert.Equal(t, "Test Server 2", result[1].Name)
|
||||||
|
|
||||||
// Verify packages were imported with new schema
|
// Verify packages were imported with new schema
|
||||||
assert.Len(t, result[0].Server.Packages, 1)
|
assert.Len(t, result[0].Packages, 1)
|
||||||
assert.Equal(t, "npm", result[0].Server.Packages[0].RegistryType)
|
assert.Equal(t, "npm", result[0].Packages[0].RegistryType)
|
||||||
assert.Equal(t, "https://registry.npmjs.org", result[0].Server.Packages[0].RegistryBaseURL)
|
assert.Equal(t, "https://registry.npmjs.org", result[0].Packages[0].RegistryBaseURL)
|
||||||
assert.Equal(t, "test-package-1", result[0].Server.Packages[0].Identifier)
|
assert.Equal(t, "test-package-1", result[0].Packages[0].Identifier)
|
||||||
assert.Len(t, result[1].Server.Packages, 1)
|
assert.Len(t, result[1].Packages, 1)
|
||||||
assert.Equal(t, "npm", result[1].Server.Packages[0].RegistryType)
|
assert.Equal(t, "npm", result[1].Packages[0].RegistryType)
|
||||||
assert.Equal(t, "https://registry.npmjs.org", result[1].Server.Packages[0].RegistryBaseURL)
|
assert.Equal(t, "https://registry.npmjs.org", result[1].Packages[0].RegistryBaseURL)
|
||||||
assert.Equal(t, "test-package-2", result[1].Server.Packages[0].Identifier)
|
assert.Equal(t, "test-package-2", result[1].Packages[0].Identifier)
|
||||||
|
|
||||||
// Verify metadata was extracted
|
// Verify metadata was extracted
|
||||||
assert.Equal(t, "server-1", result[0].XIOModelContextProtocolRegistry.ID)
|
assert.Equal(t, "server-1", result[0].Meta.IOModelContextProtocolRegistry.ID)
|
||||||
assert.Equal(t, "server-2", result[1].XIOModelContextProtocolRegistry.ID)
|
assert.Equal(t, "server-2", result[1].Meta.IOModelContextProtocolRegistry.ID)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,47 +8,49 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||||
"github.com/modelcontextprotocol/registry/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MemoryDB is an in-memory implementation of the Database interface
|
// MemoryDB is an in-memory implementation of the Database interface
|
||||||
type MemoryDB struct {
|
type MemoryDB struct {
|
||||||
entries map[string]*apiv0.ServerRecord // maps registry metadata ID to ServerRecord
|
entries map[string]*apiv0.ServerJSON // maps registry metadata ID to ServerJSON
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMemoryDB creates a new instance of the in-memory database
|
// NewMemoryDB creates a new instance of the in-memory database
|
||||||
func NewMemoryDB(e map[string]*model.ServerJSON) *MemoryDB {
|
func NewMemoryDB(e map[string]*apiv0.ServerJSON) *MemoryDB {
|
||||||
// Convert ServerJSON entries to ServerRecord entries
|
// Convert input ServerJSON entries to have proper metadata
|
||||||
serverRecords := make(map[string]*apiv0.ServerRecord)
|
serverRecords := make(map[string]*apiv0.ServerJSON)
|
||||||
for registryID, serverDetail := range e {
|
for registryID, serverDetail := range e {
|
||||||
// Create registry metadata
|
// Create a copy and add registry metadata
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
record := &apiv0.ServerRecord{
|
server := *serverDetail // Copy the server
|
||||||
Server: *serverDetail,
|
if server.Meta == nil {
|
||||||
XIOModelContextProtocolRegistry: apiv0.RegistryExtensions{
|
server.Meta = &apiv0.ServerMeta{}
|
||||||
ID: registryID,
|
|
||||||
PublishedAt: now,
|
|
||||||
UpdatedAt: now,
|
|
||||||
IsLatest: true,
|
|
||||||
ReleaseDate: now.Format(time.RFC3339),
|
|
||||||
},
|
|
||||||
XPublisher: make(map[string]interface{}),
|
|
||||||
}
|
}
|
||||||
serverRecords[registryID] = record
|
server.Meta.IOModelContextProtocolRegistry = &apiv0.RegistryExtensions{
|
||||||
|
ID: registryID,
|
||||||
|
PublishedAt: now,
|
||||||
|
UpdatedAt: now,
|
||||||
|
IsLatest: true,
|
||||||
|
ReleaseDate: now.Format(time.RFC3339),
|
||||||
|
}
|
||||||
|
if server.Meta.Publisher == nil {
|
||||||
|
server.Meta.Publisher = make(map[string]interface{})
|
||||||
|
}
|
||||||
|
serverRecords[registryID] = &server
|
||||||
}
|
}
|
||||||
return &MemoryDB{
|
return &MemoryDB{
|
||||||
entries: serverRecords,
|
entries: serverRecords,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:cyclop // Complexity from filtering logic is acceptable for memory implementation
|
//nolint:cyclop,gocyclo,gocognit // Complexity from filtering logic is acceptable for memory implementation
|
||||||
func (db *MemoryDB) List(
|
func (db *MemoryDB) List(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
filter map[string]any,
|
filter map[string]any,
|
||||||
cursor string,
|
cursor string,
|
||||||
limit int,
|
limit int,
|
||||||
) ([]*apiv0.ServerRecord, string, error) {
|
) ([]*apiv0.ServerJSON, string, error) {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return nil, "", ctx.Err()
|
return nil, "", ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
@ -61,15 +63,15 @@ func (db *MemoryDB) List(
|
||||||
defer db.mu.RUnlock()
|
defer db.mu.RUnlock()
|
||||||
|
|
||||||
// Convert all entries to a slice for pagination, filter by is_latest
|
// Convert all entries to a slice for pagination, filter by is_latest
|
||||||
var allEntries []*apiv0.ServerRecord
|
var allEntries []*apiv0.ServerJSON
|
||||||
for _, entry := range db.entries {
|
for _, entry := range db.entries {
|
||||||
if entry.XIOModelContextProtocolRegistry.IsLatest {
|
if entry.Meta != nil && entry.Meta.IOModelContextProtocolRegistry != nil && entry.Meta.IOModelContextProtocolRegistry.IsLatest {
|
||||||
allEntries = append(allEntries, entry)
|
allEntries = append(allEntries, entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple filtering implementation
|
// Simple filtering implementation
|
||||||
var filteredEntries []*apiv0.ServerRecord
|
var filteredEntries []*apiv0.ServerJSON
|
||||||
for _, entry := range allEntries {
|
for _, entry := range allEntries {
|
||||||
include := true
|
include := true
|
||||||
|
|
||||||
|
|
@ -77,21 +79,21 @@ func (db *MemoryDB) List(
|
||||||
for key, value := range filter {
|
for key, value := range filter {
|
||||||
switch key {
|
switch key {
|
||||||
case "name":
|
case "name":
|
||||||
if entry.Server.Name != value.(string) {
|
if entry.Name != value.(string) {
|
||||||
include = false
|
include = false
|
||||||
}
|
}
|
||||||
case "version":
|
case "version":
|
||||||
if entry.Server.VersionDetail.Version != value.(string) {
|
if entry.VersionDetail.Version != value.(string) {
|
||||||
include = false
|
include = false
|
||||||
}
|
}
|
||||||
case "status":
|
case "status":
|
||||||
if string(entry.Server.Status) != value.(string) {
|
if string(entry.Status) != value.(string) {
|
||||||
include = false
|
include = false
|
||||||
}
|
}
|
||||||
case "remote_url":
|
case "remote_url":
|
||||||
found := false
|
found := false
|
||||||
remoteURL := value.(string)
|
remoteURL := value.(string)
|
||||||
for _, remote := range entry.Server.Remotes {
|
for _, remote := range entry.Remotes {
|
||||||
if remote.URL == remoteURL {
|
if remote.URL == remoteURL {
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|
@ -110,14 +112,23 @@ func (db *MemoryDB) List(
|
||||||
|
|
||||||
// Sort filteredEntries by registry metadata ID for consistent pagination
|
// Sort filteredEntries by registry metadata ID for consistent pagination
|
||||||
sort.Slice(filteredEntries, func(i, j int) bool {
|
sort.Slice(filteredEntries, func(i, j int) bool {
|
||||||
return filteredEntries[i].XIOModelContextProtocolRegistry.ID < filteredEntries[j].XIOModelContextProtocolRegistry.ID
|
iID := ""
|
||||||
|
jID := ""
|
||||||
|
if filteredEntries[i].Meta != nil && filteredEntries[i].Meta.IOModelContextProtocolRegistry != nil {
|
||||||
|
iID = filteredEntries[i].Meta.IOModelContextProtocolRegistry.ID
|
||||||
|
}
|
||||||
|
if filteredEntries[j].Meta != nil && filteredEntries[j].Meta.IOModelContextProtocolRegistry != nil {
|
||||||
|
jID = filteredEntries[j].Meta.IOModelContextProtocolRegistry.ID
|
||||||
|
}
|
||||||
|
return iID < jID
|
||||||
})
|
})
|
||||||
|
|
||||||
// Find starting point for cursor-based pagination using registry metadata ID
|
// Find starting point for cursor-based pagination using registry metadata ID
|
||||||
startIdx := 0
|
startIdx := 0
|
||||||
if cursor != "" {
|
if cursor != "" {
|
||||||
for i, entry := range filteredEntries {
|
for i, entry := range filteredEntries {
|
||||||
if entry.XIOModelContextProtocolRegistry.ID == cursor {
|
if entry.Meta != nil && entry.Meta.IOModelContextProtocolRegistry != nil &&
|
||||||
|
entry.Meta.IOModelContextProtocolRegistry.ID == cursor {
|
||||||
startIdx = i + 1 // Start after the cursor
|
startIdx = i + 1 // Start after the cursor
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -127,24 +138,27 @@ func (db *MemoryDB) List(
|
||||||
// Apply pagination
|
// Apply pagination
|
||||||
endIdx := min(startIdx+limit, len(filteredEntries))
|
endIdx := min(startIdx+limit, len(filteredEntries))
|
||||||
|
|
||||||
var result []*apiv0.ServerRecord
|
var result []*apiv0.ServerJSON
|
||||||
if startIdx < len(filteredEntries) {
|
if startIdx < len(filteredEntries) {
|
||||||
result = filteredEntries[startIdx:endIdx]
|
result = filteredEntries[startIdx:endIdx]
|
||||||
} else {
|
} else {
|
||||||
result = []*apiv0.ServerRecord{}
|
result = []*apiv0.ServerJSON{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine next cursor using registry metadata ID
|
// Determine next cursor using registry metadata ID
|
||||||
nextCursor := ""
|
nextCursor := ""
|
||||||
if endIdx < len(filteredEntries) {
|
if endIdx < len(filteredEntries) && len(result) > 0 {
|
||||||
nextCursor = filteredEntries[endIdx-1].XIOModelContextProtocolRegistry.ID
|
lastEntry := result[len(result)-1]
|
||||||
|
if lastEntry.Meta != nil && lastEntry.Meta.IOModelContextProtocolRegistry != nil {
|
||||||
|
nextCursor = lastEntry.Meta.IOModelContextProtocolRegistry.ID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nextCursor, nil
|
return result, nextCursor, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetByID retrieves a single ServerRecord by its registry metadata ID
|
// GetByID retrieves a single ServerRecord by its registry metadata ID
|
||||||
func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv0.ServerRecord, error) {
|
func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv0.ServerJSON, error) {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +177,7 @@ func (db *MemoryDB) GetByID(ctx context.Context, id string) (*apiv0.ServerRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish adds a new server to the database with separated server.json and extensions
|
// Publish adds a new server to the database with separated server.json and extensions
|
||||||
func (db *MemoryDB) Publish(ctx context.Context, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerRecord, error) {
|
func (db *MemoryDB) Publish(ctx context.Context, serverDetail apiv0.ServerJSON, publisherExtensions map[string]interface{}, registryMetadata apiv0.RegistryExtensions) (*apiv0.ServerJSON, error) {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
@ -187,17 +201,26 @@ func (db *MemoryDB) Publish(ctx context.Context, serverDetail model.ServerJSON,
|
||||||
return nil, ErrInvalidInput
|
return nil, ErrInvalidInput
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create server record
|
// Create server record with metadata
|
||||||
record := &apiv0.ServerRecord{
|
record := serverDetail // Copy the input
|
||||||
Server: serverDetail,
|
|
||||||
XIOModelContextProtocolRegistry: registryMetadata,
|
// Initialize meta if not present
|
||||||
XPublisher: publisherExtensions,
|
if record.Meta == nil {
|
||||||
|
record.Meta = &apiv0.ServerMeta{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set registry metadata
|
||||||
|
record.Meta.IOModelContextProtocolRegistry = ®istryMetadata
|
||||||
|
|
||||||
|
// Set publisher extensions if provided
|
||||||
|
if len(publisherExtensions) > 0 {
|
||||||
|
record.Meta.Publisher = publisherExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the record using registry metadata ID
|
// Store the record using registry metadata ID
|
||||||
db.entries[registryMetadata.ID] = record
|
db.entries[registryMetadata.ID] = &record
|
||||||
|
|
||||||
return record, nil
|
return &record, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportSeed imports initial data from a seed file into memory database
|
// ImportSeed imports initial data from a seed file into memory database
|
||||||
|
|
@ -220,7 +243,9 @@ func (db *MemoryDB) ImportSeed(ctx context.Context, seedFilePath string) error {
|
||||||
// Import each server
|
// Import each server
|
||||||
for _, record := range seedData {
|
for _, record := range seedData {
|
||||||
// Use the registry metadata ID as the map key
|
// Use the registry metadata ID as the map key
|
||||||
db.entries[record.XIOModelContextProtocolRegistry.ID] = record
|
if record.Meta != nil && record.Meta.IOModelContextProtocolRegistry != nil {
|
||||||
|
db.entries[record.Meta.IOModelContextProtocolRegistry.ID] = record
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -236,8 +261,10 @@ func (db *MemoryDB) UpdateLatestFlag(ctx context.Context, id string, isLatest bo
|
||||||
defer db.mu.Unlock()
|
defer db.mu.Unlock()
|
||||||
|
|
||||||
if entry, exists := db.entries[id]; exists {
|
if entry, exists := db.entries[id]; exists {
|
||||||
entry.XIOModelContextProtocolRegistry.IsLatest = isLatest
|
if entry.Meta != nil && entry.Meta.IOModelContextProtocolRegistry != nil {
|
||||||
entry.XIOModelContextProtocolRegistry.UpdatedAt = time.Now()
|
entry.Meta.IOModelContextProtocolRegistry.IsLatest = isLatest
|
||||||
|
entry.Meta.IOModelContextProtocolRegistry.UpdatedAt = time.Now()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,7 +272,7 @@ func (db *MemoryDB) UpdateLatestFlag(ctx context.Context, id string, isLatest bo
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateServer updates an existing server record with new server details
|
// UpdateServer updates an existing server record with new server details
|
||||||
func (db *MemoryDB) UpdateServer(ctx context.Context, id string, serverDetail model.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerRecord, error) {
|
func (db *MemoryDB) UpdateServer(ctx context.Context, id string, serverDetail apiv0.ServerJSON, publisherExtensions map[string]interface{}) (*apiv0.ServerJSON, error) {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return nil, ctx.Err()
|
return nil, ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
@ -258,10 +285,19 @@ func (db *MemoryDB) UpdateServer(ctx context.Context, id string, serverDetail mo
|
||||||
return nil, ErrNotFound
|
return nil, ErrNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the server details
|
// Update the server details by copying fields from serverDetail
|
||||||
entry.Server = serverDetail
|
*entry = serverDetail
|
||||||
entry.XPublisher = publisherExtensions
|
|
||||||
entry.XIOModelContextProtocolRegistry.UpdatedAt = time.Now()
|
// Ensure meta exists and update it
|
||||||
|
if entry.Meta == nil {
|
||||||
|
entry.Meta = &apiv0.ServerMeta{}
|
||||||
|
}
|
||||||
|
if entry.Meta.IOModelContextProtocolRegistry != nil {
|
||||||
|
entry.Meta.IOModelContextProtocolRegistry.UpdatedAt = time.Now()
|
||||||
|
}
|
||||||
|
if len(publisherExtensions) > 0 {
|
||||||
|
entry.Meta.Publisher = publisherExtensions
|
||||||
|
}
|
||||||
|
|
||||||
// Return the updated record
|
// Return the updated record
|
||||||
return entry, nil
|
return entry, nil
|
||||||
|
|
|
||||||
24
internal/database/migrations/003_simplify_to_key_value.sql
Normal file
24
internal/database/migrations/003_simplify_to_key_value.sql
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
-- Simplify database to simple key-value table with id, value
|
||||||
|
-- This migration drops all existing data and creates a clean simple structure
|
||||||
|
|
||||||
|
-- Drop old tables and functions
|
||||||
|
DROP TRIGGER IF EXISTS update_server_extensions_on_server_update ON servers;
|
||||||
|
DROP FUNCTION IF EXISTS update_server_extensions_updated_at();
|
||||||
|
DROP TRIGGER IF EXISTS update_servers_updated_at ON servers;
|
||||||
|
DROP FUNCTION IF EXISTS update_updated_at_column();
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS server_extensions;
|
||||||
|
DROP TABLE IF EXISTS servers;
|
||||||
|
|
||||||
|
-- Create new simple servers table
|
||||||
|
CREATE TABLE servers (
|
||||||
|
id VARCHAR(255) PRIMARY KEY, -- Use registry metadata ID as primary key
|
||||||
|
value JSONB NOT NULL -- Complete ServerJSON as JSONB
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Create essential indexes for performance
|
||||||
|
CREATE INDEX idx_servers_id ON servers (id);
|
||||||
|
CREATE INDEX idx_servers_name_latest ON servers ((value->>'name'), (value->'_meta'->'io.modelcontextprotocol.registry'->>'is_latest'))
|
||||||
|
WHERE (value->'_meta'->'io.modelcontextprotocol.registry'->>'is_latest')::boolean = true;
|
||||||
|
CREATE INDEX idx_servers_updated_at ON servers ((value->'_meta'->'io.modelcontextprotocol.registry'->>'updated_at'));
|
||||||
|
CREATE INDEX idx_servers_remotes ON servers USING GIN((value->'remotes'));
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue