get-entries
Retrieve content entries from Contentful CMS by specifying a content type to access structured data for your projects.
Instructions
Get entries for a specific content type
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contentType | Yes |
Implementation Reference
- src/index.ts:84-120 (handler)The handler function for the 'get-entries' tool. It takes a contentType parameter, constructs the Contentful API endpoint to fetch entries (limited to 10), fetches the data, and returns it as JSON-formatted text or an error message.async (parameters) => { const { contentType } = parameters; const entriesEndpoint = `https://cdn.contentful.com/spaces/${CONTENTFUL_SPACE_ID}/environments/${CONTENTFUL_ENVIRONMENT}/entries?content_type=${contentType}&limit=10`; try { const response = await fetch(entriesEndpoint, { headers: { Authorization: `Bearer ${CONTENTFUL_ACCESS_TOKEN}`, }, }); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (error: any) { console.error("Error fetching entries:", error); return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } }
- src/index.ts:81-83 (schema)Input schema for the 'get-entries' tool, defining 'contentType' as a required string parameter using Zod.{ contentType: z.string(), },
- src/index.ts:78-121 (registration)Registration of the 'get-entries' tool on the MCP server, specifying name, description, input schema, and handler function.server.tool( "get-entries", "Get entries for a specific content type", { contentType: z.string(), }, async (parameters) => { const { contentType } = parameters; const entriesEndpoint = `https://cdn.contentful.com/spaces/${CONTENTFUL_SPACE_ID}/environments/${CONTENTFUL_ENVIRONMENT}/entries?content_type=${contentType}&limit=10`; try { const response = await fetch(entriesEndpoint, { headers: { Authorization: `Bearer ${CONTENTFUL_ACCESS_TOKEN}`, }, }); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } const data = await response.json(); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), }, ], }; } catch (error: any) { console.error("Error fetching entries:", error); return { content: [ { type: "text", text: `Error: ${error.message}`, }, ], }; } } );