Class: BundleUp::MCPClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bundleup/mcp.rb,
lib/bundleup/mcp_client.rb

Overview

A connected MCP session.

Tools, resources and prompts are defined by the provider — BundleUp does not rename or normalize them.

Constant Summary collapse

PROTOCOL_VERSION =
'2025-06-18'
CLIENT_NAME =
'bundleup-sdk'

Instance Method Summary collapse

Constructor Details

#initialize(base_url, api_key, connection_id) ⇒ MCPClient

Returns a new instance of MCPClient.



79
80
81
82
83
84
85
86
# File 'lib/bundleup/mcp.rb', line 79

def initialize(base_url, api_key, connection_id)
  @base_url = base_url
  @api_key = api_key
  @connection_id = connection_id
  @session_id = nil
  @connected = false
  @last_id = 0
end

Instance Method Details

#call_tool(name, args = {}) ⇒ Object

Call a tool by name, with arguments matching its own input schema.

Raises:

  • (ArgumentError)


94
95
96
97
98
99
# File 'lib/bundleup/mcp.rb', line 94

def call_tool(name, args = {})
  raise ArgumentError, 'Tool name is required to call a tool.' if blank?(name)

  connect
  send_message('tools/call', { name: name, arguments: args })
end

#closeObject

End the session and reset local state.



136
137
138
139
140
141
142
# File 'lib/bundleup/mcp.rb', line 136

def close
  delete_session if @session_id

  @session_id = nil
  @connected = false
  nil
end

#get_prompt(name, args = {}) ⇒ Object

Get a prompt by name.

Raises:

  • (ArgumentError)


120
121
122
123
124
125
# File 'lib/bundleup/mcp.rb', line 120

def get_prompt(name, args = {})
  raise ArgumentError, 'Prompt name is required to get a prompt.' if blank?(name)

  connect
  send_message('prompts/get', { name: name, arguments: args })
end

#list_promptsObject

List the provider's prompts, following pagination to the end.



115
116
117
# File 'lib/bundleup/mcp.rb', line 115

def list_prompts
  paginate('prompts/list', 'prompts')
end

#list_resourcesObject

List the provider's resources, following pagination to the end.



102
103
104
# File 'lib/bundleup/mcp.rb', line 102

def list_resources
  paginate('resources/list', 'resources')
end

#list_toolsObject

List the provider's tools, following pagination to the end.



89
90
91
# File 'lib/bundleup/mcp.rb', line 89

def list_tools
  paginate('tools/list', 'tools')
end

#prompt(name, args = {}) ⇒ Object

Get a prompt by name.

Raises:

  • (ArgumentError)


55
56
57
58
59
60
# File 'lib/bundleup/mcp_client.rb', line 55

def prompt(name, args = {})
  raise ArgumentError, 'Prompt name is required to get a prompt.' if blank?(name)

  connect
  send_message('prompts/get', { name: name, arguments: args })
end

#promptsObject

List the provider's prompts, following pagination to the end.



50
51
52
# File 'lib/bundleup/mcp_client.rb', line 50

def prompts
  paginate('prompts/list', 'prompts')
end

#read_resource(uri) ⇒ Object

Read a resource by URI.

Raises:

  • (ArgumentError)


107
108
109
110
111
112
# File 'lib/bundleup/mcp.rb', line 107

def read_resource(uri)
  raise ArgumentError, 'Resource URI is required to read a resource.' if blank?(uri)

  connect
  send_message('resources/read', { uri: uri })
end

#request(method, params = nil) ⇒ Object

Send any other JSON-RPC method on this session.

Raises:

  • (ArgumentError)


128
129
130
131
132
133
# File 'lib/bundleup/mcp.rb', line 128

def request(method, params = nil)
  raise ArgumentError, 'Method is required to send a request.' if blank?(method)

  connect
  send_message(method, params)
end

#resource(uri) ⇒ Object

Read a resource by URI.

Raises:

  • (ArgumentError)


42
43
44
45
46
47
# File 'lib/bundleup/mcp_client.rb', line 42

def resource(uri)
  raise ArgumentError, 'Resource URI is required to read a resource.' if blank?(uri)

  connect
  send_message('resources/read', { uri: uri })
end

#resourcesObject

List the provider's resources, following pagination to the end.



37
38
39
# File 'lib/bundleup/mcp_client.rb', line 37

def resources
  paginate('resources/list', 'resources')
end

#tool(name, args = {}) ⇒ Object

Call a tool by name, with arguments matching its own input schema.

Raises:

  • (ArgumentError)


29
30
31
32
33
34
# File 'lib/bundleup/mcp_client.rb', line 29

def tool(name, args = {})
  raise ArgumentError, 'Tool name is required to call a tool.' if blank?(name)

  connect
  send_message('tools/call', { name: name, arguments: args })
end

#toolsObject

List the provider's tools, following pagination to the end.



24
25
26
# File 'lib/bundleup/mcp_client.rb', line 24

def tools
  paginate('tools/list', 'tools')
end