monica_manage_tag
Manage tags in Monica CRM to group and categorize contacts. Perform actions like listing, creating, updating, or deleting tags to organize contact data efficiently.
Instructions
List, inspect, create, update, or delete tags. Tags allow you to group and categorize contacts.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | ||
| limit | No | ||
| page | No | ||
| payload | No | ||
| tagId | No |
Implementation Reference
- src/tools/modules/tags.ts:28-123 (handler)The handler function that executes the tool logic for 'monica_manage_tag'. It uses a switch statement to handle actions: list, get, create, update, or delete tags via MonicaClient methods.async ({ action, tagId, payload, limit, page }) => { switch (action) { case 'list': { const result = await client.listTags(limit, page); const tags = result.data.map(normalizeTag); return { content: [ { type: 'text' as const, text: `Found ${result.meta.total} tags:\n${tags.map((tag) => `• ${tag.name} (ID: ${tag.id})`).join('\n')}` } ] }; } case 'get': { if (!tagId) { throw new Error('tagId is required for get action'); } const result = await client.getTag(tagId); const tag = normalizeTag(result.data); return { content: [ { type: 'text' as const, text: `Tag Details:\n• Name: ${tag.name}\n• Slug: ${tag.nameSlug}\n• Created: ${tag.createdAt}\n• Updated: ${tag.updatedAt}` } ] }; } case 'create': { if (!payload) { throw new Error('payload is required for create action'); } const input = toTagPayloadInput(payload); const result = await client.createTag(input); const tag = normalizeTag(result.data); return { content: [ { type: 'text' as const, text: `Created tag "${tag.name}" (ID: ${tag.id})` } ] }; } case 'update': { if (!tagId) { throw new Error('tagId is required for update action'); } if (!payload) { throw new Error('payload is required for update action'); } const input = toTagPayloadInput(payload); const result = await client.updateTag(tagId, input); const tag = normalizeTag(result.data); return { content: [ { type: 'text' as const, text: `Updated tag "${tag.name}" (ID: ${tag.id})` } ] }; } case 'delete': { if (!tagId) { throw new Error('tagId is required for delete action'); } await client.deleteTag(tagId); return { content: [ { type: 'text' as const, text: `Deleted tag with ID ${tagId}` } ] }; } default: throw new Error(`Unknown action: ${action}`); } }
- src/tools/modules/tags.ts:15-124 (registration)The server.registerTool call that registers the 'monica_manage_tag' tool, including its title, description, input schema, and handler reference.server.registerTool( 'monica_manage_tag', { title: 'Manage Monica tags', description: 'List, inspect, create, update, or delete tags. Tags allow you to group and categorize contacts.', inputSchema: { action: z.enum(['list', 'get', 'create', 'update', 'delete']), tagId: z.number().int().positive().optional(), limit: z.number().int().min(1).max(100).optional(), page: z.number().int().min(1).optional(), payload: tagPayloadSchema.optional() } }, async ({ action, tagId, payload, limit, page }) => { switch (action) { case 'list': { const result = await client.listTags(limit, page); const tags = result.data.map(normalizeTag); return { content: [ { type: 'text' as const, text: `Found ${result.meta.total} tags:\n${tags.map((tag) => `• ${tag.name} (ID: ${tag.id})`).join('\n')}` } ] }; } case 'get': { if (!tagId) { throw new Error('tagId is required for get action'); } const result = await client.getTag(tagId); const tag = normalizeTag(result.data); return { content: [ { type: 'text' as const, text: `Tag Details:\n• Name: ${tag.name}\n• Slug: ${tag.nameSlug}\n• Created: ${tag.createdAt}\n• Updated: ${tag.updatedAt}` } ] }; } case 'create': { if (!payload) { throw new Error('payload is required for create action'); } const input = toTagPayloadInput(payload); const result = await client.createTag(input); const tag = normalizeTag(result.data); return { content: [ { type: 'text' as const, text: `Created tag "${tag.name}" (ID: ${tag.id})` } ] }; } case 'update': { if (!tagId) { throw new Error('tagId is required for update action'); } if (!payload) { throw new Error('payload is required for update action'); } const input = toTagPayloadInput(payload); const result = await client.updateTag(tagId, input); const tag = normalizeTag(result.data); return { content: [ { type: 'text' as const, text: `Updated tag "${tag.name}" (ID: ${tag.id})` } ] }; } case 'delete': { if (!tagId) { throw new Error('tagId is required for delete action'); } await client.deleteTag(tagId); return { content: [ { type: 'text' as const, text: `Deleted tag with ID ${tagId}` } ] }; } default: throw new Error(`Unknown action: ${action}`); } } );
- src/tools/modules/tags.ts:6-8 (schema)Zod schema for tag payload used in create/update actions (name field).const tagPayloadSchema = z.object({ name: z.string().min(1).max(255) });
- src/tools/modules/tags.ts:127-131 (helper)Helper function to convert the input payload form to the format expected by MonicaClient for create/update tag operations.function toTagPayloadInput(payload: TagPayloadForm): CreateTagPayload & UpdateTagPayload { return { name: payload.name }; }
- src/tools/registerTools.ts:36-36 (registration)Call to registerTagTools within the main registerTools function, which ultimately registers the monica_manage_tag tool.registerTagTools(context);