Skip to main content
Glama
custom-tools.ts9.24 kB
import { composio } from '../composio-client.js' import { z } from 'zod' /** * Custom tool definitions for specialized Google Workspace operations */ /** * Email Analytics Tool * Analyzes email patterns and provides insights */ export const createEmailAnalyticsTool = async () => { return await composio.tools.createCustomTool({ slug: 'EMAIL_ANALYTICS', name: 'Email Analytics', description: 'Analyze email patterns and generate insights', inputParams: z.object({ timeframe: z.enum(['day', 'week', 'month']).default('week'), analysisType: z.enum(['volume', 'sentiment', 'response_time']).default('volume'), includeThreads: z.boolean().default(true) }), execute: async (input) => { const { timeframe, analysisType, includeThreads } = input // Mock analytics - in production, this would call Gmail API const analytics = { period: timeframe, analysis_type: analysisType, metrics: { total_emails: Math.floor(Math.random() * 100) + 20, avg_daily: Math.floor(Math.random() * 20) + 5, response_rate: Math.floor(Math.random() * 40) + 60, top_senders: [ { email: 'colleague@company.com', count: 12 }, { email: 'client@external.com', count: 8 }, { email: 'notifications@service.com', count: 25 } ], busiest_hours: ['9-10 AM', '2-3 PM', '4-5 PM'], sentiment_score: Math.random() * 0.4 + 0.6 // 0.6-1.0 range }, insights: [ 'Peak email activity occurs during mid-morning and afternoon', 'Response rate is above average for your industry', 'Consider email batching during high-volume periods' ], generated_at: new Date().toISOString() } return { data: analytics, successful: true, error: null } } }) } /** * Meeting Optimizer Tool * Suggests optimal meeting times based on calendar analysis */ export const createMeetingOptimizerTool = async () => { return await composio.tools.createCustomTool({ slug: 'MEETING_OPTIMIZER', name: 'Meeting Time Optimizer', description: 'Find optimal meeting times based on attendee availability', inputParams: z.object({ attendees: z.array(z.string().email()), duration: z.number().min(15).max(480).default(60), // minutes dateRange: z.object({ start: z.string(), end: z.string() }), preferences: z.object({ preferredTimeSlots: z.array(z.string()).optional(), avoidMornings: z.boolean().default(false), respectTimeZones: z.boolean().default(true) }).optional() }), execute: async (input) => { const { attendees, duration, dateRange, preferences } = input // Mock optimization algorithm const suggestedTimes = [ { datetime: '2024-01-15T14:00:00Z', confidence: 0.95, conflicts: 0, reasoning: 'All attendees free, optimal time zone coverage' }, { datetime: '2024-01-16T10:00:00Z', confidence: 0.82, conflicts: 1, reasoning: 'One attendee has soft conflict, but generally available' }, { datetime: '2024-01-17T15:30:00Z', confidence: 0.78, conflicts: 0, reasoning: 'Good time zone fit, post-lunch energy peak' } ] return { data: { request: { attendees, duration, date_range: dateRange }, suggestions: suggestedTimes, analysis: { total_attendees: attendees.length, time_zones_considered: ['UTC', 'EST', 'PST'], optimization_factors: [ 'Calendar availability', 'Time zone preferences', 'Historical meeting patterns', 'Energy levels (circadian rhythm)' ] }, next_steps: [ 'Review suggested times with stakeholders', 'Send calendar invites for preferred slot', 'Set up meeting room or video conference' ] }, successful: true, error: null } } }) } /** * Document Intelligence Tool * Analyzes Google Drive documents for content insights */ export const createDocumentIntelligenceTool = async () => { return await composio.tools.createCustomTool({ slug: 'DOCUMENT_INTELLIGENCE', name: 'Document Intelligence Analyzer', description: 'Extract insights and metadata from Google Drive documents', inputParams: z.object({ fileId: z.string(), analysisDepth: z.enum(['basic', 'detailed', 'comprehensive']).default('basic'), extractKeywords: z.boolean().default(true), summarize: z.boolean().default(false) }), execute: async (input) => { const { fileId, analysisDepth, extractKeywords, summarize } = input // Mock document analysis const analysis = { file_id: fileId, analysis_depth: analysisDepth, metadata: { word_count: Math.floor(Math.random() * 5000) + 500, page_count: Math.floor(Math.random() * 20) + 1, language: 'en', reading_time: `${Math.floor(Math.random() * 15) + 2} minutes`, last_modified: new Date(Date.now() - Math.random() * 7 * 24 * 60 * 60 * 1000).toISOString() }, content_analysis: { topics: ['project management', 'team collaboration', 'quarterly goals'], sentiment: 'professional', complexity_score: Math.random() * 0.5 + 0.3, // 0.3-0.8 range keywords: extractKeywords ? [ 'quarterly', 'objectives', 'team', 'deliverables', 'timeline' ] : [] }, summary: summarize ? 'Document outlines quarterly objectives and team deliverables with associated timelines and success metrics.' : null, actionable_items: [ 'Review quarterly objectives', 'Assign team responsibilities', 'Set milestone deadlines', 'Schedule progress check-ins' ], recommendations: [ 'Consider adding visual timeline', 'Include risk assessment section', 'Define success metrics more clearly' ] } return { data: analysis, successful: true, error: null } } }) } /** * Workflow Automation Tool * Creates automated workflows across Google Workspace */ export const createWorkflowAutomationTool = async () => { return await composio.tools.createCustomTool({ slug: 'WORKSPACE_WORKFLOW', name: 'Google Workspace Workflow Automation', description: 'Create and execute automated workflows across Google Workspace apps', inputParams: z.object({ workflowType: z.enum(['email_to_calendar', 'drive_to_sheets', 'calendar_to_email']), trigger: z.object({ type: z.enum(['schedule', 'email', 'file_change', 'calendar_event']), conditions: z.record(z.any()) }), actions: z.array(z.object({ app: z.enum(['gmail', 'calendar', 'drive', 'sheets']), action: z.string(), parameters: z.record(z.any()) })) }), execute: async (input) => { const { workflowType, trigger, actions } = input // Mock workflow execution const executionResults = actions.map((action, index) => ({ step: index + 1, app: action.app, action: action.action, status: 'completed', execution_time: Math.floor(Math.random() * 2000) + 200, // ms result: `${action.app} ${action.action} executed successfully` })) return { data: { workflow_id: `wf_${Date.now()}`, workflow_type: workflowType, execution_summary: { total_steps: actions.length, completed_steps: actions.length, failed_steps: 0, total_execution_time: executionResults.reduce((sum, r) => sum + r.execution_time, 0) }, step_results: executionResults, next_execution: trigger.type === 'schedule' ? new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString() : 'on_demand', logs: [ 'Workflow initiated successfully', 'All authentication checks passed', 'Cross-app permissions verified', 'Execution completed without errors' ] }, successful: true, error: null } } }) } /** * Initialize all custom tools */ export async function initializeCustomTools() { console.log('🔧 Initializing custom tools...') try { const tools = await Promise.all([ createEmailAnalyticsTool(), createMeetingOptimizerTool(), createDocumentIntelligenceTool(), createWorkflowAutomationTool() ]) console.log(`✅ Created ${tools.length} custom tools:`) tools.forEach(tool => { console.log(` • ${tool.name}: ${tool.description}`) }) return tools } catch (error) { console.error('❌ Failed to initialize custom tools:', error) throw error } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cfdude/composio-google-workspace'

If you have feedback or need assistance with the MCP directory API, please join our Discord server