Skip to content

Commit 52b6d6f

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

File tree

1 file changed

+62
-92
lines changed

1 file changed

+62
-92
lines changed

tools/publisher/main.go

Lines changed: 62 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -13,53 +13,10 @@ import (
1313
"os"
1414
"strings"
1515

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

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

373-
func createServerStructure(
374-
name, description, version, repoURL, repoSource, registryName,
375-
packageName, packageVersion, runtimeHint, execute string,
376-
envVars []string, packageArgs []string, status string,
377-
) ServerJSON {
330+
func createServerStructure(name, description, version, repoURL, repoSource, registryName,
331+
packageName, packageVersion, runtimeHint, execute string, envVars []string, packageArgs []string, status string) model.ServerDetail {
378332
// Parse environment variables
379-
var environmentVariables []EnvironmentVariable
333+
var environmentVariables []model.KeyValueInput
380334
for _, envVar := range envVars {
381335
parts := strings.SplitN(envVar, ":", 2)
336+
envVarName := parts[0]
337+
envVarDesc := fmt.Sprintf("Environment variable for %s", parts[0])
382338
if len(parts) == 2 {
383-
environmentVariables = append(environmentVariables, EnvironmentVariable{
384-
Name: parts[0],
385-
Description: parts[1],
386-
})
387-
} else {
388-
// If no description provided, use a default
389-
environmentVariables = append(environmentVariables, EnvironmentVariable{
390-
Name: parts[0],
391-
Description: fmt.Sprintf("Environment variable for %s", parts[0]),
392-
})
339+
envVarDesc = parts[1]
393340
}
341+
342+
environmentVariables = append(environmentVariables, model.KeyValueInput{
343+
Name: envVarName,
344+
InputWithVariables: model.InputWithVariables{
345+
Input: model.Input{
346+
Description: envVarDesc,
347+
},
348+
},
349+
})
394350
}
395351

396352
// Parse package arguments
397-
var packageArguments []RuntimeArgument
353+
var packageArguments []model.Argument
398354
for i, pkgArg := range packageArgs {
399355
parts := strings.SplitN(pkgArg, ":", 2)
400356
value := parts[0]
@@ -403,19 +359,23 @@ func createServerStructure(
403359
description = parts[1]
404360
}
405361

406-
packageArguments = append(packageArguments, RuntimeArgument{
407-
Description: description,
408-
IsRequired: true, // Package arguments are typically required
409-
Format: "string",
410-
Value: value,
411-
Default: value,
412-
Type: "positional",
413-
ValueHint: value,
362+
packageArguments = append(packageArguments, model.Argument{
363+
InputWithVariables: model.InputWithVariables{
364+
Input: model.Input{
365+
Description: description,
366+
IsRequired: true, // Package arguments are typically required
367+
Format: model.FormatString,
368+
Value: value,
369+
Default: value,
370+
},
371+
},
372+
Type: model.ArgumentTypePositional,
373+
ValueHint: value,
414374
})
415375
}
416376

417377
// Parse execute command to create runtime arguments
418-
var runtimeArguments []RuntimeArgument
378+
var runtimeArguments []model.Argument
419379
if execute != "" {
420380
// Split the execute command into parts, handling quoted strings
421381
parts := smartSplit(execute)
@@ -436,43 +396,53 @@ func createServerStructure(
436396
description = fmt.Sprintf("Value for %s", parts[i])
437397
}
438398

439-
runtimeArguments = append(runtimeArguments, RuntimeArgument{
440-
Description: description,
441-
IsRequired: false,
442-
Format: "string",
443-
Value: arg,
444-
Default: arg,
445-
Type: "positional",
446-
ValueHint: arg,
399+
runtimeArguments = append(runtimeArguments, model.Argument{
400+
InputWithVariables: model.InputWithVariables{
401+
Input: model.Input{
402+
Description: description,
403+
IsRequired: false,
404+
Format: model.FormatString,
405+
Value: arg,
406+
Default: arg,
407+
},
408+
},
409+
Type: model.ArgumentTypePositional,
410+
ValueHint: arg,
447411
})
448412
}
449413
}
450414
}
451415

452416
// Create package
453-
pkg := Package{
417+
pkg := model.Package{
454418
RegistryName: registryName,
455419
Name: packageName,
456420
Version: packageVersion,
457-
RuntimeHint: runtimeHint,
421+
RunTimeHint: runtimeHint,
458422
RuntimeArguments: runtimeArguments,
459423
PackageArguments: packageArguments,
460424
EnvironmentVariables: environmentVariables,
461425
}
462426

463-
// Create server structure
464-
return ServerJSON{
465-
Name: name,
466-
Description: description,
467-
Status: status,
468-
Repository: Repository{
469-
URL: repoURL,
470-
Source: repoSource,
471-
},
472-
VersionDetail: VersionDetail{
473-
Version: version,
427+
// Create server structure using model types
428+
// Note: We only populate the fields we need for publishing
429+
return model.ServerDetail{
430+
Server: model.Server{
431+
Name: name,
432+
Description: description,
433+
Status: model.ServerStatus(status),
434+
Repository: model.Repository{
435+
URL: repoURL,
436+
Source: repoSource,
437+
// Should we allow setting the ID here, or it will be generated by the registry?
438+
},
439+
VersionDetail: model.VersionDetail{
440+
Version: version,
441+
// ReleaseDate and IsLatest will be set by the registry
442+
},
474443
},
475-
Packages: []Package{pkg},
444+
Packages: []model.Package{pkg},
445+
// Remotes can be empty for basic server definitions
476446
}
477447
}
478448

0 commit comments

Comments
 (0)