feat(publisher): copy version from package.json and prefer mcpName in init#1145
Merged
rdimitrov merged 2 commits intomodelcontextprotocol:mainfrom Apr 24, 2026
Conversation
… 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)
rdimitrov
approved these changes
Apr 24, 2026
Member
rdimitrov
left a comment
There was a problem hiding this comment.
Thanks for the contribution, @JosephDoUrden! 🙌
3 tasks
rdimitrov
added a commit
that referenced
this pull request
Apr 24, 2026
When `mcpName` is set in `package.json`, it should be the server name used by `mcp-publisher init`. Two issues addressed: 1. `getNameFromPackageJSON` was running `mcpName` through the npm-name transformation intended for the `name` field, producing a broken double-prefix result like "io.github.<your-username>/io.github.foo/bar". 2. `detectServerName` consulted the git remote before package.json, so a github.com remote or `repository` field silently overrode `mcpName`. Both now return `mcpName` as-is when set. The npm-name transformation is preserved for the `name`-only fallback path. Follow-up to #1145, completes the fix for #737. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
rdimitrov
added a commit
that referenced
this pull request
Apr 25, 2026
#1195) ## Summary Follow-up to #1145. When `mcpName` is set in `package.json`, it should be the server name used by `mcp-publisher init`. Two issues addressed: ### 1. `getNameFromPackageJSON` mangled `mcpName` through npm-name transformation `mcpName` values are already in MCP server name format (e.g. `io.github.foo/bar`). The existing code ran them through the `@scope/name → io.github.scope/name` transform and its `io.github.<your-username>/*` fallback, producing a broken double-prefix result. Example with `"mcpName": "io.github.acme/weather"`: - Before: `io.github.<your-username>/io.github.acme/weather` ❌ - After: `io.github.acme/weather` ✅ ### 2. `detectServerName` consulted git before `mcpName` Even with `mcpName` set in `package.json`, a github.com git remote (or a `repository` field) silently won — the function returned `io.github.<owner>/<repo>` and never looked at `mcpName`. Per the [quickstart docs](https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/quickstart.mdx), *"The value of `mcpName` will be your server's name in the MCP Registry"*, so `mcpName` should take precedence. ## Changes - `cmd/publisher/commands/init.go`: - New `getMcpNameFromPackageJSON()` helper that returns `mcpName` or `""`. - `detectServerName` checks `mcpName` first, before git remote and the `name`-based fallback. - `getNameFromPackageJSON` simplified — the now-redundant `mcpName` branch was removed; it only handles the npm `name` transformation. - `cmd/publisher/commands/init_test.go` (new): 5 cases through the public `InitCommand` API covering `mcpName` as-is, fallback to scoped `name`, fallback to placeholder, version fallback, and `mcpName` winning over a GitHub `repository` URL. This completes the fix for #737. ## Test plan - [x] `go test ./cmd/publisher/commands/` passes (5 new subtests) - [x] `golangci-lint run ./cmd/publisher/commands/` clean - [ ] Manual: `mcp-publisher init` in a git-tracked directory with `package.json` containing `mcpName` produces a `server.json` whose `name` matches `mcpName`, not the repo slug 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses two related enhancements to
mcp-publisher init:Copy
versionfrompackage.json(Makemcp-publisher initcopyversionfrompackage.json#736): Whenpackage.jsonis present and contains aversionfield, it is now used for both the top-levelversionandpackages[].versionin the generatedserver.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
mcpNameovername(mcp-publisher initshould prefermcpNamefrompackage.json#737): The init command now checks formcpNameinpackage.jsonfirst, falling back tonameifmcpNameis not defined. This ensures the generated server name matches the requiredmcpNameproperty.Closes #736
Closes #737
Changes
cmd/publisher/commands/init.go:getVersionFromPackageJSON()helper to read version frompackage.jsonInitCommand()to use detected version with"1.0.0"fallbackgetNameFromPackageJSON()to prefermcpNameovernameTest plan
go build ./cmd/publisher/...compiles without errorsgo test ./cmd/publisher/commands/...passes all existing testsmcp-publisher initin a directory withpackage.jsoncontainingversionandmcpName— verify both are copied toserver.jsonmcp-publisher initin a directory withpackage.jsonwithoutmcpName— verifynameis used as fallbackmcp-publisher initin a directory withoutpackage.json— verify defaults ("1.0.0", directory name) are usedAI Disclosure
AI assistance (Claude) was used for initial code exploration and issue research. The implementation was written and reviewed by the author.