html2md_mcp_client 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46468e0870a51991423deb96277081f233006f39f3a265d33d35567c38bd64e9
4
- data.tar.gz: 98c2d87ded5ff1d8b9641ac38f845f5912e622ee045a09930fc9169591f84bb7
3
+ metadata.gz: 76fea9b5c32f480a0ed9372cd6c46b39a56b19de8f88f5932f3459f7a84a141c
4
+ data.tar.gz: '08ec1fefabe058777da56e362b79ca38128b98eb999c571c4e0f4d312cd17cf0'
5
5
  SHA512:
6
- metadata.gz: 040de8322dd8523f6adad126d63c10170e09b242401baf5388b1d2243c6d2ec8895ee9874a959d305445d179243de9fd77f3b98060e20080538c9b01ea473aec
7
- data.tar.gz: 4cf6be14b86eda38382b75f35e17434d628d30dcf1b81425d211002da1e27b03cd08b01e15afa97bdad5e00e368bec6559bad2ef071ef8cdb0eea9d49180d98e
6
+ metadata.gz: 0a58981905888666eacf9ed7c45b33c9144281c60cadb959cdaedbb09f950d548f4b7fbd79cfb759d675f1be65a0fa477387f19bfc7b4f3ff4ffaf230471a698
7
+ data.tar.gz: ca53fb8fbaa31dc818f0fd357cbbe5eae1ecb9f43a2a855314be83ed7465d38afff80e9748da5d7c50d7cc05f75b18be3f2466239ade59d1dea4938f17ab31f0
@@ -61,13 +61,15 @@ module Html2mdMcpClient
61
61
  end
62
62
 
63
63
  # Call a tool. Returns the content array.
64
- # Raises ToolError if the server signals an error.
64
+ # Raises ToolError if the server signals an error or if text content
65
+ # begins with "Error" (some servers omit the isError flag).
65
66
  def call_tool(name, arguments = {})
66
67
  ensure_connected!
67
68
  result = request('tools/call', { name: name, arguments: arguments })
68
69
 
69
- if result['isError']
70
- texts = Array(result['content']).select { |c| c['type'] == 'text' }.map { |c| c['text'] }
70
+ texts = Array(result['content']).select { |c| c['type'] == 'text' }.map { |c| c['text'] }
71
+
72
+ if result['isError'] || texts.any? { |t| t.start_with?('Error') }
71
73
  raise ToolError, "Tool '#{name}' error: #{texts.join('; ')}"
72
74
  end
73
75
 
@@ -75,11 +77,15 @@ module Html2mdMcpClient
75
77
  end
76
78
 
77
79
  # Convenience: call a tool and return joined text content.
80
+ # Raises ToolError if no text content is returned.
78
81
  def tool_text(name, arguments = {})
79
- call_tool(name, arguments)
82
+ texts = call_tool(name, arguments)
80
83
  .select { |c| c['type'] == 'text' }
81
84
  .map { |c| c['text'] }
82
- .join("\n")
85
+
86
+ raise ToolError, "Tool '#{name}' returned no text content" if texts.empty?
87
+
88
+ texts.join("\n")
83
89
  end
84
90
 
85
91
  # Find a tool definition by name. Returns nil if not found.
@@ -1,3 +1,3 @@
1
1
  module Html2mdMcpClient
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
@@ -171,6 +171,17 @@ RSpec.describe Html2mdMcpClient::Client do
171
171
 
172
172
  expect(client.call_tool('empty_tool')).to eq([])
173
173
  end
174
+
175
+ it 'raises ToolError when text content starts with Error even without isError flag' do
176
+ allow(transport).to receive(:send_request)
177
+ .with(hash_including(method: 'tools/call'))
178
+ .and_return(jsonrpc_response(2, {
179
+ 'content' => [{ 'type' => 'text', 'text' => 'Error fetching URL: Connection error while fetching URL: https://bad.invalid' }]
180
+ }))
181
+
182
+ expect { client.call_tool('html_to_markdown', { url: 'https://bad.invalid' }) }
183
+ .to raise_error(Html2mdMcpClient::ToolError, /Error fetching URL/)
184
+ end
174
185
  end
175
186
 
176
187
  describe '#tool_text' do
@@ -189,6 +200,24 @@ RSpec.describe Html2mdMcpClient::Client do
189
200
 
190
201
  expect(client.tool_text('my_tool')).to eq("Line 1\nLine 2")
191
202
  end
203
+
204
+ it 'raises ToolError when no text content is returned' do
205
+ allow(transport).to receive(:send_request)
206
+ .with(hash_including(method: 'tools/call'))
207
+ .and_return(jsonrpc_response(2, {}))
208
+
209
+ expect { client.tool_text('bad_tool') }.to raise_error(Html2mdMcpClient::ToolError, /returned no text content/)
210
+ end
211
+
212
+ it 'raises ToolError when content has no text entries' do
213
+ content = [{ 'type' => 'image', 'data' => 'base64...' }]
214
+
215
+ allow(transport).to receive(:send_request)
216
+ .with(hash_including(method: 'tools/call'))
217
+ .and_return(jsonrpc_response(2, { 'content' => content }))
218
+
219
+ expect { client.tool_text('img_tool') }.to raise_error(Html2mdMcpClient::ToolError, /returned no text content/)
220
+ end
192
221
  end
193
222
 
194
223
  describe '#find_tool' do
@@ -116,6 +116,16 @@ RSpec.describe Html2mdMcpClient::Transport::Http do
116
116
  .to raise_error(Html2mdMcpClient::ConnectionError, /Cannot connect/)
117
117
  end
118
118
 
119
+ it 'raises ConnectionError on unresolvable host' do
120
+ t = described_class.new('http://this-host-does-not-exist.invalid/mcp')
121
+
122
+ stub_request(:post, 'http://this-host-does-not-exist.invalid/mcp')
123
+ .to_raise(SocketError.new('getaddrinfo: Name or service not known'))
124
+
125
+ expect { t.send_request({ jsonrpc: '2.0', id: 1, method: 'test', params: {} }) }
126
+ .to raise_error(Html2mdMcpClient::ConnectionError, /Cannot connect/)
127
+ end
128
+
119
129
  it 'raises ProtocolError on invalid JSON' do
120
130
  stub_request(:post, url).to_return(status: 200, body: 'not json')
121
131
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html2md_mcp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roscommon