Class: MCP::Transport

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

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ Transport

Initialize the transport with the server instance



6
7
8
# File 'lib/mcp/transport.rb', line 6

def initialize(server)
  @server = server
end

Instance Method Details

#closeObject

Close the transport connection

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/mcp/transport.rb', line 21

def close
  raise NotImplementedError, "Subclasses must implement close"
end

#handle_json_request(request) ⇒ Object

Handle a JSON request Returns a response that should be sent back to the client



27
28
29
30
# File 'lib/mcp/transport.rb', line 27

def handle_json_request(request)
  response = @server.handle_json(request)
  send_response(response) if response
end

#handle_request(request) ⇒ Object

Handle an incoming request Returns a response that should be sent back to the client



34
35
36
37
# File 'lib/mcp/transport.rb', line 34

def handle_request(request)
  response = @server.handle(request)
  send_response(response) if response
end

#openObject

Open the transport connection

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/mcp/transport.rb', line 16

def open
  raise NotImplementedError, "Subclasses must implement open"
end

#send_notification(method, params = nil) ⇒ Object

Send a notification to the client Returns true if the notification was sent successfully

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/mcp/transport.rb', line 41

def send_notification(method, params = nil)
  raise NotImplementedError, "Subclasses must implement send_notification"
end

#send_response(response) ⇒ Object

Send a response to the client

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/mcp/transport.rb', line 11

def send_response(response)
  raise NotImplementedError, "Subclasses must implement send_response"
end