Commit a1a3303
feat(publisher): copy version from package.json and prefer mcpName in init (#1145)
## 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 <radoslav@stacklok.com>1 parent 35b1243 commit a1a3303
1 file changed
Lines changed: 29 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
| |||
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
143 | | - | |
| 146 | + | |
| 147 | + | |
144 | 148 | | |
145 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
146 | 153 | | |
147 | 154 | | |
148 | 155 | | |
| |||
156 | 163 | | |
157 | 164 | | |
158 | 165 | | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
159 | 185 | | |
160 | 186 | | |
161 | 187 | | |
| |||
0 commit comments