Class: Mewmew::McpIntegration

Inherits:
Object
  • Object
show all
Defined in:
lib/mewmew/mcp_integration.rb

Overview

Integrates Thor CLI with MCP server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thor_class, **server_options) ⇒ McpIntegration

Returns a new instance of McpIntegration.



15
16
17
18
# File 'lib/mewmew/mcp_integration.rb', line 15

def initialize(thor_class, **server_options)
  @thor_class = thor_class
  @server_options = server_options
end

Instance Attribute Details

#server_optionsObject (readonly)

Returns the value of attribute server_options.



13
14
15
# File 'lib/mewmew/mcp_integration.rb', line 13

def server_options
  @server_options
end

#thor_classObject (readonly)

Returns the value of attribute thor_class.



13
14
15
# File 'lib/mewmew/mcp_integration.rb', line 13

def thor_class
  @thor_class
end

Instance Method Details

#create_serverObject

Create an MCP server with Thor tools



38
39
40
41
42
43
44
45
46
47
# File 'lib/mewmew/mcp_integration.rb', line 38

def create_server
  tools = ThorIntrospector.new(thor_class).to_mcp_tools

  MCP::Server.new(
    name: server_name,
    version: server_version,
    tools: tools,
    **server_options
  )
end

#serveObject

Start the MCP stdio server



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mewmew/mcp_integration.rb', line 21

def serve
  server = create_server
  transport = MCP::Server::Transports::StdioTransport.new(server)

  # Trap signals for graceful shutdown
  %w[INT TERM].each do |signal|
    Signal.trap(signal) do
      warn "\nShutting down MCP server..."
      transport.close
      exit(0)
    end
  end

  transport.open
end