serena.agent#


The Serena Model Context Protocol (MCP) Server

exception ProjectNotFoundError[source]#

Bases: Exception

class AvailableTools(tools)[source]#

Bases: object

Represents the set of available/exposed tools of a SerenaAgent.

Parameters:

tools (list[Tool]) – the list of available tools

tool_names#

the list of available tool names, sorted alphabetically

class ToolSet(tool_names)[source]#

Bases: object

Represents a set of tools by their names.

Parameters:

tool_names (set[str])

LEGACY_TOOL_NAME_MAPPING = {'replace_regex': 'replace_content'}#

maps legacy tool names to their new names for backward compatibility

classmethod default()[source]#
Returns:

the default tool set, which contains all tools that are enabled by default

Return type:

ToolSet

apply(*tool_inclusion_definitions)[source]#

Applies one or more tool inclusion definitions to this tool set, resulting in a new tool set.

Parameters:

tool_inclusion_definitions (ToolInclusionDefinition) – the definitions to apply

Returns:

a new tool set with the definitions applied

Return type:

ToolSet

without_editing_tools()[source]#
Returns:

a new tool set that excludes all tools that can edit

Return type:

ToolSet

get_tool_names()[source]#

Returns the names of the tools that are currently included in the tool set.

Return type:

set[str]

class ProjectPromptProvisionStatus(newly_activated_mode_names=None)[source]#

Bases: object

Manages the status of the provision of project-specific prompts

Parameters:

newly_activated_mode_names (set[str] | None) – list of mode names that have been newly activated (by dynamic project activation) and for which prompts must still be provided (either in the system prompt or via the activation message)

class SessionStatus(
mode_prompts_provided: bool = False,
project_activation_message_provided: bool = False,
)[source]#

Bases: object

Parameters:
  • mode_prompts_provided (bool)

  • project_activation_message_provided (bool)

is_mode_prompt_already_provided(mode_name, session_id)[source]#
Parameters:
  • mode_name (str) – the mode name

  • session_id (str) – the client session ID

Returns:

whether the mode name was already provided (in a project-specific activation message) and therefore should not be included again (in the Serena instructions manual)

Return type:

bool

get_modes_with_prompts_to_be_provided_for_project_activation(
session_id,
)[source]#

Gets the modes that have been newly activated and for which prompts still need to be provided (in dynamic project activation message).

Param:

session_id: the client session ID

Returns:

the modes

Parameters:

session_id (str)

Return type:

list[SerenaAgentMode]

mark_mode_prompts_as_provided(session_id)[source]#

Marks the prompts for all newly activated modes as provided, so that they will not be included in the project activation message.

Parameters:

session_id (str) – the client session ID

Return type:

None

mark_project_activation_message_as_provided(session_id)[source]#

Marks the project activation message as provided, so that it will not be included again in case of multiple activations of the same project.

Parameters:

session_id (str) – the client session ID

Return type:

None

is_project_activation_message_already_provided(session_id)[source]#
Parameters:

session_id (str) – the client session ID

Returns:

whether the project activation message was already provided and therefore should not be included again

Return type:

bool