diff --git a/cmd/publisher/commands/init.go b/cmd/publisher/commands/init.go index 27cb664ac..69f2055e2 100644 --- a/cmd/publisher/commands/init.go +++ b/cmd/publisher/commands/init.go @@ -27,7 +27,10 @@ func InitCommand() error { // Try to detect values from environment name := detectServerName(subfolder) description := detectDescription() - version := "1.0.0" + version := getVersionFromPackageJSON() + if version == "" { + version = "1.0.0" + } repoURL := detectRepoURL() repoSource := MethodGitHub if repoURL != "" && !strings.Contains(repoURL, "github.com") { @@ -140,9 +143,13 @@ func getNameFromPackageJSON() string { return "" } - name, ok := pkg["name"].(string) + // Prefer mcpName over name, as the server name must match mcpName + name, ok := pkg["mcpName"].(string) if !ok || name == "" { - return "" + name, ok = pkg["name"].(string) + if !ok || name == "" { + return "" + } } // Convert npm package name to MCP server name @@ -156,6 +163,25 @@ func getNameFromPackageJSON() string { return fmt.Sprintf("io.github./%s", name) } +func getVersionFromPackageJSON() string { + data, err := os.ReadFile("package.json") + if err != nil { + return "" + } + + var pkg map[string]any + if err := json.Unmarshal(data, &pkg); err != nil { + return "" + } + + version, ok := pkg["version"].(string) + if !ok || version == "" { + return "" + } + + return version +} + func detectServerName(subfolder string) string { // Try to get from git remote repoURL := detectRepoURL()