tool
ANY_TYPE = Or(str, int, float, bool, list, dict)
module-attribute
MCPTool
Bases: BaseTool
MCP activities through a tool.
Attributes:
| Name | Type | Description |
|---|---|---|
connection |
Connection
|
The MCP server connection info. |
Source code in griptape/tools/mcp/tool.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
connection = field(kw_only=True)
class-attribute
instance-attribute
__attrs_post_init__()
Source code in griptape/tools/mcp/tool.py
_convert_call_tool_result_to_artifact(call_tool_result)
Source code in griptape/tools/mcp/tool.py
_create_activity_handler(tool)
Creates an activity handler method for the MCP tool.
Source code in griptape/tools/mcp/tool.py
_get_session()
_init_activities()
async
Source code in griptape/tools/mcp/tool.py
_run_activity(activity_name, params)
async
Runs an activity on the MCP Server with the provided parameters.
Source code in griptape/tools/mcp/tool.py
to_activity_json_schema(activity, schema_id)
Override to post-process JSON schema and add items to bare arrays.
The schema library loses type information when converting Python types to JSON schema, particularly for generic types like list[str] inside Or(). This results in bare arrays without items, which OpenAI's API rejects with "array schema missing items" errors.
This override adds post-processing to fix bare arrays after the schema library conversion, ensuring compatibility with OpenAI and other LLM providers that require valid JSON schemas.
Source code in griptape/tools/mcp/tool.py
_exc_iter(exc)
Iterate over all non-exceptiongroup parts of an exception(group) because spread syntax not available in python 3.9.
https://stackoverflow.com/a/78453879
Source code in griptape/tools/mcp/tool.py
add_items_to_bare_arrays(schema)
Recursively add default items to bare array types in JSON schema.
This function works around a limitation in the schema library: when converting Python types like Or(str, list[str], dict) to JSON schema, the library loses the items type information and outputs bare {"type": "array"} without items.
OpenAI requires all array types to have an items property, so this post-processing step ensures any bare arrays get a permissive {"items": {}} schema (accepts anything).
This approach handles: - MCP servers that provide bare arrays in anyOf (e.g., Maya MCP) - Schema library conversion issues with generic types inside Or() - Any other source of bare arrays in the schema
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
JSON schema dictionary |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Modified schema with items added to bare arrays |
Source code in griptape/tools/mcp/tool.py
json_to_python_type(json_type)
process_anyof_types(any_of_items)
Process anyOf array from JSON schema and convert to Python Or type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
any_of_items
|
list
|
List of type definitions from anyOf |
required |
Returns:
| Type | Description |
|---|---|
Or
|
Or schema with all the types |