Class: Gcal::MCPServer

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities/gcal/mcp.rb

Instance Method Summary collapse

Constructor Details

#initializeMCPServer

Returns a new instance of MCPServer.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/utilities/gcal/mcp.rb', line 10

def initialize
  @prompts = [
    {
      name: "check_schedule",
      description: "Check your calendar schedule for a specific time period",
      arguments: [
        {
          name: "period",
          description: "Time period to check (e.g., 'today', 'tomorrow', 'this week', 'next Monday')",
          required: true
        }
      ]
    },
    {
      name: "find_meeting",
      description: "Find a specific meeting or event by searching for keywords",
      arguments: [
        {
          name: "keywords",
          description: "Keywords to search for in event titles and descriptions",
          required: true
        }
      ]
    },
    {
      name: "check_availability",
      description: "Check if you're free at a specific time",
      arguments: [
        {
          name: "datetime",
          description: "Date and time to check (e.g., 'tomorrow at 2pm', 'next Tuesday afternoon')",
          required: true
        }
      ]
    },
    {
      name: "weekly_overview",
      description: "Get an overview of your schedule for the upcoming week",
      arguments: []
    },
    {
      name: "meeting_conflicts",
      description: "Check for any overlapping or back-to-back meetings",
      arguments: [
        {
          name: "date",
          description: "Date to check for conflicts (default: today)",
          required: false
        }
      ]
    }
  ]

  @tools = {
    "test_connection" => {
      name: "test_connection",
      description: "Test the Google Calendar API connection",
      inputSchema: {
        type: "object",
        properties: {},
        required: []
      }
    },
    "list_events" => {
      name: "list_events",
      description: "List calendar events with optional date filtering",
      inputSchema: {
        type: "object",
        properties: {
          start_date: {
            type: "string",
            description: "Start date in YYYY-MM-DD format (default: today)"
          },
          end_date: {
            type: "string",
            description: "End date in YYYY-MM-DD format (default: 7 days from start)"
          },
          max_results: {
            type: "number",
            description: "Maximum number of events to return (default: 20)"
          },
          calendar_id: {
            type: "string",
            description: "Calendar ID to list events from (default: primary calendar)"
          }
        },
        required: []
      }
    },
    "list_calendars" => {
      name: "list_calendars",
      description: "List available calendars",
      inputSchema: {
        type: "object",
        properties: {},
        required: []
      }
    },
    "search_events" => {
      name: "search_events",
      description: "Search for events by text content",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query to find events"
          },
          start_date: {
            type: "string",
            description: "Start date in YYYY-MM-DD format (default: today)"
          },
          end_date: {
            type: "string",
            description: "End date in YYYY-MM-DD format (default: 30 days from start)"
          },
          max_results: {
            type: "number",
            description: "Maximum number of events to return (default: 10)"
          }
        },
        required: ["query"]
      }
    }
  }
end

Instance Method Details

#runObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/utilities/gcal/mcp.rb', line 137

def run
  # Disable stdout buffering for immediate response
  $stdout.sync = true

  # Log startup to file instead of stdout to avoid protocol interference
  Mcpeasy::Config.ensure_config_dirs
  File.write(Mcpeasy::Config.log_file_path("gcal", "startup"), "#{Time.now}: Google Calendar MCP Server starting on stdio\n", mode: "a")
  while (line = $stdin.gets)
    handle_request(line.strip)
  end
rescue Interrupt
  # Silent shutdown
rescue => e
  # Log to a file instead of stderr to avoid protocol interference
  File.write(Mcpeasy::Config.log_file_path("gcal", "error"), "#{Time.now}: #{e.message}\n#{e.backtrace.join("\n")}\n", mode: "a")
end