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"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that it returns content and metadata, and clarifies the note selection as 'most recently edited', which adds useful context. However, it doesn't cover other behavioral aspects such as error handling, performance, or whether it requires specific permissions or has side effects, leaving gaps for a tool with no annotation support.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded and concise, consisting of two clear sentences that directly explain the tool's purpose and behavior without any wasted words. Every sentence adds value, making it efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has no parameters, no annotations, and no output schema, the description provides basic purpose and selection criteria. However, for a tool that retrieves note content and metadata, it lacks details on the return format, potential errors, or how 'active' is defined in edge cases, making it adequate but incomplete for full contextual understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter information is needed. The description appropriately adds no parameter details, focusing on the tool's function instead. This meets the baseline for zero parameters, as it doesn't need to compensate for any schema gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('content and metadata of the currently active note in Obsidian'), making the purpose specific and understandable. However, it doesn't explicitly differentiate from siblings like 'obsidian_recent_changes' or 'obsidian_open_files', which might also relate to note access or state.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying 'currently active note' and 'most recently edited', suggesting it should be used when the user needs the latest edited note. However, it lacks explicit guidance on when to use this tool versus alternatives like 'obsidian_recent_changes' or 'obsidian_open_files', and doesn't mention any exclusions or prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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