feat: add JSON-RPC MCP Call with ToolError
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package client_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"s1d3sw1ped/robinhood-agentic-mcp/client"
|
||||
"s1d3sw1ped/robinhood-agentic-mcp/internal/rhntest"
|
||||
)
|
||||
|
||||
func TestClientCall_rpcRoundTrip(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := rhntest.New(t)
|
||||
s.Token = "tok"
|
||||
s.Set("get_equity_quotes", json.RawMessage(`{"quotes":[{"symbol":"MU"}]}`))
|
||||
c := &client.Client{URL: s.URL, Token: "tok"}
|
||||
raw, err := c.Call(context.Background(), "get_equity_quotes", map[string]any{"symbols": []string{"MU"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if string(raw) != `{"quotes":[{"symbol":"MU"}]}` {
|
||||
t.Fatalf("%s", raw)
|
||||
}
|
||||
if s.LastName() != "get_equity_quotes" {
|
||||
t.Fatal(s.LastName())
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientCall_httpErrorIsToolError(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := rhntest.New(t)
|
||||
s.SetHTTPError(500, "nope")
|
||||
c := &client.Client{URL: s.URL}
|
||||
_, err := c.Call(context.Background(), "get_accounts", map[string]any{})
|
||||
var te *client.ToolError
|
||||
if !errors.As(err, &te) || te.Name != "get_accounts" {
|
||||
t.Fatalf("%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClientCall_hook(t *testing.T) {
|
||||
t.Parallel()
|
||||
c := &client.Client{Hook: client.Func(func(ctx context.Context, name string, args map[string]any) (json.RawMessage, error) {
|
||||
return json.RawMessage(`{"ok":true}`), nil
|
||||
})}
|
||||
raw, err := c.Call(context.Background(), "x", nil)
|
||||
if err != nil || string(raw) != `{"ok":true}` {
|
||||
t.Fatalf("%s %v", raw, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user