Skip to content

Commit 604a869

Browse files
committed
feat(publisher): copy version from package.json and prefer mcpName in init
- Copy `version` from package.json to both top-level and package version fields, falling back to "1.0.0" when unavailable (modelcontextprotocol#736) - Prefer `mcpName` over `name` from package.json when detecting server name, as the server name must match mcpName (modelcontextprotocol#737)
1 parent 07fa85f commit 604a869

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

‎cmd/publisher/commands/init.go‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ func InitCommand() error {
2727
// Try to detect values from environment
2828
name := detectServerName(subfolder)
2929
description := detectDescription()
30-
version := "1.0.0"
30+
version := getVersionFromPackageJSON()
31+
if version == "" {
32+
version = "1.0.0"
33+
}
3134
repoURL := detectRepoURL()
3235
repoSource := MethodGitHub
3336
if repoURL != "" && !strings.Contains(repoURL, "github.com") {
@@ -140,9 +143,13 @@ func getNameFromPackageJSON() string {
140143
return ""
141144
}
142145

143-
name, ok := pkg["name"].(string)
146+
// Prefer mcpName over name, as the server name must match mcpName
147+
name, ok := pkg["mcpName"].(string)
144148
if !ok || name == "" {
145-
return ""
149+
name, ok = pkg["name"].(string)
150+
if !ok || name == "" {
151+
return ""
152+
}
146153
}
147154

148155
// Convert npm package name to MCP server name
@@ -156,6 +163,25 @@ func getNameFromPackageJSON() string {
156163
return fmt.Sprintf("io.github.<your-username>/%s", name)
157164
}
158165

166+
func getVersionFromPackageJSON() string {
167+
data, err := os.ReadFile("package.json")
168+
if err != nil {
169+
return ""
170+
}
171+
172+
var pkg map[string]any
173+
if err := json.Unmarshal(data, &pkg); err != nil {
174+
return ""
175+
}
176+
177+
version, ok := pkg["version"].(string)
178+
if !ok || version == "" {
179+
return ""
180+
}
181+
182+
return version
183+
}
184+
159185
func detectServerName(subfolder string) string {
160186
// Try to get from git remote
161187
repoURL := detectRepoURL()

0 commit comments

Comments
 (0)