list_notes
List all notes of the current user on HackMD. Retrieve note IDs and titles to manage your notes via API calls.
Instructions
List all notes of the current user
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:19-25 (handler)The 'list_notes' tool handler: registers the tool with no input schema, calls hackmdFetch('/notes') to list all notes for the current user, and returns the JSON result wrapped via the success helper.
server.tool("list_notes", "List all notes of the current user", {}, async () => { try { return success(await hackmdFetch("/notes")); } catch (e) { return error((e as Error).message); } }); - src/tools.ts:6-25 (registration)The registerTools function where 'list_notes' is registered on the MCP server (lines 19-25).
export function registerTools(server: McpServer) { // ── User ────────────────────────────────────────────── server.tool("get_me", "Get current user profile", {}, async () => { try { return success(await hackmdFetch("/me")); } catch (e) { return error((e as Error).message); } }); // ── Notes ───────────────────────────────────────────── server.tool("list_notes", "List all notes of the current user", {}, async () => { try { return success(await hackmdFetch("/notes")); } catch (e) { return error((e as Error).message); } }); - src/api.ts:13-38 (helper)The hackmdFetch helper: generic API client that authenticates requests to the HackMD API using HACKMD_API_TOKEN, handles errors, status codes, and returns parsed JSON.
export async function hackmdFetch( path: string, options: { method?: string; body?: unknown } = {} ): Promise<unknown> { const { method = "GET", body } = options; const token = getToken(); const res = await fetch(`${API_BASE}${path}`, { method, headers: { Authorization: `Bearer ${token}`, ...(body ? { "Content-Type": "application/json" } : {}), }, ...(body ? { body: JSON.stringify(body) } : {}), }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(`HackMD API ${method} ${path} → ${res.status}: ${text}`); } if (res.status === 204) return { success: true }; if (res.status === 202) return { success: true, status: "accepted" }; return res.json(); } - src/helpers.ts:1-12 (helper)The success and error helper functions used to wrap tool responses in the expected MCP text content format.
export function success(data: unknown) { return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } export function error(message: string) { return { content: [{ type: "text" as const, text: JSON.stringify({ error: message }) }], isError: true as const, }; }