get_posts
Retrieve posts with filters by ID, title, language, or portal, and control pagination with skip and limit parameters.
Instructions
Get a list of posts with optional filtering and pagination.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | No | Filter posts by ID | |
| title | No | Filter posts by title | |
| language | No | Filter posts by language | |
| portal | No | Filter posts by portal | |
| skip | No | Number of posts to skip | |
| limit | No | Maximum number of posts to return |
Implementation Reference
- src/tools/posts.ts:20-40 (handler)The handler function that executes the get_posts tool logic. It calls fetchPosts, validates result.getPosts exists, formats the response as MCP text content, and handles errors.
handler: async (params: PostsParams): Promise<McpResponse> => { try { const result = await fetchPosts(params) if (!result.getPosts) { throw new Error('No results returned from API') } const content: McpTextContent = { type: 'text', text: `Posts Results:\n\n${JSON.stringify(result.getPosts, null, 2)}` } return { content: [content] } } catch (error) { throw new Error(`Failed to fetch posts: ${error.message}`) } } } - src/tools/posts.ts:12-19 (schema)Zod schema defining the get_posts input parameters: id, title, language, portal (optional strings) and skip (default 0), limit (default 10) (optional numbers).
parameters: { id: z.string().optional().describe('Filter posts by ID'), title: z.string().optional().describe('Filter posts by title'), language: z.string().optional().describe('Filter posts by language'), portal: z.string().optional().describe('Filter posts by portal'), skip: z.number().optional().default(0).describe('Number of posts to skip'), limit: z.number().optional().default(10).describe('Maximum number of posts to return') }, - src/types/index.ts:52-59 (schema)TypeScript interface for PostsResponse - defines the shape of the API response including totalCount, retrieved, processedIn, and the posts array with Post fields.
export interface PostsResponse { getPosts: { totalCount: number; retrieved: number; processedIn: number; posts: Post[]; } | null; } - src/types/index.ts:100-107 (schema)TypeScript interface for PostsParams - defines the parameters accepted by the get_posts tool handler.
export interface PostsParams { id?: string; title?: string; language?: string; portal?: string; skip?: number; limit?: number; } - src/index.ts:29-34 (registration)Registration of the getPostsTool on the MCP server via server.tool(), using the tool's name, description, parameters, and handler.
server.tool( getPostsTool.name, getPostsTool.description, getPostsTool.parameters, getPostsTool.handler ) - src/services/api.ts:160-201 (helper)The fetchPosts function - sends a GraphQL query with getPosts field to the API, requesting post data with optional filtering by id, title, language, portal, skip, and limit.
export async function fetchPosts (params: { id?: string; title?: string; language?: string; portal?: string; skip?: number; limit?: number; }): Promise<PostsResponse> { const { id, title, language, portal, skip, limit } = params const languageCode = getLanguageCode(language) return await client.query({ getPosts: { __args: { _id: id, title, language: languageCode, portal, skip, limit }, totalCount: true, retrieved: true, processedIn: true, posts: { _id: true, title: true, abstract: true, type: true, link: true, additionalLinks: true, portal: { link: true, name: true }, tags: true, language: true, date: true } } }) as PostsResponse } - src/config/api.ts:17-20 (helper)Tool configuration defining the name ('get_posts') and description for the posts tool.
posts: { name: 'get_posts', description: 'Get a list of posts with optional filtering and pagination.' },