Skip to content

feat(publisher): copy version from package.json and prefer mcpName in init#1145

Merged
rdimitrov merged 2 commits intomodelcontextprotocol:mainfrom
JosephDoUrden:fix/init-copy-version-and-mcpname
Apr 24, 2026
Merged

feat(publisher): copy version from package.json and prefer mcpName in init#1145
rdimitrov merged 2 commits intomodelcontextprotocol:mainfrom
JosephDoUrden:fix/init-copy-version-and-mcpname

Conversation

@JosephDoUrden
Copy link
Copy Markdown
Contributor

Summary

Addresses two related enhancements to mcp-publisher init:

  • Copy version from package.json (Make 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 (mcp-publisher init should prefer mcpName from package.json #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

  • go build ./cmd/publisher/... compiles without errors
  • 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.

JosephDoUrden and others added 2 commits April 10, 2026 11:55
… 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)
Copy link
Copy Markdown
Member

@rdimitrov rdimitrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, @JosephDoUrden! 🙌

@rdimitrov rdimitrov merged commit a1a3303 into modelcontextprotocol:main Apr 24, 2026
3 checks passed
@JosephDoUrden JosephDoUrden deleted the fix/init-copy-version-and-mcpname branch April 24, 2026 09:49
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp-publisher init should prefer mcpName from package.json Make mcp-publisher init copy version from package.json

2 participants