|
| 1 | +# Migration Guide: Schema v1.2.0 → v1.2.1 |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Schema version 1.2.1 introduces **dual entry point support** for Hatch packages, enabling packages to declare both a FastMCP server implementation and a HatchMCP wrapper file. This enhancement provides better separation of concerns and ensures tool availability when FastMCP servers are imported independently. |
| 6 | + |
| 7 | +## Key Changes in v1.2.1 |
| 8 | + |
| 9 | +### 1. Dual Entry Point Configuration |
| 10 | + |
| 11 | +**v1.2.0 (Single Entry Point)**: |
| 12 | +```json |
| 13 | +{ |
| 14 | + "package_schema_version": "1.2.0", |
| 15 | + "entry_point": "hatch_mcp_server.py" |
| 16 | +} |
| 17 | +``` |
| 18 | + |
| 19 | +**v1.2.1 (Dual Entry Point)**: |
| 20 | +```json |
| 21 | +{ |
| 22 | + "package_schema_version": "1.2.1", |
| 23 | + "entry_point": { |
| 24 | + "mcp_server": "mcp_server.py", |
| 25 | + "hatch_mcp_server": "hatch_mcp_server.py" |
| 26 | + } |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Tool Enforcement |
| 31 | + |
| 32 | +In v1.2.1, **ALL tools declared in metadata must exist in the FastMCP server file** with proper `@mcp.tool()` decorators. This ensures: |
| 33 | + |
| 34 | +- Tools are available when FastMCP server is imported independently |
| 35 | +- Consistency across the Cracking Shells ecosystem |
| 36 | +- Better external organization compatibility |
| 37 | + |
| 38 | +## Migration Steps |
| 39 | + |
| 40 | +### Step 1: Update Package Structure |
| 41 | + |
| 42 | +If you have a single-file package, split it into dual files: |
| 43 | + |
| 44 | +**Before (v1.2.0)**: |
| 45 | +``` |
| 46 | +my_package/ |
| 47 | +├── hatch_metadata.json |
| 48 | +├── server.py # Single file with everything |
| 49 | +└── README.md |
| 50 | +``` |
| 51 | + |
| 52 | +**After (v1.2.1)**: |
| 53 | +``` |
| 54 | +my_package/ |
| 55 | +├── hatch_metadata.json |
| 56 | +├── mcp_server.py # FastMCP server implementation |
| 57 | +├── hatch_mcp_server.py # HatchMCP wrapper |
| 58 | +└── README.md |
| 59 | +``` |
| 60 | + |
| 61 | +### Step 2: Create FastMCP Server File |
| 62 | + |
| 63 | +Create a dedicated FastMCP server file (`mcp_server.py`): |
| 64 | + |
| 65 | +```python |
| 66 | +import numpy as np |
| 67 | +from mcp.server.fastmcp import FastMCP |
| 68 | + |
| 69 | +mcp = FastMCP("MyPackage", log_level="WARNING") |
| 70 | + |
| 71 | +@mcp.tool() |
| 72 | +def my_tool(param: str) -> str: |
| 73 | + """Tool description.""" |
| 74 | + return f"Processed: {param}" |
| 75 | + |
| 76 | +# Add all your tools here with @mcp.tool() decorators |
| 77 | + |
| 78 | +if __name__ == "__main__": |
| 79 | + mcp.run() |
| 80 | +``` |
| 81 | + |
| 82 | +### Step 3: Create HatchMCP Wrapper File |
| 83 | + |
| 84 | +Create a HatchMCP wrapper file (`hatch_mcp_server.py`): |
| 85 | + |
| 86 | +```python |
| 87 | +from hatch_mcp_server import HatchMCP |
| 88 | +from mcp_server import mcp # Import from your FastMCP server |
| 89 | + |
| 90 | +hatch_mcp = HatchMCP("MyPackage", |
| 91 | + fast_mcp=mcp, |
| 92 | + origin_citation="Your citation here", |
| 93 | + mcp_citation="Your MCP citation here") |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + hatch_mcp.server.run() |
| 97 | +``` |
| 98 | + |
| 99 | +### Step 4: Update Metadata |
| 100 | + |
| 101 | +Update your `hatch_metadata.json`: |
| 102 | + |
| 103 | +```json |
| 104 | +{ |
| 105 | + "package_schema_version": "1.2.1", |
| 106 | + "name": "my_package", |
| 107 | + "version": "2.0.0", |
| 108 | + "description": "Updated package with dual entry points", |
| 109 | + "entry_point": { |
| 110 | + "mcp_server": "mcp_server.py", |
| 111 | + "hatch_mcp_server": "hatch_mcp_server.py" |
| 112 | + }, |
| 113 | + "tools": [ |
| 114 | + {"name": "my_tool", "description": "Tool description."} |
| 115 | + ] |
| 116 | + // ... other fields unchanged |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +## Complete Migration Example |
| 121 | + |
| 122 | +### Original v1.2.0 Package |
| 123 | + |
| 124 | +**hatch_metadata.json**: |
| 125 | +```json |
| 126 | +{ |
| 127 | + "package_schema_version": "1.2.0", |
| 128 | + "name": "arithmetic_pkg", |
| 129 | + "version": "1.2.0", |
| 130 | + "entry_point": "arithmetic.py", |
| 131 | + "tools": [ |
| 132 | + {"name": "add", "description": "Add two numbers."}, |
| 133 | + {"name": "multiply", "description": "Multiply two numbers."} |
| 134 | + ] |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +**arithmetic.py**: |
| 139 | +```python |
| 140 | +from hatch_mcp_server import HatchMCP |
| 141 | + |
| 142 | +hatch_mcp = HatchMCP("ArithmeticTools") |
| 143 | + |
| 144 | +@hatch_mcp.server.tool() |
| 145 | +def add(a: float, b: float) -> float: |
| 146 | + """Add two numbers together.""" |
| 147 | + return a + b |
| 148 | + |
| 149 | +@hatch_mcp.server.tool() |
| 150 | +def multiply(a: float, b: float) -> float: |
| 151 | + """Multiply two numbers together.""" |
| 152 | + return a * b |
| 153 | + |
| 154 | +if __name__ == "__main__": |
| 155 | + hatch_mcp.server.run() |
| 156 | +``` |
| 157 | + |
| 158 | +### Migrated v1.2.1 Package |
| 159 | + |
| 160 | +**hatch_metadata.json**: |
| 161 | +```json |
| 162 | +{ |
| 163 | + "package_schema_version": "1.2.1", |
| 164 | + "name": "arithmetic_pkg", |
| 165 | + "version": "2.0.0", |
| 166 | + "entry_point": { |
| 167 | + "mcp_server": "mcp_arithmetic.py", |
| 168 | + "hatch_mcp_server": "hatch_mcp_arithmetic.py" |
| 169 | + }, |
| 170 | + "tools": [ |
| 171 | + {"name": "add", "description": "Add two numbers."}, |
| 172 | + {"name": "multiply", "description": "Multiply two numbers."} |
| 173 | + ] |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +**mcp_arithmetic.py** (FastMCP Server): |
| 178 | +```python |
| 179 | +from mcp.server.fastmcp import FastMCP |
| 180 | + |
| 181 | +mcp = FastMCP("ArithmeticTools", log_level="WARNING") |
| 182 | + |
| 183 | +@mcp.tool() |
| 184 | +def add(a: float, b: float) -> float: |
| 185 | + """Add two numbers together.""" |
| 186 | + return a + b |
| 187 | + |
| 188 | +@mcp.tool() |
| 189 | +def multiply(a: float, b: float) -> float: |
| 190 | + """Multiply two numbers together.""" |
| 191 | + return a * b |
| 192 | + |
| 193 | +if __name__ == "__main__": |
| 194 | + mcp.run() |
| 195 | +``` |
| 196 | + |
| 197 | +**hatch_mcp_arithmetic.py** (HatchMCP Wrapper): |
| 198 | +```python |
| 199 | +from hatch_mcp_server import HatchMCP |
| 200 | +from mcp_arithmetic import mcp |
| 201 | + |
| 202 | +hatch_mcp = HatchMCP("ArithmeticTools", |
| 203 | + fast_mcp=mcp, |
| 204 | + origin_citation="Your origin citation", |
| 205 | + mcp_citation="Your MCP citation") |
| 206 | + |
| 207 | +if __name__ == "__main__": |
| 208 | + hatch_mcp.server.run() |
| 209 | +``` |
| 210 | + |
| 211 | +## Validation Requirements |
| 212 | + |
| 213 | +### Tool Enforcement |
| 214 | + |
| 215 | +All tools declared in metadata **MUST** exist in the FastMCP server file: |
| 216 | + |
| 217 | +✅ **Correct**: |
| 218 | +```python |
| 219 | +# In mcp_server.py |
| 220 | +@mcp.tool() |
| 221 | +def my_tool(): |
| 222 | + """Tool implementation.""" |
| 223 | + pass |
| 224 | + |
| 225 | +# In hatch_metadata.json |
| 226 | +"tools": [{"name": "my_tool", "description": "Tool description."}] |
| 227 | +``` |
| 228 | + |
| 229 | +❌ **Incorrect**: |
| 230 | +```python |
| 231 | +# Tool only in HatchMCP wrapper - will fail validation |
| 232 | +@hatch_mcp.server.tool() |
| 233 | +def my_tool(): |
| 234 | + pass |
| 235 | +``` |
| 236 | + |
| 237 | +### Import Relationship |
| 238 | + |
| 239 | +The HatchMCP wrapper **MUST** import the `mcp` object from the FastMCP server: |
| 240 | + |
| 241 | +✅ **Correct**: |
| 242 | +```python |
| 243 | +from mcp_server import mcp # Correct import |
| 244 | +``` |
| 245 | + |
| 246 | +❌ **Incorrect**: |
| 247 | +```python |
| 248 | +from other_module import mcp # Wrong module |
| 249 | +``` |
| 250 | + |
| 251 | +## Backward Compatibility |
| 252 | + |
| 253 | +- **Existing v1.2.0 and v1.1.0 packages continue to work unchanged** |
| 254 | +- No breaking changes to existing packages |
| 255 | +- Validator chain automatically routes packages to appropriate validators |
| 256 | +- Migration to v1.2.1 is optional but recommended for new packages |
| 257 | + |
| 258 | +## Benefits of Migration |
| 259 | + |
| 260 | +1. **Better Separation of Concerns**: FastMCP server contains pure business logic |
| 261 | +2. **External Compatibility**: Other organizations can import FastMCP servers directly |
| 262 | +3. **Tool Availability**: Tools guaranteed to be available when FastMCP server imported |
| 263 | +4. **Enhanced Validation**: More comprehensive package validation |
| 264 | +5. **Future-Proof**: Better foundation for future enhancements |
| 265 | + |
| 266 | +## Troubleshooting |
| 267 | + |
| 268 | +### Common Migration Issues |
| 269 | + |
| 270 | +**Issue**: Tool validation fails |
| 271 | +**Solution**: Ensure all declared tools exist in FastMCP server with `@mcp.tool()` decorators |
| 272 | + |
| 273 | +**Issue**: Import validation fails |
| 274 | +**Solution**: Verify HatchMCP wrapper imports `mcp` from correct FastMCP server file |
| 275 | + |
| 276 | +**Issue**: Schema validation fails |
| 277 | +**Solution**: Ensure `package_schema_version` is exactly `"1.2.1"` and entry point is object format |
| 278 | + |
| 279 | +### Getting Help |
| 280 | + |
| 281 | +- Check validation error messages for specific guidance |
| 282 | +- Refer to the arithmetic_pkg_1_3_0 reference implementation |
| 283 | +- Review the complete examples in this guide |
| 284 | + |
| 285 | +## Next Steps |
| 286 | + |
| 287 | +After migration: |
| 288 | +1. Test your package thoroughly |
| 289 | +2. Update your documentation |
| 290 | +3. Consider incrementing your package version to indicate the structural changes |
| 291 | +4. Update any CI/CD pipelines to handle the new dual-file structure |
0 commit comments