Skip to main content
Glama
ToKiDoO

Advanced Obsidian MCP Server

by ToKiDoO

obsidian_get_active_note

Retrieve content and metadata from the currently edited note in Obsidian to enable AI agents to access and work with active user content.

Instructions

Get the content and metadata of the currently active note in Obsidian. Always returns the note that is most recently edited (edit with user).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The GetActiveNoteToolHandler class implements the obsidian_get_active_note tool. It fetches the active note via Obsidian's REST API, extracts content, frontmatter, tags, and stat info, enhances with note_info from obsidiantools, and returns formatted metadata and content.
    class GetActiveNoteToolHandler(ToolHandler): def __init__(self): super().__init__(TOOL_GET_ACTIVE_NOTE) def get_tool_description(self): return Tool( name=self.name, description="Get the content and metadata of the currently active note in Obsidian. Always returns the note that is most recently edited (edit with user).", inputSchema={ "type": "object", "properties": {}, "required": [] } ) def run_tool(self, args: dict) -> Sequence[TextContent | ImageContent | EmbeddedResource]: try: # Get the active note with full metadata using the JSON API url = f"{api.get_base_url()}/active/" headers = api._get_headers() | {'Accept': 'application/vnd.olrapi.note+json'} def call_fn(): response = requests.get(url, headers=headers, verify=api.verify_ssl, timeout=api.timeout) response.raise_for_status() return response.json() active_note_data = api._safe_call(call_fn) # Extract data from the API response content = active_note_data.get('content', '') frontmatter = active_note_data.get('frontmatter', {}) path = active_note_data.get('path', '') stat = active_note_data.get('stat', {}) api_tags = active_note_data.get('tags', []) if not content and not path: return [ TextContent( type="text", text="No active note found." ) ] # Get additional note info using obsidiantools for connections/links try: note_info = api.get_note_info(path) # Replace the tags from get_note_info with the more accurate API tags note_info['metadata']['tags'] = api_tags # Also update frontmatter with API data for accuracy note_info['metadata']['front_matter'] = frontmatter # Update file info with API stat data note_info['metadata']['file_info'].update({ 'creation_time': stat.get('ctime'), 'modification_time': stat.get('mtime'), 'size (bytes)': stat.get('size') }) except Exception as note_info_error: # Fallback: create basic note info from API data note_info = { 'metadata': { 'tags': api_tags, 'front_matter': frontmatter, 'file_info': { 'rel_filepath': path, 'creation_time': stat.get('ctime'), 'modification_time': stat.get('mtime'), 'size (bytes)': stat.get('size') }, 'counts': { 'n_backlinks': 0, 'n_wikilinks': 0, 'n_embedded_files': 0, 'n_tags': len(api_tags) } }, 'connections': { 'direct_links': [], 'backlinks': [], 'non_existent_links': [] } } # Create metadata JSON following BatchGetFilesToolHandler pattern metadata_json = { "filepath": path, "note_info": note_info } return [ TextContent( type="text", text=f"## Active Note: {path}\n\n### Metadata & Info\n```json\n{json.dumps(metadata_json, indent=2)}\n```" ), TextContent( type="text", text=f"### Content Below:\n\n{content}" ) ] except Exception as e: return [ TextContent( type="text", text=f"Error getting active note: {str(e)}" ) ]
  • Tool schema definition for obsidian_get_active_note, specifying no input parameters.
    def get_tool_description(self): return Tool( name=self.name, description="Get the content and metadata of the currently active note in Obsidian. Always returns the note that is most recently edited (edit with user).", inputSchema={ "type": "object", "properties": {}, "required": [] } )
  • TOOL_MAPPING dictionary that associates the tool name 'obsidian_get_active_note' with its handler class GetActiveNoteToolHandler.
    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, }
  • register_tools function instantiates handler classes from TOOL_MAPPING (including GetActiveNoteToolHandler) and registers them for use by the MCP server.
    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")
  • Constant defining the tool name 'obsidian_get_active_note' used throughout the codebase.
    TOOL_GET_ACTIVE_NOTE = "obsidian_get_active_note"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ToKiDoO/mcp-obsidian-advanced'

If you have feedback or need assistance with the MCP directory API, please join our Discord server