MCPcopy Index your code
hub / github.com/modelcontextprotocol/registry / ListServers

Method ListServers

internal/database/postgres.go:176–273  ·  view source on GitHub ↗
(
	ctx context.Context,
	tx pgx.Tx,
	filter *ServerFilter,
	cursor string,
	limit int,
)

Source from the content-addressed store, hash-verified

174}
175
176func (db *PostgreSQL) ListServers(
177 ctx context.Context,
178 tx pgx.Tx,
179 filter *ServerFilter,
180 cursor string,
181 limit int,
182) ([]*apiv0.ServerResponse, string, error) {
183 if limit <= 0 {
184 limit = 10
185 }
186
187 if ctx.Err() != nil {
188 return nil, "", ctx.Err()
189 }
190
191 // Build WHERE clause conditions
192 argIndex := 1
193 whereConditions, args, argIndex := buildFilterConditions(filter, argIndex)
194
195 // Add cursor pagination
196 cursorCondition, cursorArgs, argIndex := addCursorCondition(cursor, argIndex)
197 if cursorCondition != "" {
198 whereConditions = append(whereConditions, cursorCondition)
199 args = append(args, cursorArgs...)
200 }
201
202 // Build the WHERE clause
203 whereClause := ""
204 if len(whereConditions) > 0 {
205 whereClause = "WHERE " + strings.Join(whereConditions, " AND ")
206 }
207
208 // Query servers table with hybrid column/JSON data
209 query := fmt.Sprintf(`
210 SELECT server_name, version, status, status_changed_at, status_message, published_at, updated_at, is_latest, value
211 FROM servers
212 %s
213 ORDER BY server_name, version
214 LIMIT $%d
215 `, whereClause, argIndex)
216 args = append(args, limit)
217
218 rows, err := db.getExecutor(tx).Query(ctx, query, args...)
219 if err != nil {
220 return nil, "", fmt.Errorf("failed to query servers: %w", err)
221 }
222 defer rows.Close()
223
224 var results []*apiv0.ServerResponse
225 for rows.Next() {
226 var serverName, version, status string
227 var statusChangedAt, publishedAt, updatedAt time.Time
228 var statusMessage *string
229 var isLatest bool
230 var valueJSON []byte
231
232 err := rows.Scan(&serverName, &version, &status, &statusChangedAt, &statusMessage, &publishedAt, &updatedAt, &isLatest, &valueJSON)
233 if err != nil {

Callers

nothing calls this directly

Calls 6

getExecutorMethod · 0.95
StatusTypeAlias · 0.92
buildFilterConditionsFunction · 0.85
addCursorConditionFunction · 0.85
QueryMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected