notes_file
Create, read, update, delete, and list notes stored in a local JSON file using action commands.
Instructions
CRUD on local notes.json.
Actions:
create - add a new note: action='create', key='foo', content='...'
read - fetch one note: action='read', key='foo'
update - replace existing: action='update', key='foo', content='...'
delete - remove a note: action='delete', key='foo'
list - list all keys: action='list'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | ||
| key | No | ||
| content | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:70-123 (handler)The main handler function for the 'notes_file' tool. Decorated with @mcp.tool, it implements CRUD operations (create, read, update, delete, list) on a local notes.json file. It uses helper functions _load_notes and _save_notes to persist data.
@mcp.tool def notes_file( action: Literal["create", "read", "update", "delete", "list"], key: str = "", content: str = "", ) -> str: """CRUD on local notes.json. Actions: 1. create - add a new note: action='create', key='foo', content='...' 2. read - fetch one note: action='read', key='foo' 3. update - replace existing: action='update', key='foo', content='...' 4. delete - remove a note: action='delete', key='foo' 5. list - list all keys: action='list' """ notes = _load_notes() if action == "list": return ", ".join(sorted(notes.keys())) if notes else "(no notes yet)" if not key: return f"error: action {action!r} requires a key" if action == "create": if key in notes: return f"error: {key!r} already exists; use action='update' to replace" if not content: return "error: 'create' requires content" notes[key] = content _save_notes(notes) return f"saved {key}" if action == "read": if key not in notes: return f"error: {key!r} not found" return notes[key] if action == "update": if key not in notes: return f"error: {key!r} not found; use action='create' to add" if not content: return "error: 'update' requires content" notes[key] = content _save_notes(notes) return f"updated {key}" if action == "delete": if key not in notes: return f"error: {key!r} not found" del notes[key] _save_notes(notes) return f"deleted {key}" return f"error: unknown action {action!r}" - server.py:70-70 (registration)The tool is registered via the @mcp.tool decorator on the notes_file function (line 70).
@mcp.tool - server.py:71-75 (schema)The input schema/type definition for notes_file: action (Literal['create','read','update','delete','list']), key (str), content (str). The docstring describes allowed actions.
def notes_file( action: Literal["create", "read", "update", "delete", "list"], key: str = "", content: str = "", ) -> str: - server.py:19-23 (helper)Helper function _load_notes that reads notes from notes.json file and returns a dict.
def _load_notes() -> dict[str, str]: if not NOTES.exists(): return {} raw = NOTES.read_text().strip() return json.loads(raw) if raw else {} - server.py:26-27 (helper)Helper function _save_notes that writes the notes dict to notes.json file.
def _save_notes(data: dict[str, str]) -> None: NOTES.write_text(json.dumps(data, indent=2))