Repository navigation
Description
Overview
Implement create_nodes_from_markdown MCP method that parses markdown content and creates hierarchical NodeSpace nodes with proper parent/sibling relationships.
Use Case
AI agents (e.g., Claude Code) send markdown content via MCP stdio → NodeSpace creates structured node hierarchy → User sees real-time updates in UI.
Dependencies
Blocked by #112 - Requires MCP server foundation
Implementation
Backend (Rust)
- Add
pulldown-cmark = "0.11"dependency to Cargo.toml - Create
src-tauri/src/mcp/handlers/markdown.rs - Implement markdown parser with heading hierarchy tracking
- Track heading level stack (h1 → h2 → h3 parent-child)
- Pop stack when encountering same/lower level heading
- Implement list hierarchy with indentation tracking
- Track indentation depth
- Create parent-child based on indent level
- Create nodes via NodeService
- Set correct
parent_idfor hierarchy - Set
before_sibling_idfor top-to-bottom ordering
- Set correct
- Create container node with provided title
- Emit Tauri events for each created node (reactivity)
Node Type Mapping (Content-Based, No Properties)
Headers - Store markdown with hashtags in content:
# Heading→headernode, content:"# Heading"## Heading→headernode, content:"## Heading"### Heading→headernode, content:"### Heading"
Code blocks - Store with language fence in content:
rust\ncode\n```` → `code-block` node, content: `"rust\ncode\n```"`
Ordered lists - Store with number prefix in content:
1. First→ordered-listnode, content:"1. First"2. Second→ordered-listnode, content:"2. Second"
Tasks - Store with markdown checkbox in content:
- [ ] Task→tasknode, content:"- [ ] Task"(status: pending)- [~] Working→tasknode, content:"- [~] Working"(status: inProgress)- [x] Done→tasknode, content:"- [x] Done"(status: completed)
Other:
- Paragraph text →
textnode, content:"paragraph text" - List item→textnode, content:"- List item"(nested via parent_id)> Quote→quote-blocknode, content:"> Quote"
Key principle: Store content AS-IS from markdown. Let the frontend components parse and render appropriately.
MCP Interface
Request:
{
"jsonrpc": "2.0",
"method": "create_nodes_from_markdown",
"params": {
"markdown_content": "# Title\n## Subtitle\n- Item",
"container_title": "Meeting Notes"
}
}Response:
{
"jsonrpc": "2.0",
"result": {
"success": true,
"container_node_id": "uuid-123",
"nodes_created": 15,
"node_ids": ["uuid-123", "uuid-124", ...]
}
}Acceptance Criteria
- Markdown parser correctly identifies headings, lists, code blocks, quotes
- Heading hierarchy preserved (h1 → h2 → h3 parent-child relationships)
- List indentation creates nested child nodes
- Sibling ordering is top-to-bottom as markdown appears
- Container node created with provided title
- All nodes have correct
parent_idandbefore_sibling_id - Content stored AS-IS from markdown (headers with #, tasks with [ ], etc.)
- Tauri events emitted → UI updates in real-time
- Test with sample document
- MCP response includes all created node IDs
Testing
- Unit tests: Parse various markdown structures (headings, nested lists, code blocks)
- Integration test: Import
/Users/malibio/nodespace/data/sample-nodespace-data.md - Manual test: Claude Code imports markdown → NodeSpace UI shows nodes immediately
Sample Document
Test with cleaned sample-nodespace-data.md (Logseq collapsed:: true markers removed)
Path: /Users/malibio/nodespace/data/sample-nodespace-data.md ✅ File exists (8740 bytes)
Implementation Q&A
Q1: Ordered List Node Type
A: Use ordered-list node type. Content includes number: "1. Item"
Q2: Event Emission
A: Emit events directly in markdown handler after each node creation:
app.emit("node-created", json!({
"node_id": node_id,
"node_type": node.node_type
}))?;Event names: node-created, node-updated, node-deleted
Q3: Header Content Format
A: Store headers WITH hashtags in content: content: "## Heading Text"
Frontend parses the hashtags to determine level. Do NOT use properties.
Q4: List Items
A: Unordered lists (- Item) → text node, content: "- Item"
Tasks (- [ ] Task) → task node, content: "- [ ] Task"
Hierarchy via parent_id/before_sibling_id.
Q5: Task Status
A: Three task states based on checkbox content:
- [ ] Task→ pending- [~] Taskor- [o] Task→ inProgress- [x] Taskor- [X] Task→ completed
See: task-node.svelte:62-78 for parsing logic
Q6: Code Block Content
A: Store WITH language fence: content: "```rust\ncode\n```"
Frontend extracts language from fence. Do NOT use properties.
Q7: Sample Document Path
A: File exists: /Users/malibio/nodespace/data/sample-nodespace-data.md
Q8: Tauri Integration
A: MCP-only for now. Keep parser logic reusable.
References
- MCP Integration: mcp-integration.md
- Architecture: ADR-021
- Node Types:
packages/desktop-app/src-tauri/src/constants.rs - Task Status Parsing:
packages/desktop-app/src/lib/design/components/task-node.svelte:62-78
Activity
feat: Add create_nodes_from_markdown MCP method
fix: Enable GitHub Flavored Markdown extensions for task lists
refactor: Enhance markdown import with comprehensive improvements
feat: Add event emission for markdown import (CRITICAL FIX)
Merge pull request: Add markdown import with real-time UI sync (#296)
feat: Add create_nodes_from_markdown MCP method
fix: Enable GitHub Flavored Markdown extensions for task lists
refactor: Enhance markdown import with comprehensive improvements
feat: Add event emission for markdown import (CRITICAL FIX)
Merge pull request: Add markdown import with real-time UI sync (#296)
feat: Add create_nodes_from_markdown MCP method
fix: Enable GitHub Flavored Markdown extensions for task lists
refactor: Enhance markdown import with comprehensive improvements
feat: Add event emission for markdown import (CRITICAL FIX)
Merge pull request: Add markdown import with real-time UI sync (#296)
feat: Add create_nodes_from_markdown MCP method
fix: Enable GitHub Flavored Markdown extensions for task lists
refactor: Enhance markdown import with comprehensive improvements
feat: Add event emission for markdown import (CRITICAL FIX)
Merge pull request: Add markdown import with real-time UI sync (#296)