server
Abstract MCP server for WEAVE study construction.
This module provides a base server for registering MCP tools that build Jinja-templated WEAVE study YAML files. It supports common path utilities and template-backed study construction, while leaving project-specific tool registration to subclasses.
The server is designed to work with WEAVE orchestration command execution servers such as Maestro, Merlin, and StudyWeaver.
WEAVEStudyConstructionServer
Bases: BaseMCPServer, ABC
Abstract base class for constructing studies that WEAVE Orchestration tools can execute. WEAVE Orchestration tools include Maestro, Merlin, and StudyWeaver.
This class is not intended to be instantiated directly. Subclasses define project-specific tools for constructing studies from Jinja-templated workflow templates, while inheriting common utilities for path handling.
This server should be used alongside WEAVE-Orchestration-tool-specific command
execution servers. For instance, the MaestroCommandExecutionServer.
Attributes:
| Name | Type | Description |
|---|---|---|
study_constructor |
A |
Methods:
| Name | Description |
|---|---|
register_jinja_study_tool |
Register a tool backed by a single Jinja study template, or register multiple tools from a templates directory. |
register_study_construction_tools |
Abstract hook for subclasses to register their own study construction tools. |
_register_path_tools |
Register tools for working with filesystem paths. |
_register_tools |
Register all built-in and subclass-provided tools. |
Source code in src/mada_tools/workflow/weave/study_construction/server.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
__init__(server_name, description, study_templates_dir)
Constructor for WEAVEStudyConstructionServer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_name
|
str
|
The name of the MCP server |
required |
description
|
str
|
Description of the server |
required |
study_templates_dir
|
str | Path
|
The path to the directory where templated study YAML files live. |
required |
Source code in src/mada_tools/workflow/weave/study_construction/server.py
register_jinja_study_tool(*, tool_name=None, template_name=None, templates_dir=None, preprocess=None)
Register a template-backed tool with a minimal call signature.
The tool signature is intentionally small so we don't have to re-declare
template keys/defaults in Python. Agents discover valid keys via the
template mcp_doc section (plus the auto-generated key list).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str | None
|
MCP tool name to register (required when |
None
|
template_name
|
str | Path | None
|
Template filename or absolute path (required when |
None
|
templates_dir
|
str | Path | None
|
If provided, register one tool per |
None
|
preprocess
|
Callable[[Dict[str, Any]], Dict[str, Any]] | None
|
Optional hook to validate/normalize override values before rendering. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
ValueError
|
If arguments are inconsistent (e.g., both |
FileNotFoundError
|
If |
Source code in src/mada_tools/workflow/weave/study_construction/server.py
register_study_construction_tools()
abstractmethod
Hook for subclasses to register their own template-backed study tools.
Each tool defined here should utilize the self.register_jinja_study_tool().
Preprocessing can be added to each tool by creating a separate method in your
class and linking your tool to it.
Example:
Here's a full example that defines a study construction tool with preprocessing.
In this example, we're targeting the creation of a study called `my_cool_study`
that needs a path `py3_utils` in order to run. As part of the preprocessing, we
coerce the path of `py3_utils` to ensure it's provided and exists.
```python
from mada_tools.workflow.weave import WEAVEStudyConstructionServer
class MyProjectStudyConstructionServer(WEAVEStudyConstructionServer):
def _prep_my_cool_study(self, overrides: Dict[str, Any]) -> Dict[str, Any]:
# Preprocess this study by validating a path that's needed
raw_py3 = overrides.get("py3_utils")
if raw_py3 is None:
py3_utils_path = Path(__file__).parent / "py3utils"
else:
py3_utils_path = raw_py3 if isinstance(raw_py3, Path) else Path(str(raw_py3))
if not py3_utils_path.exists():
raise FileNotFoundError(f"The py3utils directory '{py3_utils_path}' does not exist.")
overrides["py3_utils"] = str(py3_utils_path)
return overrides
def register_study_construction_tools(self):
# Register the tool that constructs your cool study
self.register_jinja_study_tool(
tool_name="construct_my_cool_study",
template_name="my_cool_study.yaml",
preprocess=self._prep_my_cool_study,
)
```