import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { z } from 'zod'; import { accountParam, runOrDiagnose, registerRunTool } from './utils.js'; export function registerContactsTools(server: McpServer): void { server.registerTool('gog_contacts_search', { description: 'Search personal Google Contacts by name, email, or phone. For searching the Workspace directory (internal users not in your personal contacts), use gog_people_search from gogcli-mcp-contacts.', annotations: { readOnlyHint: true }, inputSchema: { query: z.string().describe('Search query (name, email, or phone)'), account: accountParam, }, }, async ({ query, account }) => { return runOrDiagnose(['contacts', 'search', query], { account }); }); server.registerTool('gog_contacts_list', { description: 'List all Google Contacts.', annotations: { readOnlyHint: true }, inputSchema: { account: accountParam, }, }, async ({ account }) => { return runOrDiagnose(['contacts', 'list'], { account }); }); server.registerTool('gog_contacts_get', { description: 'Get a contact by resource name.', annotations: { readOnlyHint: true }, inputSchema: { resourceName: z.string().describe('Contact resource name (e.g. people/c12345)'), account: accountParam, }, }, async ({ resourceName, account }) => { return runOrDiagnose(['contacts', 'get', resourceName], { account }); }); server.registerTool('gog_contacts_create', { description: 'Create a new Google Contact.', annotations: { destructiveHint: false }, inputSchema: { givenName: z.string().describe('Given (first) name'), familyName: z.string().optional().describe('Family (last) name'), email: z.string().optional().describe('Email address'), phone: z.string().optional().describe('Phone number'), org: z.string().optional().describe('Organization/company name'), title: z.string().optional().describe('Job title'), account: accountParam, }, }, async ({ givenName, familyName, email, phone, org, title, account }) => { const args = ['contacts', 'create', `--given=${givenName}`]; if (familyName) args.push(`--family=${familyName}`); if (email) args.push(`--email=${email}`); if (phone) args.push(`--phone=${phone}`); if (org) args.push(`--org=${org}`); if (title) args.push(`--title=${title}`); return runOrDiagnose(args, { account }); }); registerRunTool(server, { service: 'contacts', examples: '"update", "delete", "directory"' }); }