|
| 1 | +# Complete Example: Adding a Feature and Publishing |
| 2 | + |
| 3 | +This is a step-by-step walkthrough of adding a feature and releasing it. |
| 4 | + |
| 5 | +## Scenario |
| 6 | + |
| 7 | +You want to add a new `useMcpTools()` React hook to the `mcp-use` package. |
| 8 | + |
| 9 | +## Step 1: Create Feature Branch |
| 10 | + |
| 11 | +```bash |
| 12 | +git checkout main |
| 13 | +git pull origin main |
| 14 | +git checkout -b feat/add-use-mcp-tools-hook |
| 15 | +``` |
| 16 | + |
| 17 | +## Step 2: Implement the Feature |
| 18 | + |
| 19 | +```typescript |
| 20 | +// packages/mcp-use/src/react/hooks/useMcpTools.ts |
| 21 | +import { useState, useEffect } from 'react'; |
| 22 | +import { MCPClient } from '../../client.js'; |
| 23 | + |
| 24 | +export function useMcpTools(serverName: string) { |
| 25 | + const [tools, setTools] = useState([]); |
| 26 | + const [loading, setLoading] = useState(true); |
| 27 | + |
| 28 | + useEffect(() => { |
| 29 | + // Implementation... |
| 30 | + }, [serverName]); |
| 31 | + |
| 32 | + return { tools, loading }; |
| 33 | +} |
| 34 | + |
| 35 | +// Export from packages/mcp-use/src/react/index.ts |
| 36 | +export { useMcpTools } from './hooks/useMcpTools.js'; |
| 37 | +``` |
| 38 | + |
| 39 | +## Step 3: Build and Test Locally |
| 40 | + |
| 41 | +```bash |
| 42 | +# Build all packages |
| 43 | +pnpm build |
| 44 | + |
| 45 | +# Output: |
| 46 | +# packages/mcp-use build: ESM ⚡️ Build success in 42ms |
| 47 | +# packages/mcp-use build: CJS ⚡️ Build success in 42ms |
| 48 | +# ✓ All packages built successfully |
| 49 | + |
| 50 | +# Run tests |
| 51 | +pnpm test |
| 52 | + |
| 53 | +# Run linter |
| 54 | +pnpm lint |
| 55 | +``` |
| 56 | + |
| 57 | +## Step 4: Create a Changeset |
| 58 | + |
| 59 | +```bash |
| 60 | +pnpm changeset |
| 61 | +``` |
| 62 | + |
| 63 | +**Interactive Prompts:** |
| 64 | + |
| 65 | +``` |
| 66 | +🦋 Which packages would you like to include? |
| 67 | +◉ mcp-use |
| 68 | +◯ @mcp-use/cli |
| 69 | +◯ @mcp-use/inspector |
| 70 | +◯ create-mcp-use-app |
| 71 | +
|
| 72 | +🦋 What kind of change is this for mcp-use? |
| 73 | +◯ major |
| 74 | +◉ minor ← Select this (new feature) |
| 75 | +◯ patch |
| 76 | +
|
| 77 | +🦋 Please enter a summary for this change (this will be written to the changelog): |
| 78 | +Added useMcpTools React hook for easier tool management |
| 79 | +``` |
| 80 | + |
| 81 | +**Result:** Creates `.changeset/random-name-here.md` |
| 82 | + |
| 83 | +```md |
| 84 | +--- |
| 85 | +"mcp-use": minor |
| 86 | +--- |
| 87 | + |
| 88 | +Added useMcpTools React hook for easier tool management |
| 89 | +``` |
| 90 | + |
| 91 | +## Step 5: Commit Everything |
| 92 | + |
| 93 | +```bash |
| 94 | +git add . |
| 95 | +git commit -m "feat: add useMcpTools React hook" |
| 96 | +git push origin feat/add-use-mcp-tools-hook |
| 97 | +``` |
| 98 | + |
| 99 | +## Step 6: Create Pull Request |
| 100 | + |
| 101 | +Create a PR on GitHub with: |
| 102 | + |
| 103 | +**Title:** `feat: add useMcpTools React hook` |
| 104 | + |
| 105 | +**Description:** |
| 106 | +```markdown |
| 107 | +## What |
| 108 | + |
| 109 | +Adds a new `useMcpTools()` React hook for managing MCP tools. |
| 110 | + |
| 111 | +## Why |
| 112 | + |
| 113 | +Simplifies tool management in React applications. |
| 114 | + |
| 115 | +## Changes |
| 116 | + |
| 117 | +- Added `useMcpTools` hook in `packages/mcp-use/src/react/hooks/` |
| 118 | +- Exported from `mcp-use/react` |
| 119 | +- Added tests for the new hook |
| 120 | + |
| 121 | +## Changeset |
| 122 | + |
| 123 | +✅ Changeset included (minor bump for mcp-use) |
| 124 | +``` |
| 125 | + |
| 126 | +## Step 7: Review & Merge |
| 127 | + |
| 128 | +After review and approval: |
| 129 | + |
| 130 | +```bash |
| 131 | +# Merge the PR to main |
| 132 | +``` |
| 133 | + |
| 134 | +## Step 8: Release (Maintainer Task) |
| 135 | + |
| 136 | +On the `main` branch after merge: |
| 137 | + |
| 138 | +```bash |
| 139 | +# Switch to main and pull |
| 140 | +git checkout main |
| 141 | +git pull origin main |
| 142 | + |
| 143 | +# Check what will be versioned |
| 144 | +pnpm version:check |
| 145 | +``` |
| 146 | + |
| 147 | +**Output:** |
| 148 | +``` |
| 149 | +🦋 info Packages to be bumped at minor: |
| 150 | +🦋 - mcp-use (0.2.0 → 0.3.0) |
| 151 | +🦋 |
| 152 | +🦋 info Packages to be bumped at patch: |
| 153 | +🦋 - @mcp-use/cli (2.0.1 → 2.0.2) ← depends on mcp-use |
| 154 | +🦋 - @mcp-use/inspector (0.1.0 → 0.1.1) ← depends on mcp-use |
| 155 | +``` |
| 156 | + |
| 157 | +```bash |
| 158 | +# Apply the version changes |
| 159 | +pnpm version |
| 160 | +``` |
| 161 | + |
| 162 | +**This will:** |
| 163 | +1. Update `mcp-use/package.json` to `0.3.0` |
| 164 | +2. Update dependent packages (`@mcp-use/cli`, `@mcp-use/inspector`) with patch bumps |
| 165 | +3. Generate/update `CHANGELOG.md` in each package: |
| 166 | + |
| 167 | +```markdown |
| 168 | +# mcp-use |
| 169 | + |
| 170 | +## 0.3.0 |
| 171 | + |
| 172 | +### Minor Changes |
| 173 | + |
| 174 | +- abc1234: Added useMcpTools React hook for easier tool management |
| 175 | + |
| 176 | +## 0.2.0 |
| 177 | +... |
| 178 | +``` |
| 179 | + |
| 180 | +4. Delete `.changeset/random-name-here.md` |
| 181 | +5. Update `pnpm-lock.yaml` |
| 182 | + |
| 183 | +```bash |
| 184 | +# Review the changes |
| 185 | +git diff |
| 186 | + |
| 187 | +# Commit the version changes |
| 188 | +git add . |
| 189 | +git commit -m "chore: version packages" |
| 190 | +git push origin main |
| 191 | +``` |
| 192 | + |
| 193 | +## Step 9: Publish to npm |
| 194 | + |
| 195 | +```bash |
| 196 | +# Build everything |
| 197 | +pnpm build |
| 198 | + |
| 199 | +# Publish to npm |
| 200 | +pnpm release |
| 201 | +``` |
| 202 | + |
| 203 | +**This will:** |
| 204 | +1. Build all packages with tsup |
| 205 | +2. Run `changeset publish` |
| 206 | +3. Publish `[email protected]` to npm |
| 207 | +4. Publish `@mcp-use/[email protected]` to npm |
| 208 | +5. Publish `@mcp-use/[email protected]` to npm |
| 209 | +6. Create git tags for each version |
| 210 | + |
| 211 | +**Output:** |
| 212 | +``` |
| 213 | +🦋 info npm info mcp-use |
| 214 | +🦋 info npm publish [email protected] |
| 215 | +🦋 success packages published successfully: |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | +``` |
| 220 | + |
| 221 | +```bash |
| 222 | +# Push tags |
| 223 | +git push --follow-tags |
| 224 | +``` |
| 225 | + |
| 226 | +## Step 10: Verify Publication |
| 227 | + |
| 228 | +```bash |
| 229 | +# Check on npm |
| 230 | +npm view mcp-use version |
| 231 | +# Output: 0.3.0 |
| 232 | + |
| 233 | +npm view @mcp-use/cli version |
| 234 | +# Output: 2.0.2 |
| 235 | + |
| 236 | +# Or visit: |
| 237 | +# https://www.npmjs.com/package/mcp-use |
| 238 | +# https://www.npmjs.com/package/@mcp-use/cli |
| 239 | +# https://www.npmjs.com/package/@mcp-use/inspector |
| 240 | +# https://www.npmjs.com/package/create-mcp-use-app |
| 241 | +``` |
| 242 | + |
| 243 | +## 📊 Timeline Summary |
| 244 | + |
| 245 | +1. **Day 1**: Developer creates feature + changeset, pushes PR |
| 246 | +2. **Day 2-3**: Code review, changes, approval |
| 247 | +3. **Day 3**: PR merged to main |
| 248 | +4. **Day 3**: Maintainer runs `pnpm version` → Version PR created |
| 249 | +5. **Day 3**: Maintainer reviews and merges Version PR |
| 250 | +6. **Day 3**: Automated workflow publishes to npm |
| 251 | +7. **Done!** ✨ |
| 252 | + |
| 253 | +## 🤖 Automated Workflow (GitHub Actions) |
| 254 | + |
| 255 | +With the included GitHub Actions workflows: |
| 256 | + |
| 257 | +1. **Developer** creates PR with changeset |
| 258 | +2. **CI** validates build, tests, lint |
| 259 | +3. **Merge** to main triggers release workflow |
| 260 | +4. **Changesets Action** creates "Version Packages" PR automatically |
| 261 | +5. **Maintainer** reviews and merges Version PR |
| 262 | +6. **Action** automatically publishes to npm |
| 263 | +7. **Done!** No manual commands needed |
| 264 | + |
| 265 | +## 🎓 Learning Resources |
| 266 | + |
| 267 | +- **Quick Reference**: See `CHANGESET_WORKFLOW.md` |
| 268 | +- **Detailed Guide**: See `VERSIONING.md` |
| 269 | +- **Changesets Docs**: https://github.com/changesets/changesets |
| 270 | +- **Semantic Versioning**: https://semver.org/ |
| 271 | + |
| 272 | +## 💡 Tips |
| 273 | + |
| 274 | +- **Batch related changes** - Create one changeset for related changes across packages |
| 275 | +- **Clear summaries** - Write what users need to know, not implementation details |
| 276 | +- **Link to PRs** - Reference PR numbers in changeset summaries |
| 277 | +- **Test before release** - Always build and test before publishing |
| 278 | +- **Coordinate major bumps** - Plan breaking changes with the team |
| 279 | + |
| 280 | +--- |
| 281 | + |
| 282 | +**Ready to get started?** |
| 283 | + |
| 284 | +```bash |
| 285 | +# Make some changes, then: |
| 286 | +pnpm changeset |
| 287 | +``` |
| 288 | + |
0 commit comments