Enough to use
This commit is contained in:
parent
96ae3b2198
commit
60279f0b4e
@ -4,6 +4,7 @@ require_relative "mcp/version"
|
||||
|
||||
module Mcp
|
||||
class Error < StandardError; end
|
||||
class ClientDisconnectedError < Error; end
|
||||
|
||||
class Client
|
||||
def tools
|
||||
@ -20,11 +21,10 @@ module Mcp
|
||||
private
|
||||
|
||||
def respond_to_missing?(name, include_private = false)
|
||||
@tools.any? { |tool| tool["name"] == name.to_s } || super
|
||||
end
|
||||
|
||||
def method_missing(name, **kwargs)
|
||||
@client.call_tool(name, **kwargs)
|
||||
@client.call_tool(name.to_s, kwargs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,13 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Mcp do
|
||||
it "has a version number" do
|
||||
expect(distance([1, 1], [1, 2])).to eq(1)
|
||||
it "can list tools" do
|
||||
client = Mcp::Client.new("/Users/joshuacoles/.local/bin/mcp-server-fetch", [])
|
||||
expect(client.list_tools).to_not be_nil
|
||||
end
|
||||
|
||||
it "does something useful" do
|
||||
a = Mcp::Client.new("/Users/joshuacoles/.local/bin/mcp-server-fetch", [])
|
||||
puts a.list_tools
|
||||
puts a.tools.fetch(url: 'http://example.com')
|
||||
it 'can call tools' do
|
||||
client = Mcp::Client.new("/Users/joshuacoles/.local/bin/mcp-server-fetch", [])
|
||||
result = client.tools.fetch(url: 'http://example.com')
|
||||
|
||||
expect(result).to be_a(Hash)
|
||||
expect(result['content'][0]).to be_a(Hash)
|
||||
expect(result['content'][0]['text']).to include('Contents of http://example.com/')
|
||||
end
|
||||
|
||||
it 'handles calls after disconnect' do
|
||||
client = Mcp::Client.new("/Users/joshuacoles/.local/bin/mcp-server-fetch", [])
|
||||
client.disconnect
|
||||
|
||||
expect { client.tools.fetch(url: 'http://example.com') }.to raise_error(Mcp::ClientDisconnectedError)
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user