From a1a3303af92a666538f4525b7a3c7785aa53a37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yusufhan=20Sa=C3=A7ak?= <67666222+JosephDoUrden@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:47:24 +0300 Subject: [PATCH] feat(publisher): copy version from package.json and prefer mcpName in init (#1145) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Addresses two related enhancements to `mcp-publisher init`: - **Copy `version` from `package.json`** (#736): When `package.json` is present and contains a `version` field, it is now used for both the top-level `version` and `packages[].version` in the generated `server.json`. Falls back to `"1.0.0"` when unavailable. This aligns with the recommended best practice of keeping server version in sync with package version. - **Prefer `mcpName` over `name`** (#737): The init command now checks for `mcpName` in `package.json` first, falling back to `name` if `mcpName` is not defined. This ensures the generated server name matches the required `mcpName` property. Closes #736 Closes #737 ## Changes - `cmd/publisher/commands/init.go`: - Added `getVersionFromPackageJSON()` helper to read version from `package.json` - Modified `InitCommand()` to use detected version with `"1.0.0"` fallback - Modified `getNameFromPackageJSON()` to prefer `mcpName` over `name` ## Test plan - [x] `go build ./cmd/publisher/...` compiles without errors - [x] `go test ./cmd/publisher/commands/...` passes all existing tests - [ ] Manual: run `mcp-publisher init` in a directory with `package.json` containing `version` and `mcpName` — verify both are copied to `server.json` - [ ] Manual: run `mcp-publisher init` in a directory with `package.json` without `mcpName` — verify `name` is used as fallback - [ ] Manual: run `mcp-publisher init` in a directory without `package.json` — verify defaults (`"1.0.0"`, directory name) are used ## AI Disclosure AI assistance (Claude) was used for initial code exploration and issue research. The implementation was written and reviewed by the author. Co-authored-by: Radoslav Dimitrov --- cmd/publisher/commands/init.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/cmd/publisher/commands/init.go b/cmd/publisher/commands/init.go index 8d0b505..8e645f5 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()