@@ -55,44 +55,78 @@ func (db *PostgreSQL) List(
5555 }
5656
5757 // Build WHERE clause for filtering
58+ whereConditions , args , argIndex := db .buildFilterConditions (filter )
59+
60+ return db .executeQuery (ctx , whereConditions , args , argIndex , cursor , limit )
61+ }
62+
63+ // buildFilterConditions builds WHERE conditions for filtering
64+ func (db * PostgreSQL ) buildFilterConditions (filter * ServerFilter ) ([]string , []any , int ) {
5865 var whereConditions []string
5966 args := []any {}
6067 argIndex := 1
6168
62- // Add filters using JSON operators
63- if filter != nil {
64- if filter .Name != nil {
65- whereConditions = append (whereConditions , fmt .Sprintf ("value->>'name' = $%d" , argIndex ))
66- args = append (args , * filter .Name )
67- argIndex ++
68- }
69- if filter .RemoteURL != nil {
70- whereConditions = append (whereConditions , fmt .Sprintf ("EXISTS (SELECT 1 FROM jsonb_array_elements(value->'remotes') AS remote WHERE remote->>'url' = $%d)" , argIndex ))
71- args = append (args , * filter .RemoteURL )
72- argIndex ++
73- }
74- if filter .UpdatedSince != nil {
75- whereConditions = append (whereConditions , fmt .Sprintf ("(value->'_meta'->'io.modelcontextprotocol.registry/official'->>'updated_at')::timestamp > $%d" , argIndex ))
76- args = append (args , * filter .UpdatedSince )
77- argIndex ++
78- }
79- if filter .SubstringName != nil {
80- whereConditions = append (whereConditions , fmt .Sprintf ("value->>'name' ILIKE $%d" , argIndex ))
81- args = append (args , "%" + * filter .SubstringName + "%" )
82- argIndex ++
83- }
84- if filter .Version != nil {
85- whereConditions = append (whereConditions , fmt .Sprintf ("(value->'version_detail'->>'version') = $%d" , argIndex ))
86- args = append (args , * filter .Version )
87- argIndex ++
88- }
89- if filter .IsLatest != nil {
90- whereConditions = append (whereConditions , fmt .Sprintf ("(value->'_meta'->'io.modelcontextprotocol.registry/official'->>'is_latest')::boolean = $%d" , argIndex ))
91- args = append (args , * filter .IsLatest )
92- argIndex ++
93- }
69+ if filter == nil {
70+ return whereConditions , args , argIndex
71+ }
72+
73+ // Basic filters
74+ whereConditions , args , argIndex = db .addBasicFilters (filter , whereConditions , args , argIndex )
75+ // Meta-based filters
76+ whereConditions , args , argIndex = db .addMetaFilters (filter , whereConditions , args , argIndex )
77+ // Search filters
78+ whereConditions , args , argIndex = db .addSearchFilters (filter , whereConditions , args , argIndex )
79+
80+ return whereConditions , args , argIndex
81+ }
82+
83+ // addBasicFilters adds name, remote URL, and version filters
84+ func (db * PostgreSQL ) addBasicFilters (filter * ServerFilter , whereConditions []string , args []any , argIndex int ) ([]string , []any , int ) {
85+ if filter .Name != nil {
86+ whereConditions = append (whereConditions , fmt .Sprintf ("value->>'name' = $%d" , argIndex ))
87+ args = append (args , * filter .Name )
88+ argIndex ++
9489 }
90+ if filter .RemoteURL != nil {
91+ whereConditions = append (whereConditions , fmt .Sprintf ("EXISTS (SELECT 1 FROM jsonb_array_elements(value->'remotes') AS remote WHERE remote->>'url' = $%d)" , argIndex ))
92+ args = append (args , * filter .RemoteURL )
93+ argIndex ++
94+ }
95+ if filter .Version != nil {
96+ whereConditions = append (whereConditions , fmt .Sprintf ("(value->'version_detail'->>'version') = $%d" , argIndex ))
97+ args = append (args , * filter .Version )
98+ argIndex ++
99+ }
100+ return whereConditions , args , argIndex
101+ }
102+
103+ // addMetaFilters adds updated_since and is_latest filters
104+ func (db * PostgreSQL ) addMetaFilters (filter * ServerFilter , whereConditions []string , args []any , argIndex int ) ([]string , []any , int ) {
105+ if filter .UpdatedSince != nil {
106+ whereConditions = append (whereConditions , fmt .Sprintf ("(value->'_meta'->'io.modelcontextprotocol.registry/official'->>'updated_at')::timestamp > $%d" , argIndex ))
107+ args = append (args , * filter .UpdatedSince )
108+ argIndex ++
109+ }
110+ if filter .IsLatest != nil {
111+ whereConditions = append (whereConditions , fmt .Sprintf ("(value->'_meta'->'io.modelcontextprotocol.registry/official'->>'is_latest')::boolean = $%d" , argIndex ))
112+ args = append (args , * filter .IsLatest )
113+ argIndex ++
114+ }
115+ return whereConditions , args , argIndex
116+ }
117+
118+ // addSearchFilters adds substring name search filter
119+ func (db * PostgreSQL ) addSearchFilters (filter * ServerFilter , whereConditions []string , args []any , argIndex int ) ([]string , []any , int ) {
120+ if filter .SubstringName != nil {
121+ whereConditions = append (whereConditions , fmt .Sprintf ("value->>'name' ILIKE $%d" , argIndex ))
122+ args = append (args , "%" + * filter .SubstringName + "%" )
123+ argIndex ++
124+ }
125+ return whereConditions , args , argIndex
126+ }
95127
128+ // executeQuery executes the final query with pagination
129+ func (db * PostgreSQL ) executeQuery (ctx context.Context , whereConditions []string , args []any , argIndex int , cursor string , limit int ) ([]* apiv0.ServerJSON , string , error ) {
96130 // Add cursor pagination using registry metadata ID
97131 if cursor != "" {
98132 if _ , err := uuid .Parse (cursor ); err != nil {
0 commit comments