get_note
Retrieve the full content of a HackMD note by providing its unique note ID. Access stored note details quickly.
Instructions
Get a note by ID (returns full content)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note_id | Yes | Note ID |
Implementation Reference
- src/tools.ts:27-40 (handler)Tool 'get_note' registration and handler: fetches a note by ID from the HackMD API via a GET request to /notes/{note_id}. Input schema validates a required note_id string.
server.tool( "get_note", "Get a note by ID (returns full content)", { note_id: z.string().min(1).describe("Note ID"), }, async ({ note_id }) => { try { return success(await hackmdFetch(`/notes/${note_id}`)); } catch (e) { return error((e as Error).message); } } ); - src/tools.ts:27-32 (schema)Zod schema for 'get_note' input: requires note_id as a non-empty string.
server.tool( "get_note", "Get a note by ID (returns full content)", { note_id: z.string().min(1).describe("Note ID"), }, - src/tools.ts:6-6 (registration)The registerTools function is called from server.ts to register all tools including get_note with the MCP server.
export function registerTools(server: McpServer) { - src/api.ts:13-38 (helper)hackmdFetch helper: makes authenticated HTTP requests to the HackMD API, used by get_note to GET /notes/{note_id}.
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)success and error response formatters: wrap API results into MCP-compatible content arrays, used by the get_note handler's return value.
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, }; }