collection
List all collections in a specified project space, with options for JSON output and including system collections.
Instructions
Show collections for space. Lists all collections available in the current space.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | No | Project name | |
| json | No | JSON output format | |
| sys | No | Show system collections |
Implementation Reference
- src/index.ts:177-181 (schema)Schema definition for the 'collection' tool. Defines input parameters: project (optional), json (optional boolean), sys (optional boolean to show system collections).
const collectionSchema = z.object({ project: z.string().optional().describe("Project name"), json: z.boolean().optional().describe("JSON output format"), sys: z.boolean().optional().describe("Show system collections") }); - src/index.ts:498-510 (registration)Tool registration entry for 'collection' in the tools array. Defines name='collection', description='Show collections for space', and maps to the collectionSchema for input validation.
{ name: "collection", description: "Show collections for space. Lists all collections available in the current space.", schema: collectionSchema, inputSchema: { type: "object", properties: { project: { type: "string", description: "Project name" }, json: { type: "boolean", description: "JSON output format" }, sys: { type: "boolean", description: "Show system collections" } } } } - src/index.ts:1370-1391 (handler)Handler implementation for the 'collection' tool. Builds CLI arguments to call 'coho collection' with project, space, json, and sys flags, then executes via executeCohoCommand and returns the result.
case "collection": { const { project, json, sys } = args as CollectionArgs; const collectionArgs = [ 'collection', '--project', project || config.projectId, '--space', config.space ]; if (json) collectionArgs.push('--json'); if (sys) collectionArgs.push('--sys'); const result = await executeCohoCommand(collectionArgs); return { content: [ { type: "text", text: result } ], isError: false }; } - src/index.ts:204-204 (helper)TypeScript type inference for CollectionArgs using z.infer<typeof collectionSchema>.
type CollectionArgs = z.infer<typeof collectionSchema>; - src/index.ts:528-564 (helper)Helper function executeCohoCommand used by the 'collection' tool handler to execute CLI commands with admin token sanitization.
// Helper function to execute coho CLI commands async function executeCohoCommand(args: string[]): Promise<string> { const safeArgs = ['coho', ...args, '--admintoken', '***']; console.error(`Executing command: ${safeArgs.join(' ')}`); try { const { stdout, stderr } = await execFile('coho', [...args, '--admintoken', config.adminToken], { timeout: 120000 // 2 minutes timeout for CLI operations }); if (stderr) { // Sanitize stderr before logging to avoid token exposure const safeSterr = stderr.replace(new RegExp(config.adminToken, 'g'), '***'); console.error(`Command output to stderr:`, safeSterr); } console.error(`Command successful`); const result = stdout || stderr; // Sanitize result to ensure admin token is not exposed return result ? result.replace(new RegExp(config.adminToken, 'g'), '***') : result; } catch (error: any) { // Comprehensive sanitization of all error properties to avoid admin token exposure const sanitizeText = (text: string): string => text ? text.replace(new RegExp(config.adminToken, 'g'), '***') : text; const sanitizedMessage = sanitizeText(error?.message || 'Unknown error'); const sanitizedCmd = sanitizeText(error?.cmd || ''); const sanitizedStdout = sanitizeText(error?.stdout || ''); const sanitizedStderr = sanitizeText(error?.stderr || ''); // Log sanitized error details console.error(`Command failed: ${sanitizedMessage}`); if (sanitizedCmd) console.error(`Command: ${sanitizedCmd}`); if (sanitizedStdout) console.error(`Stdout: ${sanitizedStdout}`); if (sanitizedStderr) console.error(`Stderr: ${sanitizedStderr}`); // Return sanitized error message const errorDetails = [sanitizedMessage, sanitizedStderr].filter(Boolean).join(' - '); throw new McpError(ErrorCode.InvalidRequest, `Command failed: ${errorDetails}`); } }