From 52b6d6fef4c19dc67c94eeeaf7faf32a9c649f56 Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Fri, 1 Aug 2025 01:11:04 +0300 Subject: [PATCH 1/2] Fix struct duplication between internal/model and tools/publisher Signed-off-by: Radoslav Dimitrov --- tools/publisher/main.go | 154 ++++++++++++++++------------------------ 1 file changed, 62 insertions(+), 92 deletions(-) diff --git a/tools/publisher/main.go b/tools/publisher/main.go index d7813d7c..7f9ff578 100644 --- a/tools/publisher/main.go +++ b/tools/publisher/main.go @@ -13,53 +13,10 @@ import ( "os" "strings" + "github.com/modelcontextprotocol/registry/internal/model" "github.com/modelcontextprotocol/registry/tools/publisher/auth" ) -// Server structure types for JSON generation -type Repository struct { - URL string `json:"url"` - Source string `json:"source"` -} - -type VersionDetail struct { - Version string `json:"version"` -} - -type EnvironmentVariable struct { - Name string `json:"name"` - Description string `json:"description"` -} - -type RuntimeArgument struct { - Description string `json:"description"` - IsRequired bool `json:"is_required"` - Format string `json:"format"` - Value string `json:"value"` - Default string `json:"default"` - Type string `json:"type"` - ValueHint string `json:"value_hint"` -} - -type Package struct { - RegistryName string `json:"registry_name"` - Name string `json:"name"` - Version string `json:"version"` - RuntimeHint string `json:"runtime_hint,omitempty"` - RuntimeArguments []RuntimeArgument `json:"runtime_arguments,omitempty"` - PackageArguments []RuntimeArgument `json:"package_arguments,omitempty"` - EnvironmentVariables []EnvironmentVariable `json:"environment_variables,omitempty"` -} - -type ServerJSON struct { - Name string `json:"name"` - Description string `json:"description"` - Status string `json:"status,omitempty"` - Repository Repository `json:"repository"` - VersionDetail VersionDetail `json:"version_detail"` - Packages []Package `json:"packages"` -} - func main() { if len(os.Args) < 2 { printUsage() @@ -370,31 +327,30 @@ func publishToRegistry(registryURL string, mcpData []byte, token string) error { return nil } -func createServerStructure( - name, description, version, repoURL, repoSource, registryName, - packageName, packageVersion, runtimeHint, execute string, - envVars []string, packageArgs []string, status string, -) ServerJSON { +func createServerStructure(name, description, version, repoURL, repoSource, registryName, + packageName, packageVersion, runtimeHint, execute string, envVars []string, packageArgs []string, status string) model.ServerDetail { // Parse environment variables - var environmentVariables []EnvironmentVariable + var environmentVariables []model.KeyValueInput for _, envVar := range envVars { parts := strings.SplitN(envVar, ":", 2) + envVarName := parts[0] + envVarDesc := fmt.Sprintf("Environment variable for %s", parts[0]) if len(parts) == 2 { - environmentVariables = append(environmentVariables, EnvironmentVariable{ - Name: parts[0], - Description: parts[1], - }) - } else { - // If no description provided, use a default - environmentVariables = append(environmentVariables, EnvironmentVariable{ - Name: parts[0], - Description: fmt.Sprintf("Environment variable for %s", parts[0]), - }) + envVarDesc = parts[1] } + + environmentVariables = append(environmentVariables, model.KeyValueInput{ + Name: envVarName, + InputWithVariables: model.InputWithVariables{ + Input: model.Input{ + Description: envVarDesc, + }, + }, + }) } // Parse package arguments - var packageArguments []RuntimeArgument + var packageArguments []model.Argument for i, pkgArg := range packageArgs { parts := strings.SplitN(pkgArg, ":", 2) value := parts[0] @@ -403,19 +359,23 @@ func createServerStructure( description = parts[1] } - packageArguments = append(packageArguments, RuntimeArgument{ - Description: description, - IsRequired: true, // Package arguments are typically required - Format: "string", - Value: value, - Default: value, - Type: "positional", - ValueHint: value, + packageArguments = append(packageArguments, model.Argument{ + InputWithVariables: model.InputWithVariables{ + Input: model.Input{ + Description: description, + IsRequired: true, // Package arguments are typically required + Format: model.FormatString, + Value: value, + Default: value, + }, + }, + Type: model.ArgumentTypePositional, + ValueHint: value, }) } // Parse execute command to create runtime arguments - var runtimeArguments []RuntimeArgument + var runtimeArguments []model.Argument if execute != "" { // Split the execute command into parts, handling quoted strings parts := smartSplit(execute) @@ -436,43 +396,53 @@ func createServerStructure( description = fmt.Sprintf("Value for %s", parts[i]) } - runtimeArguments = append(runtimeArguments, RuntimeArgument{ - Description: description, - IsRequired: false, - Format: "string", - Value: arg, - Default: arg, - Type: "positional", - ValueHint: arg, + runtimeArguments = append(runtimeArguments, model.Argument{ + InputWithVariables: model.InputWithVariables{ + Input: model.Input{ + Description: description, + IsRequired: false, + Format: model.FormatString, + Value: arg, + Default: arg, + }, + }, + Type: model.ArgumentTypePositional, + ValueHint: arg, }) } } } // Create package - pkg := Package{ + pkg := model.Package{ RegistryName: registryName, Name: packageName, Version: packageVersion, - RuntimeHint: runtimeHint, + RunTimeHint: runtimeHint, RuntimeArguments: runtimeArguments, PackageArguments: packageArguments, EnvironmentVariables: environmentVariables, } - // Create server structure - return ServerJSON{ - Name: name, - Description: description, - Status: status, - Repository: Repository{ - URL: repoURL, - Source: repoSource, - }, - VersionDetail: VersionDetail{ - Version: version, + // Create server structure using model types + // Note: We only populate the fields we need for publishing + return model.ServerDetail{ + Server: model.Server{ + Name: name, + Description: description, + Status: model.ServerStatus(status), + Repository: model.Repository{ + URL: repoURL, + Source: repoSource, + // Should we allow setting the ID here, or it will be generated by the registry? + }, + VersionDetail: model.VersionDetail{ + Version: version, + // ReleaseDate and IsLatest will be set by the registry + }, }, - Packages: []Package{pkg}, + Packages: []model.Package{pkg}, + // Remotes can be empty for basic server definitions } } From a0123ba8bb2169fe14997dc9823c8725cda9676e Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Wed, 20 Aug 2025 15:58:43 +0300 Subject: [PATCH 2/2] Move model from internal to pkg Signed-off-by: Radoslav Dimitrov --- cmd/registry/main.go | 2 +- internal/api/handlers/v0/auth/github_at.go | 2 +- internal/api/handlers/v0/auth/github_at_test.go | 2 +- internal/api/handlers/v0/auth/github_oidc.go | 2 +- internal/api/handlers/v0/auth/github_oidc_test.go | 2 +- internal/api/handlers/v0/auth/none.go | 2 +- internal/api/handlers/v0/auth/none_test.go | 2 +- internal/api/handlers/v0/publish.go | 2 +- internal/api/handlers/v0/publish_integration_test.go | 2 +- internal/api/handlers/v0/publish_test.go | 2 +- internal/api/handlers/v0/servers.go | 2 +- internal/api/handlers/v0/servers_test.go | 2 +- internal/auth/jwt.go | 2 +- internal/auth/jwt_test.go | 2 +- internal/database/database.go | 2 +- internal/database/import.go | 2 +- internal/database/import_test.go | 2 +- internal/database/memory.go | 2 +- internal/database/mongo.go | 2 +- internal/service/fake_service.go | 2 +- internal/service/registry_service.go | 2 +- internal/service/service.go | 2 +- {internal => pkg}/model/model.go | 0 tools/publisher/main.go | 2 +- 24 files changed, 23 insertions(+), 23 deletions(-) rename {internal => pkg}/model/model.go (100%) diff --git a/cmd/registry/main.go b/cmd/registry/main.go index 8b4c2638..c9a43983 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -14,7 +14,7 @@ import ( "github.com/modelcontextprotocol/registry/internal/api" "github.com/modelcontextprotocol/registry/internal/config" "github.com/modelcontextprotocol/registry/internal/database" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/modelcontextprotocol/registry/internal/service" ) diff --git a/internal/api/handlers/v0/auth/github_at.go b/internal/api/handlers/v0/auth/github_at.go index d4ef7e07..1a86dba5 100644 --- a/internal/api/handlers/v0/auth/github_at.go +++ b/internal/api/handlers/v0/auth/github_at.go @@ -12,7 +12,7 @@ import ( v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // GitHubTokenExchangeInput represents the input for GitHub token exchange diff --git a/internal/api/handlers/v0/auth/github_at_test.go b/internal/api/handlers/v0/auth/github_at_test.go index c57beba0..af49611d 100644 --- a/internal/api/handlers/v0/auth/github_at_test.go +++ b/internal/api/handlers/v0/auth/github_at_test.go @@ -16,7 +16,7 @@ import ( v0auth "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/api/handlers/v0/auth/github_oidc.go b/internal/api/handlers/v0/auth/github_oidc.go index 0cd8f96d..fb7df2b7 100644 --- a/internal/api/handlers/v0/auth/github_oidc.go +++ b/internal/api/handlers/v0/auth/github_oidc.go @@ -15,7 +15,7 @@ import ( v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // GitHubOIDCTokenExchangeInput represents the input for GitHub OIDC token exchange diff --git a/internal/api/handlers/v0/auth/github_oidc_test.go b/internal/api/handlers/v0/auth/github_oidc_test.go index c83470e3..7782b841 100644 --- a/internal/api/handlers/v0/auth/github_oidc_test.go +++ b/internal/api/handlers/v0/auth/github_oidc_test.go @@ -11,7 +11,7 @@ import ( "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth" internalauth "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/api/handlers/v0/auth/none.go b/internal/api/handlers/v0/auth/none.go index 41e5288f..42dd60b9 100644 --- a/internal/api/handlers/v0/auth/none.go +++ b/internal/api/handlers/v0/auth/none.go @@ -9,7 +9,7 @@ import ( v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // NoneHandler handles anonymous authentication diff --git a/internal/api/handlers/v0/auth/none_test.go b/internal/api/handlers/v0/auth/none_test.go index bc250b3c..8b680d83 100644 --- a/internal/api/handlers/v0/auth/none_test.go +++ b/internal/api/handlers/v0/auth/none_test.go @@ -10,7 +10,7 @@ import ( v0auth "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/api/handlers/v0/publish.go b/internal/api/handlers/v0/publish.go index b2e9bfd6..d5fc0d5f 100644 --- a/internal/api/handlers/v0/publish.go +++ b/internal/api/handlers/v0/publish.go @@ -8,7 +8,7 @@ import ( "github.com/danielgtaylor/huma/v2" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/modelcontextprotocol/registry/internal/service" ) diff --git a/internal/api/handlers/v0/publish_integration_test.go b/internal/api/handlers/v0/publish_integration_test.go index e3a098dc..4a89f630 100644 --- a/internal/api/handlers/v0/publish_integration_test.go +++ b/internal/api/handlers/v0/publish_integration_test.go @@ -16,7 +16,7 @@ import ( v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/modelcontextprotocol/registry/internal/service" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/api/handlers/v0/publish_test.go b/internal/api/handlers/v0/publish_test.go index a3117111..d60b2313 100644 --- a/internal/api/handlers/v0/publish_test.go +++ b/internal/api/handlers/v0/publish_test.go @@ -17,7 +17,7 @@ import ( v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/internal/api/handlers/v0/servers.go b/internal/api/handlers/v0/servers.go index faa0b2eb..7909ef59 100644 --- a/internal/api/handlers/v0/servers.go +++ b/internal/api/handlers/v0/servers.go @@ -6,7 +6,7 @@ import ( "github.com/danielgtaylor/huma/v2" "github.com/google/uuid" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/modelcontextprotocol/registry/internal/service" ) diff --git a/internal/api/handlers/v0/servers_test.go b/internal/api/handlers/v0/servers_test.go index 1945aa02..c328df20 100644 --- a/internal/api/handlers/v0/servers_test.go +++ b/internal/api/handlers/v0/servers_test.go @@ -12,7 +12,7 @@ import ( "github.com/danielgtaylor/huma/v2/adapters/humago" "github.com/google/uuid" v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" ) diff --git a/internal/auth/jwt.go b/internal/auth/jwt.go index 114c658e..664178ed 100644 --- a/internal/auth/jwt.go +++ b/internal/auth/jwt.go @@ -10,7 +10,7 @@ import ( "github.com/golang-jwt/jwt/v5" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // PermissionAction represents the type of action that can be performed diff --git a/internal/auth/jwt_test.go b/internal/auth/jwt_test.go index 8aaf0ee8..303d1195 100644 --- a/internal/auth/jwt_test.go +++ b/internal/auth/jwt_test.go @@ -11,7 +11,7 @@ import ( "github.com/golang-jwt/jwt/v5" "github.com/modelcontextprotocol/registry/internal/auth" "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/database/database.go b/internal/database/database.go index d145f0c6..bee95373 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -4,7 +4,7 @@ import ( "context" "errors" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // Common database errors diff --git a/internal/database/import.go b/internal/database/import.go index 8c39143b..7ed33769 100644 --- a/internal/database/import.go +++ b/internal/database/import.go @@ -13,7 +13,7 @@ import ( "strings" "time" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // ReadSeedFile reads seed data from various sources: diff --git a/internal/database/import_test.go b/internal/database/import_test.go index cda9eeaf..2e066aea 100644 --- a/internal/database/import_test.go +++ b/internal/database/import_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/modelcontextprotocol/registry/internal/database" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" ) diff --git a/internal/database/memory.go b/internal/database/memory.go index 2efcb64c..f9e8bbc8 100644 --- a/internal/database/memory.go +++ b/internal/database/memory.go @@ -11,7 +11,7 @@ import ( "time" "github.com/google/uuid" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // MemoryDB is an in-memory implementation of the Database interface diff --git a/internal/database/mongo.go b/internal/database/mongo.go index 3e93aa6c..6ea33412 100644 --- a/internal/database/mongo.go +++ b/internal/database/mongo.go @@ -8,7 +8,7 @@ import ( "time" "github.com/google/uuid" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" diff --git a/internal/service/fake_service.go b/internal/service/fake_service.go index 07aa805d..7e046c42 100644 --- a/internal/service/fake_service.go +++ b/internal/service/fake_service.go @@ -6,7 +6,7 @@ import ( "github.com/google/uuid" "github.com/modelcontextprotocol/registry/internal/database" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // fakeRegistryService implements RegistryService interface with an in-memory database diff --git a/internal/service/registry_service.go b/internal/service/registry_service.go index d9798be3..9b7020a8 100644 --- a/internal/service/registry_service.go +++ b/internal/service/registry_service.go @@ -5,7 +5,7 @@ import ( "time" "github.com/modelcontextprotocol/registry/internal/database" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" ) // registryServiceImpl implements the RegistryService interface using our Database diff --git a/internal/service/service.go b/internal/service/service.go index a3e14019..4a8db6fe 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -1,6 +1,6 @@ package service -import "github.com/modelcontextprotocol/registry/internal/model" +import "github.com/modelcontextprotocol/registry/pkg/model" // RegistryService defines the interface for registry operations type RegistryService interface { diff --git a/internal/model/model.go b/pkg/model/model.go similarity index 100% rename from internal/model/model.go rename to pkg/model/model.go diff --git a/tools/publisher/main.go b/tools/publisher/main.go index 7f9ff578..635bbdb1 100644 --- a/tools/publisher/main.go +++ b/tools/publisher/main.go @@ -13,7 +13,7 @@ import ( "os" "strings" - "github.com/modelcontextprotocol/registry/internal/model" + "github.com/modelcontextprotocol/registry/pkg/model" "github.com/modelcontextprotocol/registry/tools/publisher/auth" )