PUBLISH.md•3.05 kB
# Step-by-Step Guide to Publish to npm
## Step 1: Check Package Name Availability
The name `mcp-ping` is already taken. You have two options:
### Option A: Use a Scoped Package (Recommended)
Use your npm username as a scope: `@yourusername/mcp-ping`
### Option B: Choose a Different Name
Pick a unique name like `mcp-ping-server` or `@mcp/ping`
## Step 2: Update package.json
If using a scoped package, update the name in `package.json`:
```json
{
"name": "@yourusername/mcp-ping",
...
}
```
Or choose a different unique name:
```json
{
"name": "mcp-ping-server",
...
}
```
## Step 3: Login to npm
```bash
npm login
```
You'll be prompted for:
- Username
- Password
- Email address
- One-time password (if you have 2FA enabled)
Verify you're logged in:
```bash
npm whoami
```
## Step 4: Build the Package
```bash
npm run build
```
This will:
- Compile TypeScript to JavaScript
- Add the shebang to the binary
- Make the file executable
## Step 5: Test Locally (Optional but Recommended)
Test the package locally before publishing:
```bash
# Install locally
npm link
# Test it works
mcp-ping
# Should output: "MCP Ping Server running on stdio"
# Unlink when done testing
npm unlink -g mcp-ping
```
## Step 6: Check What Will Be Published
```bash
npm pack --dry-run
```
This shows what files will be included in the package. Should include:
- `dist/` directory
- `README.md`
- `LICENSE`
- `package.json`
## Step 7: Publish to npm
### For Scoped Packages (if using @username/package-name):
```bash
npm publish --access public
```
The `--access public` flag is required for scoped packages (they're private by default).
### For Regular Packages:
```bash
npm publish
```
## Step 8: Verify Publication
Check your package on npm:
```bash
npm view <your-package-name>
```
Or visit: https://www.npmjs.com/package/<your-package-name>
## Step 9: Test Installation
Test that others can install it:
```bash
# Using npx (no installation)
npx <your-package-name>
# Or install globally
npm install -g <your-package-name>
<your-package-name>
```
## Troubleshooting
### "Package name already exists"
- Use a scoped package name (`@username/package-name`)
- Or choose a different name
### "You do not have permission"
- Make sure you're logged in: `npm whoami`
- For scoped packages, ensure you own the scope or use `--access public`
### "Invalid package name"
- Package names must be lowercase
- Can contain hyphens and underscores
- Scoped packages: `@scope/package-name`
### "Version already exists"
- Update the version in `package.json` (e.g., `1.0.1`)
- Or use `npm version patch/minor/major` to bump version
## Updating the Package
When you make changes:
1. Update version in `package.json`:
```bash
npm version patch # for bug fixes (1.0.0 -> 1.0.1)
npm version minor # for new features (1.0.0 -> 1.1.0)
npm version major # for breaking changes (1.0.0 -> 2.0.0)
```
2. Build and publish:
```bash
npm run build
npm publish # or npm publish --access public for scoped packages
```