Class: AgentHarness::McpServer
- Inherits:
-
Object
- Object
- AgentHarness::McpServer
- Defined in:
- lib/agent_harness/mcp_server.rb
Overview
Canonical representation of an MCP server for request-time execution.
Provider-agnostic value object that can be translated by each provider adapter into its CLI-specific configuration.
Constant Summary collapse
- VALID_TRANSPORTS =
%w[stdio http sse].freeze
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.from_hash(hash) ⇒ McpServer
Build from a plain Hash (e.g. from user input or serialized config).
Instance Method Summary collapse
- #http? ⇒ Boolean
-
#initialize(name:, transport:, command: nil, args: nil, env: nil, url: nil) ⇒ McpServer
constructor
A new instance of McpServer.
- #stdio? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(name:, transport:, command: nil, args: nil, env: nil, url: nil) ⇒ McpServer
Returns a new instance of McpServer.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/agent_harness/mcp_server.rb', line 34 def initialize(name:, transport:, command: nil, args: nil, env: nil, url: nil) @name = name @transport = transport.to_s @command = command @args = args || [] @env = env || {} @url = url validate! end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
26 27 28 |
# File 'lib/agent_harness/mcp_server.rb', line 26 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
26 27 28 |
# File 'lib/agent_harness/mcp_server.rb', line 26 def command @command end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
26 27 28 |
# File 'lib/agent_harness/mcp_server.rb', line 26 def env @env end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/agent_harness/mcp_server.rb', line 26 def name @name end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
26 27 28 |
# File 'lib/agent_harness/mcp_server.rb', line 26 def transport @transport end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
26 27 28 |
# File 'lib/agent_harness/mcp_server.rb', line 26 def url @url end |
Class Method Details
.from_hash(hash) ⇒ McpServer
Build from a plain Hash (e.g. from user input or serialized config)
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/agent_harness/mcp_server.rb', line 49 def self.from_hash(hash) unless hash.is_a?(Hash) raise McpConfigurationError, "MCP server definition must be a Hash, got #{hash.class}" end begin hash = hash.transform_keys(&:to_sym) rescue NoMethodError, TypeError => e raise McpConfigurationError, "MCP server hash contains invalid keys: #{e.}" end new( name: hash[:name], transport: hash[:transport], command: hash[:command], args: hash[:args], env: hash[:env], url: hash[:url] ) end |
Instance Method Details
#http? ⇒ Boolean
74 75 76 |
# File 'lib/agent_harness/mcp_server.rb', line 74 def http? %w[http sse].include?(@transport) end |
#stdio? ⇒ Boolean
70 71 72 |
# File 'lib/agent_harness/mcp_server.rb', line 70 def stdio? @transport == "stdio" end |
#to_h ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/agent_harness/mcp_server.rb', line 78 def to_h h = {name: @name, transport: @transport} if stdio? h[:command] = @command h[:args] = @args unless @args.empty? else h[:url] = @url end h[:env] = @env unless @env.empty? h end |