Class: MockServer::MCP::McpMockBuilder

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

Instance Method Summary collapse

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>

Returns:



199
200
201
# File 'lib/mockserver/mcp.rb', line 199

def apply_to(client)
  client.upsert(*build.map { |h| RawExpectation.new(h) })
end

#buildArray<Hash>

Returns the ordered list of expectations.

Returns:

  • (Array<Hash>)

    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

Returns:



150
151
152
# File 'lib/mockserver/mcp.rb', line 150

def with_prompt(name)
  McpPromptBuilder.new(self, name)
end

#with_prompts_capabilityself

Returns:

  • (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

Returns:

  • (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

Returns:



145
146
147
# File 'lib/mockserver/mcp.rb', line 145

def with_resource(uri)
  McpResourceBuilder.new(self, uri)
end

#with_resources_capabilityself

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:



140
141
142
# File 'lib/mockserver/mcp.rb', line 140

def with_tool(name)
  McpToolBuilder.new(self, name)
end

#with_tools_capabilityself

Returns:

  • (self)


122
123
124
125
# File 'lib/mockserver/mcp.rb', line 122

def with_tools_capability
  @tools_capability = true
  self
end