diff --git a/pkg/remote/remote.go b/pkg/remote/remote.go index 712cc59..d5977d9 100644 --- a/pkg/remote/remote.go +++ b/pkg/remote/remote.go @@ -117,20 +117,44 @@ func (s *Server) Close() error { // --- tools.Server interface --- func (s *Server) ListTools() ([]tools.ToolInfo, error) { - // The remote server has the same tools as what's configured. - // We return a minimal set — the real tool list comes from the - // local execute.Decl during prompt assembly. - return nil, nil + id := s.nextID.Add(1) + req := rpcRequest{ + JSONRPC: "2.0", + ID: id, + Method: "list_tools", + } + + s.mu.Lock() + if err := s.enc.Encode(req); err != nil { + s.mu.Unlock() + return nil, fmt.Errorf("remote list_tools write: %w", err) + } + var resp rpcResponse + if err := s.dec.Decode(&resp); err != nil { + s.mu.Unlock() + return nil, fmt.Errorf("remote list_tools read: %w", err) + } + s.mu.Unlock() + + if resp.Error != nil { + return nil, fmt.Errorf("remote list_tools: %s", resp.Error.Message) + } + + var infos []tools.ToolInfo + if err := json.Unmarshal(resp.Result, &infos); err != nil { + return nil, fmt.Errorf("remote list_tools unmarshal: %w", err) + } + return infos, nil } func (s *Server) CallTool(ctx context.Context, tool string, args json.RawMessage) (json.RawMessage, error) { - // Forward the call as an "execute" RPC + // Forward the call with the tool name as the RPC method. id := s.nextID.Add(1) req := rpcRequest{ JSONRPC: "2.0", ID: id, - Method: "execute", + Method: tool, Params: args, } @@ -151,12 +175,7 @@ func (s *Server) CallTool(ctx context.Context, tool string, args json.RawMessage return nil, fmt.Errorf("remote error: %s", resp.Error.Message) } - // The result is the execute server's JSON output - resultJSON, err := json.Marshal(resp.Result) - if err != nil { - return nil, fmt.Errorf("remote result marshal: %w", err) - } - return resultJSON, nil + return resp.Result, nil } // ping verifies the remote server is responsive.