Template Generator¶
hatch.template_generator
¶
Template Generator for Hatch packages.
This module contains functions to generate template files for Hatch MCP server packages. Each function generates a specific file for the package template.
Functions¶
create_package_template(target_dir, package_name, description='')
¶
Create a package template directory with all necessary files.
This function orchestrates the generation of a complete package structure by: 1. Creating the package directory 2. Generating and writing the init.py file 3. Generating and writing the mcp_server.py file with example tools 4. Generating and writing the hatch_mcp_server_entry.py file that wraps the MCP server 5. Creating the hatch_metadata.json with package information 6. Generating a README.md with basic documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_dir
|
Path
|
Directory where the package should be created. |
required |
package_name
|
str
|
Name of the package. |
required |
description
|
str
|
Package description. Defaults to empty string. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
Path to the created package directory. |
Source code in hatch/template_generator.py
generate_hatch_mcp_server_entry_py(package_name)
¶
Generate the hatch_mcp_server_entry.py file content for a template package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Content for hatch_mcp_server_entry.py file. |
Source code in hatch/template_generator.py
generate_init_py()
¶
Generate the init.py file content for a template package.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Content for init.py file. |
generate_mcp_server_py(package_name)
¶
Generate the mcp_server.py file content for a template package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Content for mcp_server.py file. |
Source code in hatch/template_generator.py
generate_metadata_json(package_name, description='')
¶
Generate the metadata JSON content for a template package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package. |
required |
description
|
str
|
Package description. Defaults to empty string. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Metadata dictionary. |
Source code in hatch/template_generator.py
generate_readme_md(package_name, description='')
¶
Generate the README.md file content for a template package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_name
|
str
|
Name of the package. |
required |
description
|
str
|
Package description. Defaults to empty string. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Content for README.md file. |