|
| 1 | +# MCP Template Scripts |
| 2 | + |
| 3 | +This directory contains utility scripts for managing MCP server repositories derived from the mcp-template. |
| 4 | + |
| 5 | +## merge-template-updates.sh |
| 6 | + |
| 7 | +A sophisticated script for merging updates from the mcp-template repository into derived MCP server repositories while preserving project-specific customizations. |
| 8 | + |
| 9 | +### Features |
| 10 | + |
| 11 | +- **Selective merging**: Automatically excludes project-specific files from being overwritten |
| 12 | +- **Dry run mode**: Preview changes before applying them |
| 13 | +- **Local template support**: Can merge from a local copy of the template for testing |
| 14 | +- **Project-aware**: Knows about specific MCP projects and their unique files |
| 15 | +- **Safe operation**: Validates repository state before merging |
| 16 | +- **Detailed feedback**: Shows exactly what files changed and how |
| 17 | + |
| 18 | +### Installation |
| 19 | + |
| 20 | +Copy this script to your derived MCP repository: |
| 21 | + |
| 22 | +```bash |
| 23 | +# From your derived repository (e.g., mcp-wayback-machine) |
| 24 | +mkdir -p scripts |
| 25 | +curl -o scripts/merge-template-updates.sh \ |
| 26 | + https://raw.githubusercontent.com/Mearman/mcp-template/main/scripts/merge-template-updates.sh |
| 27 | +chmod +x scripts/merge-template-updates.sh |
| 28 | +``` |
| 29 | + |
| 30 | +### Usage |
| 31 | + |
| 32 | +Basic usage from the root of your derived MCP repository: |
| 33 | + |
| 34 | +```bash |
| 35 | +./scripts/merge-template-updates.sh |
| 36 | +``` |
| 37 | + |
| 38 | +With options: |
| 39 | + |
| 40 | +```bash |
| 41 | +# Preview what would happen without making changes |
| 42 | +./scripts/merge-template-updates.sh --dry-run |
| 43 | + |
| 44 | +# Merge from a specific branch |
| 45 | +./scripts/merge-template-updates.sh --branch feature/new-updates |
| 46 | + |
| 47 | +# Merge from a local template repository |
| 48 | +./scripts/merge-template-updates.sh --template-path ../mcp-template |
| 49 | + |
| 50 | +# Show help |
| 51 | +./scripts/merge-template-updates.sh --help |
| 52 | +``` |
| 53 | + |
| 54 | +### What Files Are Preserved |
| 55 | + |
| 56 | +The script automatically preserves these repository-specific files: |
| 57 | + |
| 58 | +**Always preserved:** |
| 59 | +- `package.json` - Your project name, version, description |
| 60 | +- `README.md` - Your project documentation |
| 61 | +- `CHANGELOG.md` - Your project's changelog |
| 62 | +- `LICENSE` - Your project's license |
| 63 | +- `.github/workflows/release.yml` - Release configuration |
| 64 | +- `.github/workflows/semantic-release.yml` - Semantic release config |
| 65 | +- `src/tools/*` - All your custom tools |
| 66 | +- `src/index.ts` - Your main server implementation |
| 67 | +- `src/cli.ts` - Your CLI implementation |
| 68 | +- `scripts/merge-template-updates.sh` - This script itself |
| 69 | +- `scripts/README.md` - Scripts documentation |
| 70 | + |
| 71 | +**Project-specific preservations:** |
| 72 | +- **mcp-wayback-machine**: `RELEASING.md`, integration tests, package tests |
| 73 | +- **mcp-openalex**: Type definitions, OpenAlex client utilities |
| 74 | + |
| 75 | +### Example Workflow |
| 76 | + |
| 77 | +#### 1. Standard Update Flow |
| 78 | + |
| 79 | +```bash |
| 80 | +# Ensure clean working directory |
| 81 | +git status |
| 82 | +# Should show: nothing to commit, working tree clean |
| 83 | + |
| 84 | +# Run the merge |
| 85 | +./scripts/merge-template-updates.sh |
| 86 | + |
| 87 | +# Review what changed |
| 88 | +git diff HEAD~1 |
| 89 | + |
| 90 | +# Run tests |
| 91 | +yarn test |
| 92 | + |
| 93 | +# If all looks good, push and create PR |
| 94 | +git push origin merge-template-YYYYMMDD-HHMMSS |
| 95 | +``` |
| 96 | + |
| 97 | +#### 2. Testing with Dry Run |
| 98 | + |
| 99 | +```bash |
| 100 | +# See what would happen without making changes |
| 101 | +./scripts/merge-template-updates.sh --dry-run |
| 102 | + |
| 103 | +# If satisfied, run for real |
| 104 | +./scripts/merge-template-updates.sh |
| 105 | +``` |
| 106 | + |
| 107 | +#### 3. Testing with Local Template |
| 108 | + |
| 109 | +```bash |
| 110 | +# Clone template locally and make experimental changes |
| 111 | +git clone https://github.com/Mearman/mcp-template.git ../mcp-template-test |
| 112 | +cd ../mcp-template-test |
| 113 | +# Make your changes... |
| 114 | + |
| 115 | +# Test merge from local template |
| 116 | +cd ../mcp-wayback-machine |
| 117 | +./scripts/merge-template-updates.sh --template-path ../mcp-template-test --dry-run |
| 118 | +``` |
| 119 | + |
| 120 | +### Handling Merge Conflicts |
| 121 | + |
| 122 | +If conflicts occur, the script will: |
| 123 | + |
| 124 | +1. List all conflicting files |
| 125 | +2. Provide resolution tips based on file type |
| 126 | +3. Exit with clear instructions |
| 127 | + |
| 128 | +To resolve conflicts: |
| 129 | + |
| 130 | +```bash |
| 131 | +# 1. Review conflicts |
| 132 | +git status |
| 133 | + |
| 134 | +# 2. Edit conflicting files |
| 135 | +# Look for conflict markers: <<<<<<< HEAD |
| 136 | + |
| 137 | +# 3. Common resolution strategies: |
| 138 | +# - Configuration files: Usually keep your version |
| 139 | +# - Shared utilities: Carefully merge both versions |
| 140 | +# - Test files: Ensure they match your project structure |
| 141 | + |
| 142 | +# 4. Stage resolved files |
| 143 | +git add <resolved-files> |
| 144 | + |
| 145 | +# 5. Complete the merge |
| 146 | +git commit |
| 147 | + |
| 148 | +# 6. Continue with PR workflow |
| 149 | +git push origin merge-template-YYYYMMDD-HHMMSS |
| 150 | +``` |
| 151 | + |
| 152 | +### Aborting a Merge |
| 153 | + |
| 154 | +If you need to abort and start over: |
| 155 | + |
| 156 | +```bash |
| 157 | +# Return to original branch |
| 158 | +git checkout main # or your original branch |
| 159 | + |
| 160 | +# Delete the merge branch |
| 161 | +git branch -D merge-template-YYYYMMDD-HHMMSS |
| 162 | + |
| 163 | +# Remove the template remote (optional) |
| 164 | +git remote remove mcp-template |
| 165 | +``` |
| 166 | + |
| 167 | +### Understanding the Merge Process |
| 168 | + |
| 169 | +1. **Validation Phase** |
| 170 | + - Checks you're in a valid MCP repository |
| 171 | + - Ensures no uncommitted changes |
| 172 | + - Validates project structure |
| 173 | + |
| 174 | +2. **Setup Phase** |
| 175 | + - Adds mcp-template as a git remote |
| 176 | + - Fetches latest changes |
| 177 | + - Creates a new branch for the merge |
| 178 | + |
| 179 | +3. **Configuration Phase** |
| 180 | + - Sets up git attributes to exclude specific files |
| 181 | + - Configures merge strategy to preserve your files |
| 182 | + - Identifies project-specific exclusions |
| 183 | + |
| 184 | +4. **Merge Phase** |
| 185 | + - Performs the actual merge |
| 186 | + - Handles unrelated histories (first-time merges) |
| 187 | + - Reports conflicts if any |
| 188 | + |
| 189 | +5. **Cleanup Phase** |
| 190 | + - Shows what changed |
| 191 | + - Provides next steps |
| 192 | + - Cleans up temporary git configuration |
| 193 | + |
| 194 | +### Best Practices |
| 195 | + |
| 196 | +1. **Always review changes**: Use `git diff HEAD~1` to see exactly what changed |
| 197 | +2. **Run tests**: Ensure `yarn test` passes before creating a PR |
| 198 | +3. **Test locally**: Run `yarn dev` to verify everything works |
| 199 | +4. **Use dry run first**: Especially when merging after a long time |
| 200 | +5. **Create PRs**: Don't merge directly to main, use pull requests for review |
| 201 | + |
| 202 | +### Customizing for New Projects |
| 203 | + |
| 204 | +If you're creating a new MCP server not yet known to the script: |
| 205 | + |
| 206 | +1. The script will still work, using the default exclusion list |
| 207 | +2. To add project-specific exclusions, edit the script and add a case in the switch statement: |
| 208 | + |
| 209 | +```bash |
| 210 | +case "$REPO_NAME" in |
| 211 | + "mcp-your-project") |
| 212 | + EXCLUDE_FILES+=("your-special-file.ts" "another-file.md") |
| 213 | + ;; |
| 214 | +``` |
| 215 | +
|
| 216 | +3. Consider submitting a PR to update the template script with your project |
| 217 | +
|
| 218 | +### Troubleshooting |
| 219 | +
|
| 220 | +**"Not in a git repository"** |
| 221 | +- Ensure you're in the root directory of your MCP project |
| 222 | +- Check that `.git` directory exists |
| 223 | +
|
| 224 | +**"You have uncommitted changes"** |
| 225 | +- Commit or stash your changes: `git stash` |
| 226 | +- After merging, restore with: `git stash pop` |
| 227 | +
|
| 228 | +**"This doesn't appear to be a valid MCP repository"** |
| 229 | +- Ensure you have `package.json` and `src/` directory |
| 230 | +- You might be in the wrong directory |
| 231 | +
|
| 232 | +**Merge conflicts in files that should be excluded** |
| 233 | +- The exclusion might not be working for wildcard patterns |
| 234 | +- Manually resolve and report the issue |
| 235 | +
|
| 236 | +**"fatal: refusing to merge unrelated histories"** |
| 237 | +- This is handled automatically by the script |
| 238 | +- If it still occurs, you might need to update git |
| 239 | +
|
| 240 | +### Contributing |
| 241 | +
|
| 242 | +To improve this script: |
| 243 | +
|
| 244 | +1. Test your changes with `--dry-run` first |
| 245 | +2. Ensure it works with all known MCP projects |
| 246 | +3. Update this README with any new features |
| 247 | +4. Submit a PR to the mcp-template repository |
| 248 | +
|
| 249 | +## analyze-template-diff.sh |
| 250 | +
|
| 251 | +A utility script for analyzing differences between your MCP server and the template. Useful for understanding what has diverged before merging updates. |
| 252 | +
|
| 253 | +### Features |
| 254 | +
|
| 255 | +- **Multiple output formats**: Summary, detailed diff, or file listing |
| 256 | +- **Comprehensive analysis**: Checks files, directories, and dependencies |
| 257 | +- **Local template support**: Can analyze against a local template copy |
| 258 | +- **Package.json insights**: Shows dependency count differences |
| 259 | +
|
| 260 | +### Usage |
| 261 | +
|
| 262 | +Basic usage from the root of your derived MCP repository: |
| 263 | +
|
| 264 | +```bash |
| 265 | +# Show summary of differences |
| 266 | +./scripts/analyze-template-diff.sh |
| 267 | +
|
| 268 | +# Show detailed diffs for modified files |
| 269 | +./scripts/analyze-template-diff.sh --output detailed |
| 270 | +
|
| 271 | +# List files that exist in only one repository |
| 272 | +./scripts/analyze-template-diff.sh --output files |
| 273 | +
|
| 274 | +# Analyze against a local template |
| 275 | +./scripts/analyze-template-diff.sh --template-path ../mcp-template |
| 276 | +``` |
| 277 | +
|
| 278 | +### Output Formats |
| 279 | +
|
| 280 | +#### Summary (default) |
| 281 | +
|
| 282 | +Shows a high-level overview: |
| 283 | +- ✓ Identical files |
| 284 | +- ↻ Modified files |
| 285 | +- + Files only in your repository |
| 286 | +- - Files missing from your repository |
| 287 | +- Directory file counts |
| 288 | +- Dependency analysis |
| 289 | +
|
| 290 | +#### Detailed |
| 291 | +
|
| 292 | +Shows full unified diffs for all modified files. Useful for understanding exactly what changed. |
| 293 | +
|
| 294 | +#### Files |
| 295 | +
|
| 296 | +Lists all files that exist in only one repository. Helpful for identifying: |
| 297 | +- Custom files you've added |
| 298 | +- Template files you haven't adopted |
| 299 | +
|
| 300 | +### Example Output |
| 301 | +
|
| 302 | +``` |
| 303 | +Analysis Results: |
| 304 | +================== |
| 305 | +
|
| 306 | +File Differences: |
| 307 | + ✓ tsconfig.json (identical) |
| 308 | + ↻ package.json (modified) |
| 309 | + + RELEASING.md (only in mcp-wayback-machine) |
| 310 | + - src/tools/fetch-example.ts (missing from mcp-wayback-machine) |
| 311 | +
|
| 312 | +Directory Differences: |
| 313 | + ↻ src/tools (4 files vs 2 in template) |
| 314 | + ✓ src/utils (3 files) |
| 315 | +
|
| 316 | +Package.json Analysis: |
| 317 | + Dependencies: 5 (vs 3 in template) |
| 318 | + Dev Dependencies: 15 (vs 15 in template) |
| 319 | + Version: 1.0.0 (template: 1.1.1) |
| 320 | +``` |
| 321 | +
|
| 322 | +### When to Use |
| 323 | +
|
| 324 | +Run this script: |
| 325 | +- **Before merging**: Understand what will change |
| 326 | +- **After development**: See how far you've diverged |
| 327 | +- **During planning**: Identify reusable patterns to contribute back |
| 328 | +- **For documentation**: Track customizations in your project |
| 329 | +
|
| 330 | +## mcp-status.sh |
| 331 | +
|
| 332 | +A utility script for getting a quick overview of all MCP servers in a directory. Useful for managing multiple MCP server projects. |
| 333 | +
|
| 334 | +### Features |
| 335 | +
|
| 336 | +- **Auto-discovery**: Finds all MCP servers by checking for @modelcontextprotocol dependency |
| 337 | +- **Git status**: Shows branch, uncommitted changes, and unpushed commits |
| 338 | +- **Script availability**: Indicates which servers have merge scripts installed |
| 339 | +- **Project metrics**: Shows tool count and last modification time |
| 340 | +
|
| 341 | +### Usage |
| 342 | +
|
| 343 | +From the mcp-template directory: |
| 344 | +
|
| 345 | +```bash |
| 346 | +# Check all MCP servers in parent directory (default) |
| 347 | +./scripts/mcp-status.sh |
| 348 | +
|
| 349 | +# Check MCP servers in a specific directory |
| 350 | +./scripts/mcp-status.sh /path/to/mcp-servers |
| 351 | +``` |
| 352 | +
|
| 353 | +### Example Output |
| 354 | +
|
| 355 | +``` |
| 356 | +MCP Server Status Report |
| 357 | +======================== |
| 358 | +
|
| 359 | +Searching in: .. |
| 360 | +
|
| 361 | +━━━ mcp-wayback-machine ━━━ |
| 362 | + |
| 363 | + Description: MCP server for Internet Archive Wayback Machine |
| 364 | + Scripts: ✓ (2 scripts found) |
| 365 | + Git Branch: main |
| 366 | + Git Status: ✓ Clean |
| 367 | + Last Modified: 2024-01-15 14:32 |
| 368 | + Tools: 4 |
| 369 | +
|
| 370 | +━━━ mcp-openalex ━━━ |
| 371 | + |
| 372 | + Description: MCP server for OpenAlex scholarly data |
| 373 | + Scripts: ✗ (no scripts directory) |
| 374 | + Git Branch: feature/new-tool |
| 375 | + Git Status: ⚠ 3 uncommitted changes |
| 376 | + Unpushed: ⚠ 2 commits ahead |
| 377 | + Last Modified: 2024-01-15 16:45 |
| 378 | + Tools: 6 |
| 379 | +``` |
| 380 | +
|
| 381 | +### When to Use |
| 382 | +
|
| 383 | +- **Project overview**: Get a quick status of all your MCP servers |
| 384 | +- **Maintenance planning**: Identify which servers need script updates |
| 385 | +- **Git hygiene**: Find servers with uncommitted or unpushed changes |
| 386 | +- **Development tracking**: See which servers were recently modified |
0 commit comments