Skip to main content
Glama
dweigend

Joplin MCP Server

by dweigend

import_markdown

Convert a markdown file into a Joplin note by specifying its file path. This tool adds external markdown content to your Joplin workspace for organization and editing.

Instructions

Import a markdown file as a new note.

Args: args: Import parameters file_path: Path to the markdown file Returns: Dictionary containing the created note data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsYes

Implementation Reference

  • The handler function for the 'import_markdown' tool, including the @mcp.tool() decorator for registration. It processes the input file path, parses the Markdown content using a helper utility, and creates a new note in Joplin.
    @mcp.tool() async def import_markdown(args: ImportMarkdownInput) -> Dict[str, Any]: """Import a markdown file as a new note. Args: args: Import parameters file_path: Path to the markdown file Returns: Dictionary containing the created note data """ if not api: return {"error": "Joplin API client not initialized"} try: file_path = Path(args.file_path) md_content = MarkdownContent.from_file(file_path) note = api.create_note( title=md_content.title, body=md_content.content ) return { "status": "success", "note": { "id": note.id, "title": note.title, "body": note.body, "created_time": note.created_time.isoformat() if note.created_time else None, "updated_time": note.updated_time.isoformat() if note.updated_time else None, "is_todo": note.is_todo }, "imported_from": str(file_path) } except Exception as e: logger.error(f"Error importing markdown: {e}") return {"error": str(e)}
  • Pydantic input schema for the import_markdown tool, defining the required 'file_path' parameter.
    class ImportMarkdownInput(BaseModel): """Input parameters for importing markdown files.""" file_path: str
  • Helper classmethod MarkdownContent.from_file() that parses a markdown file, extracts title from first H1 or filename, and provides content, used directly in the import_markdown handler.
    @classmethod def from_file(cls, file_path: Path) -> 'MarkdownContent': """Create MarkdownContent from a file. Args: file_path: Path to the markdown file Returns: MarkdownContent instance Raises: FileNotFoundError: If the file doesn't exist ValueError: If the file is empty or invalid """ if not file_path.exists(): raise FileNotFoundError(f"File not found: {file_path}") if not file_path.is_file(): raise ValueError(f"Not a file: {file_path}") content = file_path.read_text(encoding='utf-8') if not content.strip(): raise ValueError(f"File is empty: {file_path}") # Extract title from first heading or use filename lines = content.splitlines() title = file_path.stem for line in lines: if line.startswith('# '): title = line[2:].strip() content = '\n'.join(lines[1:]).strip() break return cls( title=title, content=content, source_path=file_path, created_time=datetime.fromtimestamp(file_path.stat().st_ctime), modified_time=datetime.fromtimestamp(file_path.stat().st_mtime) )

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/dweigend/joplin-mcp-server'

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