get_article
Retrieve a specific article by its unique ID within Emlog blog systems, including handling password-protected content.
Instructions
Get a specific article by ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the article to retrieve | |
| password | No | Password for protected articles |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"id": {
"description": "The ID of the article to retrieve",
"type": "number"
},
"password": {
"description": "Password for protected articles",
"type": "string"
}
},
"required": [
"id"
],
"type": "object"
}
Implementation Reference
- src/index.ts:290-308 (handler)The handler function for the "get_article" MCP tool. It fetches the article details using emlogClient and returns formatted text output.async ({ id, password }) => { try { const article = await emlogClient.getArticleDetail(id, password); return { content: [{ type: "text", text: `Article: ${article.title}\n\nContent: ${article.content}\n\nExcerpt: ${article.excerpt || 'N/A'}\nCategory: ${article.sort_id}\nTags: ${article.tags || 'N/A'}\nViews: ${article.views}\nComments: ${article.comnum}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/index.ts:285-288 (schema)Input schema for the get_article tool using Zod validation.inputSchema: { id: z.number().describe("The ID of the article to retrieve"), password: z.string().optional().describe("Password for protected articles") }
- src/index.ts:280-281 (registration)Registration of the "get_article" tool with the MCP server.server.registerTool( "get_article",
- src/emlog-client.ts:240-246 (helper)Helper method in EmlogClient that performs the actual API call to retrieve article details.async getArticleDetail(id: number, password?: string): Promise<EmlogPost> { const params: { id: number; password?: string } = { id }; if (password) params.password = password; const queryParams = this.buildParams(params); const response = await this.api.get(`/?rest-api=article_detail&${queryParams.toString()}`); return response.data.data.article; }
- src/emlog-client.ts:6-35 (schema)TypeScript interface defining the structure of an EmlogPost, used for typing the article data.export interface EmlogPost { id: number; title: string; content: string; content_raw?: string; excerpt?: string; excerpt_raw?: string; description?: string; description_raw?: string; cover?: string; url?: string; author_id: number; author_name: string; author_avatar?: string; sort_id: number; sort_name: string; views: number; comnum: number; like_count: number; date: string; tags: Array<{ name: string; url: string }>; top: 'y' | 'n'; sortop: 'y' | 'n'; need_pwd: 'y' | 'n'; allow_remark?: 'y' | 'n'; password?: string; link?: string; fields?: Record<string, any>; type?: string; }