GetMicroCMSContent
Retrieve specific content from microCMS by providing the endpoint and content ID. Use this tool to fetch structured data with optional field selection and reference expansion.
Instructions
Get specific content from MicroCMS by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpoint | Yes | API endpoint (e.g., 'blogs') | |
| contentId | Yes | Content ID to retrieve | |
| fields | No | Comma-separated list of fields to return | |
| depth | No | Depth for expanding references |
Implementation Reference
- src/index.ts:102-139 (handler)The asynchronous handler function that fetches specific content from MicroCMS by ID using the client.get method. It constructs queries for optional fields and depth, stringifies the response as formatted JSON, and returns it as text content. Includes error handling to return an error message if the request fails.async ({ endpoint, contentId, fields, depth }) => { try { const queries: Record<string, any> = {}; if (fields) queries.fields = fields; if (depth) queries.depth = depth; const response = await client.get({ endpoint, contentId, queries, }); // 結果をJSON文字列に変換 const resultJson = JSON.stringify(response, null, 2); return { content: [ { type: "text", text: resultJson } ] }; } catch (error: unknown) { console.error("Error getting MicroCMS content:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to get MicroCMS content: ${errorMessage}` } ] }; } } );
- src/index.ts:96-101 (schema)Zod input schema defining required parameters 'endpoint' and 'contentId', with optional 'fields' and 'depth' for customizing the content retrieval.{ endpoint: z.string().describe("API endpoint (e.g., 'blogs')"), contentId: z.string().describe("Content ID to retrieve"), fields: z.string().optional().describe("Comma-separated list of fields to return"), depth: z.number().optional().describe("Depth for expanding references"), },
- src/index.ts:93-139 (registration)The server.tool registration call that defines the 'GetMicroCMSContent' tool, including its name, description, input schema, and handler function.server.tool( "GetMicroCMSContent", "Get specific content from MicroCMS by ID", { endpoint: z.string().describe("API endpoint (e.g., 'blogs')"), contentId: z.string().describe("Content ID to retrieve"), fields: z.string().optional().describe("Comma-separated list of fields to return"), depth: z.number().optional().describe("Depth for expanding references"), }, async ({ endpoint, contentId, fields, depth }) => { try { const queries: Record<string, any> = {}; if (fields) queries.fields = fields; if (depth) queries.depth = depth; const response = await client.get({ endpoint, contentId, queries, }); // 結果をJSON文字列に変換 const resultJson = JSON.stringify(response, null, 2); return { content: [ { type: "text", text: resultJson } ] }; } catch (error: unknown) { console.error("Error getting MicroCMS content:", error); const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Failed to get MicroCMS content: ${errorMessage}` } ] }; } } );