list_teams
List all teams the authenticated user belongs to. Use this to view team memberships and access team-specific notes.
Instructions
List teams the user belongs to
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:138-144 (handler)The handler function for 'list_teams' tool. It calls hackmdFetch('/teams') to list teams the user belongs to, and returns the result wrapped with success() or error().
server.tool("list_teams", "List teams the user belongs to", {}, async () => { try { return success(await hackmdFetch("/teams")); } catch (e) { return error((e as Error).message); } }); - src/tools.ts:138-144 (registration)Registration of the 'list_teams' tool via server.tool() with name, description, empty input schema ({}), and async handler.
server.tool("list_teams", "List teams the user belongs to", {}, async () => { try { return success(await hackmdFetch("/teams")); } catch (e) { return error((e as Error).message); } }); - src/tools.ts:138-144 (schema)The empty Zod schema {} is used as the input validation for list_teams, meaning no parameters are required.
server.tool("list_teams", "List teams the user belongs to", {}, async () => { try { return success(await hackmdFetch("/teams")); } catch (e) { return error((e as Error).message); } }); - src/api.ts:13-36 (helper)The hackmdFetch helper function that performs authenticated HTTP requests to the HackMD API. Called by the list_teams handler with path '/teams'.
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" }; - src/helpers.ts:1-12 (helper)The success() and error() helper functions used to format MCP tool responses. success serializes data as JSON, error returns an isError response.
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, }; }