Skip to content

Commit e9420e8

Browse files
committed
Fix struct duplication between internal/model and tools/publisher
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent d461400 commit e9420e8

File tree

1 file changed

+61
-88
lines changed

1 file changed

+61
-88
lines changed

tools/publisher/main.go

Lines changed: 61 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,11 @@ import (
1313
"os"
1414
"strings"
1515

16+
"github.com/modelcontextprotocol/registry/internal/model"
1617
"github.com/modelcontextprotocol/registry/tools/publisher/auth"
1718
"github.com/modelcontextprotocol/registry/tools/publisher/auth/github"
1819
)
1920

20-
// Server structure types for JSON generation
21-
type Repository struct {
22-
URL string `json:"url"`
23-
Source string `json:"source"`
24-
}
25-
26-
type VersionDetail struct {
27-
Version string `json:"version"`
28-
}
29-
30-
type EnvironmentVariable struct {
31-
Name string `json:"name"`
32-
Description string `json:"description"`
33-
}
34-
35-
type RuntimeArgument struct {
36-
Description string `json:"description"`
37-
IsRequired bool `json:"is_required"`
38-
Format string `json:"format"`
39-
Value string `json:"value"`
40-
Default string `json:"default"`
41-
Type string `json:"type"`
42-
ValueHint string `json:"value_hint"`
43-
}
44-
45-
type Package struct {
46-
RegistryName string `json:"registry_name"`
47-
Name string `json:"name"`
48-
Version string `json:"version"`
49-
RuntimeHint string `json:"runtime_hint,omitempty"`
50-
RuntimeArguments []RuntimeArgument `json:"runtime_arguments,omitempty"`
51-
PackageArguments []RuntimeArgument `json:"package_arguments,omitempty"`
52-
EnvironmentVariables []EnvironmentVariable `json:"environment_variables,omitempty"`
53-
}
54-
55-
type ServerJSON struct {
56-
Name string `json:"name"`
57-
Description string `json:"description"`
58-
Status string `json:"status,omitempty"`
59-
Repository Repository `json:"repository"`
60-
VersionDetail VersionDetail `json:"version_detail"`
61-
Packages []Package `json:"packages"`
62-
}
63-
6421
func main() {
6522
if len(os.Args) < 2 {
6623
printUsage()
@@ -361,27 +318,29 @@ func publishToRegistry(registryURL string, mcpData []byte, token string) error {
361318
}
362319

363320
func createServerStructure(name, description, version, repoURL, repoSource, registryName,
364-
packageName, packageVersion, runtimeHint, execute string, envVars []string, packageArgs []string, status string) ServerJSON {
321+
packageName, packageVersion, runtimeHint, execute string, envVars []string, packageArgs []string, status string) model.ServerDetail {
365322
// Parse environment variables
366-
var environmentVariables []EnvironmentVariable
323+
var environmentVariables []model.KeyValueInput
367324
for _, envVar := range envVars {
368325
parts := strings.SplitN(envVar, ":", 2)
326+
envVarName := parts[0]
327+
envVarDesc := fmt.Sprintf("Environment variable for %s", parts[0])
369328
if len(parts) == 2 {
370-
environmentVariables = append(environmentVariables, EnvironmentVariable{
371-
Name: parts[0],
372-
Description: parts[1],
373-
})
374-
} else {
375-
// If no description provided, use a default
376-
environmentVariables = append(environmentVariables, EnvironmentVariable{
377-
Name: parts[0],
378-
Description: fmt.Sprintf("Environment variable for %s", parts[0]),
379-
})
329+
envVarDesc = parts[1]
380330
}
331+
332+
environmentVariables = append(environmentVariables, model.KeyValueInput{
333+
Name: envVarName,
334+
InputWithVariables: model.InputWithVariables{
335+
Input: model.Input{
336+
Description: envVarDesc,
337+
},
338+
},
339+
})
381340
}
382341

383342
// Parse package arguments
384-
var packageArguments []RuntimeArgument
343+
var packageArguments []model.Argument
385344
for i, pkgArg := range packageArgs {
386345
parts := strings.SplitN(pkgArg, ":", 2)
387346
value := parts[0]
@@ -390,19 +349,23 @@ func createServerStructure(name, description, version, repoURL, repoSource, regi
390349
description = parts[1]
391350
}
392351

393-
packageArguments = append(packageArguments, RuntimeArgument{
394-
Description: description,
395-
IsRequired: true, // Package arguments are typically required
396-
Format: "string",
397-
Value: value,
398-
Default: value,
399-
Type: "positional",
400-
ValueHint: value,
352+
packageArguments = append(packageArguments, model.Argument{
353+
InputWithVariables: model.InputWithVariables{
354+
Input: model.Input{
355+
Description: description,
356+
IsRequired: true, // Package arguments are typically required
357+
Format: model.FormatString,
358+
Value: value,
359+
Default: value,
360+
},
361+
},
362+
Type: model.ArgumentTypePositional,
363+
ValueHint: value,
401364
})
402365
}
403366

404367
// Parse execute command to create runtime arguments
405-
var runtimeArguments []RuntimeArgument
368+
var runtimeArguments []model.Argument
406369
if execute != "" {
407370
// Split the execute command into parts, handling quoted strings
408371
parts := smartSplit(execute)
@@ -423,43 +386,53 @@ func createServerStructure(name, description, version, repoURL, repoSource, regi
423386
description = fmt.Sprintf("Value for %s", parts[i])
424387
}
425388

426-
runtimeArguments = append(runtimeArguments, RuntimeArgument{
427-
Description: description,
428-
IsRequired: false,
429-
Format: "string",
430-
Value: arg,
431-
Default: arg,
432-
Type: "positional",
433-
ValueHint: arg,
389+
runtimeArguments = append(runtimeArguments, model.Argument{
390+
InputWithVariables: model.InputWithVariables{
391+
Input: model.Input{
392+
Description: description,
393+
IsRequired: false,
394+
Format: model.FormatString,
395+
Value: arg,
396+
Default: arg,
397+
},
398+
},
399+
Type: model.ArgumentTypePositional,
400+
ValueHint: arg,
434401
})
435402
}
436403
}
437404
}
438405

439406
// Create package
440-
pkg := Package{
407+
pkg := model.Package{
441408
RegistryName: registryName,
442409
Name: packageName,
443410
Version: packageVersion,
444-
RuntimeHint: runtimeHint,
411+
RunTimeHint: runtimeHint,
445412
RuntimeArguments: runtimeArguments,
446413
PackageArguments: packageArguments,
447414
EnvironmentVariables: environmentVariables,
448415
}
449416

450-
// Create server structure
451-
return ServerJSON{
452-
Name: name,
453-
Description: description,
454-
Status: status,
455-
Repository: Repository{
456-
URL: repoURL,
457-
Source: repoSource,
458-
},
459-
VersionDetail: VersionDetail{
460-
Version: version,
417+
// Create server structure using model types
418+
// Note: We only populate the fields we need for publishing
419+
return model.ServerDetail{
420+
Server: model.Server{
421+
Name: name,
422+
Description: description,
423+
Status: model.ServerStatus(status),
424+
Repository: model.Repository{
425+
URL: repoURL,
426+
Source: repoSource,
427+
// Should we allow setting the ID here, or it will be generated by the registry?
428+
},
429+
VersionDetail: model.VersionDetail{
430+
Version: version,
431+
// ReleaseDate and IsLatest will be set by the registry
432+
},
461433
},
462-
Packages: []Package{pkg},
434+
Packages: []model.Package{pkg},
435+
// Remotes can be empty for basic server definitions
463436
}
464437
}
465438

0 commit comments

Comments
 (0)