MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / decodeCursor

Function decodeCursor

mcp/server.go:1556–1569  ·  view source on GitHub ↗

decodeCursor decodes an opaque pagination cursor into the original pageToken struct.

(cursor string)

Source from the content-addressed store, hash-verified

1554
1555// decodeCursor decodes an opaque pagination cursor into the original pageToken struct.
1556func decodeCursor(cursor string) (*pageToken, error) {
1557 decodedBytes, err := base64.URLEncoding.DecodeString(cursor)
1558 if err != nil {
1559 return nil, fmt.Errorf("failed to decode cursor: %w", err)
1560 }
1561
1562 var token pageToken
1563 buf := bytes.NewBuffer(decodedBytes)
1564 decoder := gob.NewDecoder(buf)
1565 if err := decoder.Decode(&token); err != nil {
1566 return nil, fmt.Errorf("failed to decode page token: %w, cursor: %v", err, cursor)
1567 }
1568 return &token, nil
1569}
1570
1571// paginateList is a generic helper that returns a paginated slice of items
1572// from a featureSet. It populates the provided result res with the items

Callers 1

paginateListFunction · 0.85

Calls 1

DecodeMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…