Class: ActiveMcp::Server
- Inherits:
-
Object
show all
- Defined in:
- lib/active_mcp/server.rb,
lib/active_mcp/server/fetcher.rb,
lib/active_mcp/server/protocol_handler.rb
Defined Under Namespace
Classes: Fetcher, Logger, ProtocolHandler
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(version: "1.0.0", name: "ActiveMcp", uri: nil, auth: nil) ⇒ Server
Returns a new instance of Server.
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/active_mcp/server.rb', line 40
def initialize(
version: "1.0.0",
name: "ActiveMcp",
uri: nil,
auth: nil
)
@name = name
@version = version
@uri = uri
@fetcher = Fetcher.new(base_uri: uri, auth:)
@protocol_handler = ProtocolHandler.new(self)
end
|
Instance Attribute Details
#fetcher ⇒ Object
Returns the value of attribute fetcher.
38
39
40
|
# File 'lib/active_mcp/server.rb', line 38
def fetcher
@fetcher
end
|
#name ⇒ Object
Returns the value of attribute name.
38
39
40
|
# File 'lib/active_mcp/server.rb', line 38
def name
@name
end
|
#protocol_handler ⇒ Object
Returns the value of attribute protocol_handler.
38
39
40
|
# File 'lib/active_mcp/server.rb', line 38
def protocol_handler
@protocol_handler
end
|
#uri ⇒ Object
Returns the value of attribute uri.
38
39
40
|
# File 'lib/active_mcp/server.rb', line 38
def uri
@uri
end
|
#version ⇒ Object
Returns the value of attribute version.
38
39
40
|
# File 'lib/active_mcp/server.rb', line 38
def version
@version
end
|
Class Method Details
.log_error(message, error) ⇒ Object
33
34
35
|
# File 'lib/active_mcp/server.rb', line 33
def log_error(message, error)
logger.log(message, error)
end
|
.logger ⇒ Object
29
30
31
|
# File 'lib/active_mcp/server.rb', line 29
def logger
@logger ||= Logger.new
end
|
Instance Method Details
#fetch(params:) ⇒ Object
53
54
55
|
# File 'lib/active_mcp/server.rb', line 53
def fetch(params:)
@fetcher.call(params:)
end
|
#initialized ⇒ Object
77
78
79
|
# File 'lib/active_mcp/server.rb', line 77
def initialized
@protocol_handler.initialized
end
|
#serve(connection) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/active_mcp/server.rb', line 65
def serve(connection)
loop do
message = connection.read_next_message
break if message.nil?
response = @protocol_handler.process_message(message)
next if response.nil?
connection.send_message(response)
end
end
|
#serve_stdio ⇒ Object
61
62
63
|
# File 'lib/active_mcp/server.rb', line 61
def serve_stdio
serve(StdioConnection.new)
end
|
#start ⇒ Object
57
58
59
|
# File 'lib/active_mcp/server.rb', line 57
def start
serve_stdio
end
|
81
82
83
|
# File 'lib/active_mcp/server.rb', line 81
def tools
@tool_manager.tools
end
|