Class: MockServer::MCP::McpMockBuilder
- Inherits:
-
Object
- Object
- MockServer::MCP::McpMockBuilder
- Defined in:
- lib/mockserver/mcp.rb
Instance Method Summary collapse
- #add_prompt(prompt) ⇒ Object private
- #add_resource(resource) ⇒ Object private
- #add_tool(tool) ⇒ Object private
- #apply_to(client) ⇒ Array<Expectation>
-
#build ⇒ Array<Hash>
The ordered list of expectations.
-
#initialize(path = '/mcp') ⇒ McpMockBuilder
constructor
A new instance of McpMockBuilder.
- #with_prompt(name) ⇒ McpPromptBuilder
- #with_prompts_capability ⇒ self
- #with_protocol_version(version) ⇒ self
- #with_resource(uri) ⇒ McpResourceBuilder
- #with_resources_capability ⇒ self
- #with_server_name(name) ⇒ self
- #with_server_version(version) ⇒ self
- #with_tool(name) ⇒ McpToolBuilder
- #with_tools_capability ⇒ self
Constructor Details
#initialize(path = '/mcp') ⇒ McpMockBuilder
Returns a new instance of McpMockBuilder.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/mockserver/mcp.rb', line 90 def initialize(path = '/mcp') @path = path.is_a?(String) ? path : '/mcp' @server_name = 'MockMCPServer' @server_version = '1.0.0' @protocol_version = '2025-03-26' @tools_capability = false @resources_capability = false @prompts_capability = false @tools = [] @resources = [] @prompts = [] end |
Instance Method Details
#add_prompt(prompt) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
167 168 169 170 |
# File 'lib/mockserver/mcp.rb', line 167 def add_prompt(prompt) @prompts << prompt @prompts_capability = true end |
#add_resource(resource) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
161 162 163 164 |
# File 'lib/mockserver/mcp.rb', line 161 def add_resource(resource) @resources << resource @resources_capability = true end |
#add_tool(tool) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
155 156 157 158 |
# File 'lib/mockserver/mcp.rb', line 155 def add_tool(tool) @tools << tool @tools_capability = true end |
#apply_to(client) ⇒ Array<Expectation>
199 200 201 |
# File 'lib/mockserver/mcp.rb', line 199 def apply_to(client) client.upsert(*build.map { |h| RawExpectation.new(h) }) end |
#build ⇒ Array<Hash>
Returns the ordered list of expectations.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/mockserver/mcp.rb', line 173 def build expectations = [ build_initialize_expectation, build_ping_expectation, build_notifications_initialized_expectation ] if @tools_capability || !@tools.empty? expectations << build_tools_list_expectation end @tools.each { |tool| expectations << build_tools_call_expectation(tool) } if @resources_capability || !@resources.empty? expectations << build_resources_list_expectation end @resources.each { |resource| expectations << build_resources_read_expectation(resource) } if @prompts_capability || !@prompts.empty? expectations << build_prompts_list_expectation end @prompts.each { |prompt| expectations << build_prompts_get_expectation(prompt) } expectations end |
#with_prompt(name) ⇒ McpPromptBuilder
150 151 152 |
# File 'lib/mockserver/mcp.rb', line 150 def with_prompt(name) McpPromptBuilder.new(self, name) end |
#with_prompts_capability ⇒ self
134 135 136 137 |
# File 'lib/mockserver/mcp.rb', line 134 def with_prompts_capability @prompts_capability = true self end |
#with_protocol_version(version) ⇒ self
116 117 118 119 |
# File 'lib/mockserver/mcp.rb', line 116 def with_protocol_version(version) @protocol_version = version self end |
#with_resource(uri) ⇒ McpResourceBuilder
145 146 147 |
# File 'lib/mockserver/mcp.rb', line 145 def with_resource(uri) McpResourceBuilder.new(self, uri) end |
#with_resources_capability ⇒ self
128 129 130 131 |
# File 'lib/mockserver/mcp.rb', line 128 def with_resources_capability @resources_capability = true self end |
#with_server_name(name) ⇒ self
104 105 106 107 |
# File 'lib/mockserver/mcp.rb', line 104 def with_server_name(name) @server_name = name self end |
#with_server_version(version) ⇒ self
110 111 112 113 |
# File 'lib/mockserver/mcp.rb', line 110 def with_server_version(version) @server_version = version self end |
#with_tool(name) ⇒ McpToolBuilder
140 141 142 |
# File 'lib/mockserver/mcp.rb', line 140 def with_tool(name) McpToolBuilder.new(self, name) end |
#with_tools_capability ⇒ self
122 123 124 125 |
# File 'lib/mockserver/mcp.rb', line 122 def with_tools_capability @tools_capability = true self end |