Add an item to a list
add_itemAdd an item to a Cozi list by specifying the list ID and text. Optionally set a position. Returns the new item's ID and text.
Instructions
Add an item to a list. Returns: {id, text}.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| list_id | Yes | ||
| text | Yes | ||
| position | No |
Implementation Reference
- src/tools/items.ts:5-13 (handler)The addItemHandler function that executes the tool logic. It takes a CoziClient, listId, text, and position, calls client.addItem, and returns {id, text}.
export async function addItemHandler( client: CoziClient, listId: string, text: string, position: number, ): Promise<{ id: string; text: string }> { const item = await client.addItem(listId, text, position); return { id: item.id ?? '', text: item.text }; } - src/tools/items.ts:49-64 (registration)Registration of the 'add_item' tool on the MCP server via server.registerTool. Defines input schema (list_id, text, position) and the callback that invokes addItemHandler.
server.registerTool( 'add_item', { title: 'Add an item to a list', description: 'Add an item to a list. Returns: {id, text}.', inputSchema: { list_id: z.string(), text: z.string(), position: z.number().int().optional(), }, }, async ({ list_id, text, position }) => { const result = await addItemHandler(await getClient(), list_id, text, position ?? 0); return { content: [{ type: 'text', text: JSON.stringify(result) }] }; }, ); - src/tools/items.ts:50-58 (schema)Input schema for the 'add_item' tool defined using zod: list_id (string), text (string), position (optional int).
'add_item', { title: 'Add an item to a list', description: 'Add an item to a list. Returns: {id, text}.', inputSchema: { list_id: z.string(), text: z.string(), position: z.number().int().optional(), }, - src/cozi/client.ts:150-159 (helper)The CoziClient.addItem method that performs the actual HTTP POST request to the Cozi API endpoint /list/{listId}/item/ with text and position body, parsing the response with CoziItemSchema.
async addItem(listId: string, text: string, position = 0): Promise<CoziItem> { if (!text.trim()) throw new ValidationError('Item text cannot be empty'); await this.ensureAuthenticated(); const response = await this.http.request({ method: 'POST', endpoint: this.accountEndpoint(`/list/${listId}/item/`), body: { text, position }, }); return CoziItemSchema.parse(response); } - src/tools/index.ts:14-14 (registration)registerItemTools is called from registerCoziTools which wires up all tool registrations to the MCP server.
registerItemTools(server, getClient);