obsidian_execute_commands
Execute multiple commands in Obsidian sequentially to automate workflows. Ensure notes are open for note-specific actions, enabling efficient task management through the Advanced Obsidian MCP Server.
Instructions
Execute one or more commands in obsidian interface, in order. For commands used on specific notes, make sure to open a note first.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commands | Yes | List of commands to execute |
Implementation Reference
- The run_tool method of ExecuteCommandsToolHandler class implements the core execution logic for the 'obsidian_execute_commands' tool. It processes a list of commands from the arguments and calls api.execute_command for each.def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: commands = args.get("commands") if not commands: raise ValueError("One or more commands are required") results = [] success = True for command in commands: try: api.execute_command(command) results.append(f"Command '{command}' executed successfully") except Exception as e: success = False results.append(f"Failed to execute command '{command}': {str(e)}") if success: return [ TextContent( type="text", text="All commands executed successfully!" ) ] else: return [ TextContent( type="text", text="\n".join(results) ) ]
- The get_tool_description method defines the Tool schema for 'obsidian_execute_commands', including name, description, and inputSchema requiring a list of commands.def get_tool_description(self): return Tool( name=self.name, description="Execute one or more commands in obsidian interface, *in order*. For commands used on specific notes, make sure to open a note first.", inputSchema={ "type": "object", "properties": { "commands": { "type": "array", "items": { "type": "string", "description": "Command to execute" }, "description": "List of commands to execute" }, }, "required": ["commands"] } )
- src/mcp_obsidian_advanced/server.py:25-43 (registration)TOOL_MAPPING dictionary maps the tool name 'obsidian_execute_commands' (imported as tools.TOOL_EXECUTE_COMMANDS) to its handler class ExecuteCommandsToolHandler. This mapping is used in register_tools() to instantiate and register the tool with the MCP server.# Tool mapping between tool constants and their handler classes TOOL_MAPPING = { tools.TOOL_LIST_FILES_IN_DIR: tools.ListFilesInDirToolHandler, tools.TOOL_SIMPLE_SEARCH: tools.SearchToolHandler, tools.TOOL_PATCH_CONTENT: tools.PatchContentToolHandler, tools.TOOL_PUT_CONTENT: tools.PutContentToolHandler, tools.TOOL_APPEND_CONTENT: tools.AppendContentToolHandler, tools.TOOL_DELETE_FILE: tools.DeleteFileToolHandler, tools.TOOL_COMPLEX_SEARCH: tools.ComplexSearchToolHandler, tools.TOOL_BATCH_GET_FILES: tools.BatchGetFilesToolHandler, tools.TOOL_PERIODIC_NOTES: tools.PeriodicNotesToolHandler, tools.TOOL_RECENT_PERIODIC_NOTES: tools.RecentPeriodicNotesToolHandler, tools.TOOL_RECENT_CHANGES: tools.RecentChangesToolHandler, tools.TOOL_UNDERSTAND_VAULT: tools.UnderstandVaultToolHandler, tools.TOOL_GET_ACTIVE_NOTE: tools.GetActiveNoteToolHandler, tools.TOOL_OPEN_FILES: tools.OpenFilesToolHandler, tools.TOOL_LIST_COMMANDS: tools.ListCommandsToolHandler, tools.TOOL_EXECUTE_COMMANDS: tools.ExecuteCommandsToolHandler, }
- src/mcp_obsidian_advanced/server.py:95-109 (registration)The register_tools function instantiates handler classes from TOOL_MAPPING based on INCLUDE_TOOLS env var (or all), adds them to tool_handlers dict, which is used by @app.list_tools() and @app.call_tool() decorators.def register_tools(): """Register the selected tools with the server.""" tools_to_include = parse_include_tools() registered_count = 0 for tool_name in tools_to_include: if tool_name in TOOL_MAPPING: handler_class = TOOL_MAPPING[tool_name] handler_instance = handler_class() add_tool_handler(handler_instance) registered_count += 1 logger.debug(f"Registered tool: {tool_name}") logger.info(f"Successfully registered {registered_count} tools")
- Base ToolHandler class that all tool handlers inherit from, providing the name, abstract get_tool_description and run_tool methods.class ToolHandler(): def __init__(self, tool_name: str): self.name = tool_name def get_tool_description(self) -> Tool: raise NotImplementedError() def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: raise NotImplementedError()