serena.tools.tools_base#
Source code: serena/tools/tools_base.py
- class ToolMarkerCanEdit[source]#
Bases:
ToolMarkerMarker class for all tools that can perform editing operations on files.
- class ToolMarkerDoesNotRequireActiveProject[source]#
Bases:
ToolMarker
- class ToolMarkerOptional[source]#
Bases:
ToolMarkerMarker class for optional tools that are disabled by default.
- class ToolMarkerSymbolicRead[source]#
Bases:
ToolMarkerMarker class for tools that perform symbol read operations.
- class ToolMarkerSymbolicEdit[source]#
Bases:
ToolMarkerCanEditMarker class for tools that perform symbolic edit operations.
- class ToolMarkerBeta[source]#
Bases:
ToolMarkerMarker for tools that are considered beta features (may not be fully robust)
- class ApplyMethodProtocol(*args, **kwargs)[source]#
Bases:
ProtocolCallable protocol for the apply method of a tool.
- exception ToolCallError(error_message)[source]#
Bases:
ExceptionRepresents an error raised during a tool call execution
- Parameters:
error_message (str)
- class Tool(agent)[source]#
Bases:
Component- Parameters:
agent (SerenaAgent)
- SESSION_ID_PARAM_NAME = 'session_id'#
parameter name to use in apply method for the client session ID. This parameter will be ignored by the MCP interface but will be populated with the session ID of the current client session when the tool is called, allowing tools to be session-aware if needed.
- classmethod can_edit()[source]#
Returns whether this tool can perform editing operations on code.
- Returns:
True if the tool can edit code, False otherwise
- Return type:
bool
- classmethod get_apply_docstring_from_cls()[source]#
Get the docstring for the apply method from the class (static metadata). Needed for creating MCP tools in a separate process without running into serialization issues.
- Return type:
str
- get_apply_docstring()[source]#
Gets the docstring for the tool application, used by the MCP server.
- Return type:
str
- get_apply_fn_metadata(structured_output=None)[source]#
Gets the metadata for the tool application function, used by the MCP server.
- Parameters:
structured_output (bool | None)
- Return type:
FuncMetadata
- classmethod get_apply_fn_metadata_from_cls(structured_output=None)[source]#
Get the metadata for the apply method from the class (static metadata). Needed for creating MCP tools in a separate process without running into serialization issues.
- Parameters:
structured_output (bool | None)
- Return type:
FuncMetadata
- classmethod get_param_aliases()[source]#
- Returns:
a mapping of parameter aliases for the apply method, where the key is the alias and the value is the actual parameter name. This can be used to define alternative parameter names for the same parameter.
- Return type:
dict[str, str]
- apply_ex(log_call=True, catch_exceptions=True, mcp_ctx=None, **kwargs)[source]#
Applies the tool with logging and exception handling, using the given keyword arguments. This method either returns a string result or raises a ToolCallError in case of an error during tool application (but if
catch_exceptionsis enabled, it will return the error message as a string instead of raising the exception).- Parameters:
log_call (bool) – whether to log the tool call and its result
catch_exceptions (bool) – whether to catch exceptions and return their messages as strings, instead of raising a ToolCallError
mcp_ctx (Context | None)
- Return type:
str
- class EditingToolWithDiagnostics(agent)[source]#
Bases:
Tool,ToolMarkerCanEditBase class for editing tools that want to capture and report changes in LSP diagnostics before and after the edit.
- Parameters:
agent (SerenaAgent)
- ENABLE_DIAGNOSTICS: bool = False#
Global flag to enable/disable diagnostics for LSP-based editing tools derived from this class. The feature is currently disabled, because per-edit diagnostics are a questionable feature, since individual edits often intentionally introduce diagnostics (e.g. function signature mismatches or even syntax errors) that are then resolved in subsequent edits.
- class EditedFileContext(relative_path, code_editor)[source]#
Bases:
objectContext manager for file editing.
Create the context, then use set_updated_content to set the new content, the original content being provided in original_content. When exiting the context without an exception, the updated content will be written back to the file.
- Parameters:
relative_path (str)
code_editor (CodeEditor)