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



8
9
10
11
# File 'lib/mcp/transport.rb', line 8

def initialize(server)
  @server = server
  server.transport = self
end

Instance Method Details

#closeObject

Close the transport connection

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/mcp/transport.rb', line 24

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



30
31
32
33
# File 'lib/mcp/transport.rb', line 30

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



37
38
39
40
# File 'lib/mcp/transport.rb', line 37

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

#openObject

Open the transport connection

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/mcp/transport.rb', line 19

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)


44
45
46
# File 'lib/mcp/transport.rb', line 44

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

#send_request(method, params = nil) ⇒ Object

Send a JSON-RPC request to the client and wait for a response.

Raises:

  • (NotImplementedError)


49
50
51
# File 'lib/mcp/transport.rb', line 49

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

#send_response(response) ⇒ Object

Send a response to the client

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/mcp/transport.rb', line 14

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