Skip to content

Commit b45934d

Browse files
Merge pull request #24 from CrackingShells/schema-updates
Schema updates
2 parents 1ba271d + 6255864 commit b45934d

5 files changed

Lines changed: 568 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ JSON schemas for the CrackingShells organization package ecosystem.
77
This repository contains JSON schemas for validating Hatch metadata:
88

99
- **Package Schema**: Validates individual package metadata. [Learn More](docs/package/overview.md)
10-
- Latest: `package/v1.2.0/hatch_pkg_metadata_schema.json`
11-
- Versioned: `package/v1.2.0/hatch_pkg_metadata_schema.json`
10+
- Latest: `package/v1.2.1/hatch_pkg_metadata_schema.json`
11+
- Versioned: `package/v1.2.1/hatch_pkg_metadata_schema.json`, `package/v1.2.0/hatch_pkg_metadata_schema.json`
1212
- Deprecated: `package/v1.0/hatch_pkg_metadata_schema.json`, `package/v1.1.0/hatch_pkg_metadata_schema.json`
1313

1414
- **Registry Schema**: Validates the central package registry. [Learn More](docs/registry/overview.md)

docs/package/examples.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,49 @@
22

33
This document provides examples of valid package metadata files compliant with the Hatch Package Schema.
44

5-
## Basic Example
5+
## v1.2.1 Dual Entry Point Example
6+
7+
```json
8+
{
9+
"$schema": "https://raw.githubusercontent.com/crackingshells/Hatch-Schemas/main/package/v1.2.1/hatch_pkg_metadata_schema.json",
10+
"package_schema_version": "1.2.1",
11+
"name": "arithmetic_package",
12+
"version": "1.3.0",
13+
"description": "A package for arithmetic operations with dual entry points",
14+
"tags": ["math", "arithmetic", "dual-entry"],
15+
"author": {
16+
"name": "John Doe",
17+
"email": "john.doe@example.com"
18+
},
19+
"license": {
20+
"name": "MIT"
21+
},
22+
"entry_point": {
23+
"mcp_server": "mcp_arithmetic.py",
24+
"hatch_mcp_server": "hatch_mcp_arithmetic.py"
25+
},
26+
"tools": [
27+
{"name": "add", "description": "Add two numbers together."},
28+
{"name": "subtract", "description": "Subtract one number from another."},
29+
{"name": "multiply", "description": "Multiply two numbers together."},
30+
{"name": "divide", "description": "Divide one number by another."}
31+
],
32+
"dependencies": {
33+
"hatch": [],
34+
"python": [{
35+
"name": "numpy", "version_constraint": ">=2.2.0", "package_manager": "pip"
36+
}],
37+
"system": [],
38+
"docker": []
39+
},
40+
"citations": {
41+
"origin": "John Doe, \"Origin: Example MCP Server for Hatch!\", 2025",
42+
"mcp": "John Doe, \"MCP: Example Arithmetic Tools for Hatch!\", 2025"
43+
}
44+
}
45+
```
46+
47+
## Basic Example (v1.2.0)
648

749
```json
850
{

docs/package/overview.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Package Schema (`hatch_pkg_metadata_schema.json`) defines the structure for
66

77
## Current Version
88

9-
The current version of the Package Schema is **v1.2.0**.
9+
The current version of the Package Schema is **v1.2.1**.
1010

1111
## Schema Structure
1212

@@ -18,7 +18,7 @@ The Package Schema includes the following major sections:
1818
- **Package Links**: Repository and documentation URLs
1919
- **Dependencies**: Hatch, Python, system, and Docker dependencies
2020
- **Compatibility Requirements**: Hatchling and Python version constraints
21-
- **Entry Points and Tools**: Primary entry point and additional tools
21+
- **Entry Points and Tools**: Dual entry point configuration (FastMCP server + HatchMCP wrapper) and additional tools
2222

2323
For detailed field-by-field documentation including types, formats, and examples, see the [Package Schema Field Reference](fields.md).
2424

@@ -43,10 +43,10 @@ For detailed field-by-field documentation including types, formats, and examples
4343

4444
```json
4545
{
46-
"package_schema_version": "1.2.0",
46+
"package_schema_version": "1.2.1",
4747
"name": "example_package",
4848
"version": "1.0.0",
49-
"description": "An example Hatch package",
49+
"description": "An example Hatch package with dual entry points",
5050
"tags": ["example", "demo"],
5151
"author": {
5252
"name": "John Doe",
@@ -56,7 +56,10 @@ For detailed field-by-field documentation including types, formats, and examples
5656
"name": "MIT",
5757
"uri": "https://opensource.org/licenses/MIT"
5858
},
59-
"entry_point": "server.py",
59+
"entry_point": {
60+
"mcp_server": "mcp_server.py",
61+
"hatch_mcp_server": "hatch_mcp_server.py"
62+
},
6063
"dependencies": {
6164
"hatch": [
6265
{
Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,291 @@
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

Comments
 (0)