list_collections
Retrieve a list of all collections defined in your NocoBase instance.
Instructions
List all collections in NocoBase
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_collections"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:41-45 (handler)The tool 'list_collections' is registered via server.registerTool with name 'list_collections'. Its handler is an async function that calls nocoFetch('/api/collections') to list all collections in NocoBase and wraps the result with the ok() helper.
server.registerTool( "list_collections", { description: "List all collections in NocoBase" }, async () => ok(await nocoFetch("/api/collections")) ); - src/index.ts:41-45 (registration)Same code block — this is also where the tool is registered on the MCP server using 'server.registerTool("list_collections", ...)'.
server.registerTool( "list_collections", { description: "List all collections in NocoBase" }, async () => ok(await nocoFetch("/api/collections")) ); - src/index.ts:43-43 (schema)The schema/description for 'list_collections' is simply { description: 'List all collections in NocoBase' } with no input parameters (no inputSchema).
{ description: "List all collections in NocoBase" }, - src/index.ts:29-31 (helper)The 'ok' helper function wraps data into the MCP content response format: { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] }.
const ok = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }); - src/index.ts:18-27 (helper)The 'nocoFetch' helper is used by the handler to make authenticated HTTP requests to the NocoBase API at /api/collections.
async function nocoFetch(path: string, options: RequestInit = {}): Promise<unknown> { const url = `${NOCOBASE_URL}${path}`; const res = await fetch(url, { ...options, headers: { ...reqHeaders, ...(options.headers as Record<string, string> | undefined) }, }); const text = await res.text(); if (!res.ok) throw new Error(`HTTP ${res.status} ${res.statusText}: ${text}`); try { return JSON.parse(text); } catch { return text; } }