import { CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js'; /** * Service connectors that integrate with MCP tools * These act as bridges between JARVIS and the various MCP services */ export interface MCPToolResponse { content: Array<{ type: string; text?: string; data?: any; }>; isError?: boolean; } export class GmailConnector { private mcpInvoke?: (tool: string, args: any) => Promise; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { if (mcpInvoke) { this.mcpInvoke = mcpInvoke; } } async getUnreadEmails(limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockEmails(); } try { const response = await this.mcpInvoke('mcp__gmail__gmail_search_messages', { query: 'is:unread', maxResults: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Gmail connector error:', error); return this.getMockEmails(); } } async getImportantEmails(limit: number = 5): Promise { if (!this.mcpInvoke) { return this.getMockEmails(); } try { const response = await this.mcpInvoke('mcp__gmail__gmail_search_messages', { query: 'is:important is:unread', maxResults: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Gmail connector error:', error); return this.getMockEmails(); } } async searchEmails(query: string, limit: number = 20): Promise { if (!this.mcpInvoke) { return this.getMockEmails(); } try { const response = await this.mcpInvoke('mcp__gmail__gmail_search_messages', { query, maxResults: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Gmail search error:', error); return this.getMockEmails(); } } private getMockEmails() { return [ { id: '1', from: 'john@marketing.com', subject: 'Q4 Budget Approval Request', snippet: 'Hi Ricardo, I need your approval for the Q4 marketing budget...', date: new Date().toISOString(), unread: true, important: true }, { id: '2', from: 'sarah@dev.com', subject: 'API Documentation Updated', snippet: 'The REST API docs have been updated with the new auth endpoints...', date: new Date().toISOString(), unread: true, important: false } ]; } } export class SlackConnector { private mcpInvoke?: (tool: string, args: any) => Promise; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { if (mcpInvoke) { this.mcpInvoke = mcpInvoke; } } async getChannelHistory(channel: string, limit: number = 20): Promise { if (!this.mcpInvoke) { return this.getMockMessages(); } try { const response = await this.mcpInvoke('mcp__slack__slack_get_channel_history', { channel, limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Slack connector error:', error); return this.getMockMessages(); } } async searchMessages(query: string, limit: number = 20): Promise { if (!this.mcpInvoke) { return this.getMockMessages(); } try { const response = await this.mcpInvoke('mcp__slack__slack_search_messages', { query, count: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Slack search error:', error); return this.getMockMessages(); } } async getMentions(limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockMessages(); } try { // Search for mentions of the current user const response = await this.mcpInvoke('mcp__slack__slack_search_messages', { query: '@me', count: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Slack mentions error:', error); return this.getMockMessages(); } } private getMockMessages() { return [ { user: 'Alice', text: 'Has anyone reviewed the authentication PR yet?', timestamp: new Date().toISOString(), channel: '#development' }, { user: 'Bob', text: "I'm seeing some issues with the staging deployment. Looking into it.", timestamp: new Date().toISOString(), channel: '#development' } ]; } } export class GoogleDriveConnector { private mcpInvoke?: (tool: string, args: any) => Promise; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { if (mcpInvoke) { this.mcpInvoke = mcpInvoke; } } async getRecentFiles(limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockFiles(); } try { const response = await this.mcpInvoke('mcp__google-drive__drive_list_files', { pageSize: limit, orderBy: 'modifiedTime desc' }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Google Drive connector error:', error); return this.getMockFiles(); } } async searchFiles(query: string, limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockFiles(); } try { const response = await this.mcpInvoke('mcp__google-drive__drive_search_files', { query, pageSize: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Google Drive search error:', error); return this.getMockFiles(); } } private getMockFiles() { return [ { id: '1', name: 'Q4 Budget Planning.xlsx', mimeType: 'application/vnd.google-apps.spreadsheet', modifiedTime: new Date().toISOString() }, { id: '2', name: 'API Documentation.doc', mimeType: 'application/vnd.google-apps.document', modifiedTime: new Date().toISOString() } ]; } } export class JiraConnector { private mcpInvoke?: (tool: string, args: any) => Promise; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { if (mcpInvoke) { this.mcpInvoke = mcpInvoke; } } async getMyIssues(limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockIssues(); } try { const response = await this.mcpInvoke('mcp__jira__jira_search_issues', { jql: 'assignee = currentUser() AND status != Done', max_results: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Jira connector error:', error); return this.getMockIssues(); } } async getSprintIssues(limit: number = 20): Promise { if (!this.mcpInvoke) { return this.getMockIssues(); } try { const response = await this.mcpInvoke('mcp__jira__jira_search_issues', { jql: 'sprint in openSprints()', max_results: limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Jira sprint error:', error); return this.getMockIssues(); } } private getMockIssues() { return [ { key: 'DEV-123', summary: 'Implement authentication system', status: 'In Progress', assignee: 'Ricardo', priority: 'High' }, { key: 'DEV-124', summary: 'Update API documentation', status: 'To Do', assignee: 'Ricardo', priority: 'Medium' } ]; } } export class DiscordConnector { private mcpInvoke?: (tool: string, args: any) => Promise; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { if (mcpInvoke) { this.mcpInvoke = mcpInvoke; } } async getChannelHistory(channel: string, limit: number = 20): Promise { if (!this.mcpInvoke) { return this.getMockDiscordMessages(); } try { const response = await this.mcpInvoke('mcp__discord__discord_get_channel_history', { channel, limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('Discord connector error:', error); return this.getMockDiscordMessages(); } } private getMockDiscordMessages() { return [ { author: 'TechLead', content: 'Great progress on the new feature!', timestamp: new Date().toISOString(), channel: 'development' } ]; } } export class HubSpotConnector { private mcpInvoke?: (tool: string, args: any) => Promise; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { if (mcpInvoke) { this.mcpInvoke = mcpInvoke; } } async getRecentContacts(limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockContacts(); } try { const response = await this.mcpInvoke('mcp__hubspot__hubspot_search_contacts', { limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('HubSpot connector error:', error); return this.getMockContacts(); } } async getTasks(limit: number = 10): Promise { if (!this.mcpInvoke) { return this.getMockTasks(); } try { const response = await this.mcpInvoke('mcp__hubspot__hubspot_search_tasks', { limit }); return response.content[0]?.data || response.content[0]?.text; } catch (error) { console.error('HubSpot tasks error:', error); return this.getMockTasks(); } } private getMockContacts() { return [ { id: '1', firstname: 'John', lastname: 'Doe', email: 'john@example.com', company: 'Tech Corp' } ]; } private getMockTasks() { return [ { id: '1', subject: 'Follow up with client', status: 'NOT_STARTED', priority: 'HIGH', due_date: new Date().toISOString() } ]; } } /** * Unified connector manager */ export class ServiceConnectorManager { public gmail: GmailConnector; public slack: SlackConnector; public googleDrive: GoogleDriveConnector; public jira: JiraConnector; public discord: DiscordConnector; public hubspot: HubSpotConnector; constructor(mcpInvoke?: (tool: string, args: any) => Promise) { this.gmail = new GmailConnector(mcpInvoke); this.slack = new SlackConnector(mcpInvoke); this.googleDrive = new GoogleDriveConnector(mcpInvoke); this.jira = new JiraConnector(mcpInvoke); this.discord = new DiscordConnector(mcpInvoke); this.hubspot = new HubSpotConnector(mcpInvoke); } }