Class: BundleUp::MCPClient
- Inherits:
-
Object
- Object
- BundleUp::MCPClient
- 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
-
#call_tool(name, args = {}) ⇒ Object
Call a tool by name, with arguments matching its own input schema.
-
#close ⇒ Object
End the session and reset local state.
-
#get_prompt(name, args = {}) ⇒ Object
Get a prompt by name.
-
#initialize(base_url, api_key, connection_id) ⇒ MCPClient
constructor
A new instance of MCPClient.
-
#list_prompts ⇒ Object
List the provider's prompts, following pagination to the end.
-
#list_resources ⇒ Object
List the provider's resources, following pagination to the end.
-
#list_tools ⇒ Object
List the provider's tools, following pagination to the end.
-
#prompt(name, args = {}) ⇒ Object
Get a prompt by name.
-
#prompts ⇒ Object
List the provider's prompts, following pagination to the end.
-
#read_resource(uri) ⇒ Object
Read a resource by URI.
-
#request(method, params = nil) ⇒ Object
Send any other JSON-RPC method on this session.
-
#resource(uri) ⇒ Object
Read a resource by URI.
-
#resources ⇒ Object
List the provider's resources, following pagination to the end.
-
#tool(name, args = {}) ⇒ Object
Call a tool by name, with arguments matching its own input schema.
-
#tools ⇒ Object
List the provider's tools, following pagination to the end.
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.
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 ('tools/call', { name: name, arguments: args }) end |
#close ⇒ Object
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.
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 ('prompts/get', { name: name, arguments: args }) end |
#list_prompts ⇒ Object
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_resources ⇒ Object
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_tools ⇒ Object
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.
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 ('prompts/get', { name: name, arguments: args }) end |
#prompts ⇒ Object
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.
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 ('resources/read', { uri: uri }) end |
#request(method, params = nil) ⇒ Object
Send any other JSON-RPC method on this session.
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 (method, params) end |
#resource(uri) ⇒ Object
Read a resource by URI.
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 ('resources/read', { uri: uri }) end |
#resources ⇒ Object
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.
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 ('tools/call', { name: name, arguments: args }) end |
#tools ⇒ Object
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 |