Skip to main content
Glama
searchEntries.ts1.95 kB
import { z } from 'zod'; import { createSuccessResponse, withErrorHandling, } from '../../utils/response.js'; import { BaseToolSchema, createToolClient } from '../../utils/tools.js'; import { summarizeData } from '../../utils/summarizer.js'; import type { ContentfulConfig } from '../../config/types.js'; export const SearchEntriesToolParams = BaseToolSchema.extend({ query: z.object({ content_type: z.string().optional().describe('Filter by content type'), include: z .number() .optional() .describe('Include this many levels of linked entries'), select: z .string() .optional() .describe('Comma-separated list of fields to return'), links_to_entry: z .string() .optional() .describe('Find entries that link to the specified entry ID'), limit: z .number() .optional() .describe('Maximum number of entries to return'), skip: z.number().optional().describe('Skip this many entries'), order: z.string().optional().describe('Order entries by this field'), }), }); type Params = z.infer<typeof SearchEntriesToolParams>; export function searchEntriesTool(config: ContentfulConfig) { async function tool(args: Params) { const params = { spaceId: args.spaceId, environmentId: args.environmentId, }; const contentfulClient = createToolClient(config, args); const entries = await contentfulClient.entry.getMany({ ...params, query: { ...args.query, limit: Math.min(args.query.limit || 3, 3), skip: args.query.skip || 0, }, }); const summarized = summarizeData(entries, { maxItems: 3, remainingMessage: 'To see more entries, please ask me to retrieve the next page.', }); return createSuccessResponse('Entries retrieved successfully', { entries: summarized, }); } return withErrorHandling(tool, 'Error searching entries'); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/contentful/contentful-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server