Class: Gdrive::MCPServer

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities/gdrive/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
# File 'lib/utilities/gdrive/mcp.rb', line 10

def initialize
  @tools = {
    "test_connection" => {
      name: "test_connection",
      description: "Test the Google Drive API connection",
      inputSchema: {
        type: "object",
        properties: {},
        required: []
      }
    },
    "search_files" => {
      name: "search_files",
      description: "Search for files in Google Drive by content or name",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query to find files"
          },
          max_results: {
            type: "number",
            description: "Maximum number of results to return (default: 10)"
          }
        },
        required: ["query"]
      }
    },
    "get_file_content" => {
      name: "get_file_content",
      description: "Get the content of a specific Google Drive file",
      inputSchema: {
        type: "object",
        properties: {
          file_id: {
            type: "string",
            description: "The Google Drive file ID"
          }
        },
        required: ["file_id"]
      }
    },
    "list_files" => {
      name: "list_files",
      description: "List recent files in Google Drive",
      inputSchema: {
        type: "object",
        properties: {
          max_results: {
            type: "number",
            description: "Maximum number of files to return (default: 20)"
          }
        },
        required: []
      }
    }
  }
end

Instance Method Details

#runObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/utilities/gdrive/mcp.rb', line 70

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("gdrive", "startup"), "#{Time.now}: Google Drive 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("gdrive", "error"), "#{Time.now}: #{e.message}\n#{e.backtrace.join("\n")}\n", mode: "a")
end