monica_manage_tag
Manage contact tags in Monica CRM to organize and categorize your contacts effectively. Perform actions like listing, creating, updating, or deleting tags for better contact management.
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 | ||
| tagId | No | ||
| limit | No | ||
| page | No | ||
| payload | No |
Implementation Reference
- src/tools/modules/tags.ts:28-123 (handler)Handler function for 'monica_manage_tag' tool that supports listing, getting, creating, updating, and deleting tags using 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)Registration of the 'monica_manage_tag' tool, including title, description, input schema, and reference to the handler function.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:20-25 (schema)Zod input schema defining parameters for the tool: action, optional tagId, limit, page, and payload.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()
- src/tools/modules/tags.ts:6-8 (schema)Zod schema for tag payload, requiring a name string between 1 and 255 characters.const tagPayloadSchema = z.object({ name: z.string().min(1).max(255) });
- src/tools/modules/tags.ts:127-131 (helper)Helper function to convert TagPayloadForm to the input format expected by createTag and updateTag methods.function toTagPayloadInput(payload: TagPayloadForm): CreateTagPayload & UpdateTagPayload { return { name: payload.name }; }