get contents
Retrieve content from TabNews API using pagination and sorting strategies to access articles, posts, or discussions.
Instructions
get contents from tabnews api
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | The page number to get | |
| per_page | No | The number of contents per page | |
| strategy | No | The strategy to get the contents |
Implementation Reference
- src/index.ts:31-36 (registration)Registration of the "get contents" tool on the MCP server by calling server.tool() with the tool's properties.server.tool( getContentsTool.name, getContentsTool.description, getContentsTool.parameters, getContentsTool.handler );
- src/tools/status.ts:58-81 (handler)The handler function that executes the "get contents" tool logic: fetches data using getContents API helper, formats as JSON text response, handles errors.handler: async (params: GetContentsParams): Promise<McpResponse> => { try { const result = await getContents({ page: params.page, per_page: params.per_page, strategy: params.strategy, }); const content: McpTextContent = { type: "text", text: `Contents:\n\n${JSON.stringify(result, null, 2)}`, }; return { content: [content], }; } catch (error) { if (error instanceof Error) { throw new Error(`Failed to get contents: ${error.message}`); } else { throw new Error("Failed to get contents"); } } },
- src/tools/status.ts:50-57 (schema)Zod schema defining input parameters for the "get contents" tool: page, per_page, strategy.parameters: { page: z.number().optional().describe("The page number to get"), per_page: z.number().optional().describe("The number of contents per page"), strategy: z .enum(["relevant", "new", "old"]) .optional() .describe("The strategy to get the contents"), },
- src/services/api.ts:22-37 (helper)Helper function getContents that performs the actual API fetch to TabNews /contents endpoint, used by the tool handler.export async function getContents({ page = 1, per_page = 30, strategy = "relevant", }: GetContentsParams = {}): Promise<TabNewsContent[]> { const queryParams = new URLSearchParams({ page: page.toString(), per_page: per_page.toString(), strategy: strategy, }); const response = await fetch(`${TABNEWS_API_URL}/contents?${queryParams}`); const data = await response.json(); return data as TabNewsContent[]; }