add_comment
Submit comments to Emlog blog articles, including the commenter’s name, email, website, and reply context, for enhanced engagement and discussion.
Instructions
Add a comment to an article
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| commail | No | Email of the commenter | |
| comment | Yes | The comment content | |
| comname | Yes | Name of the commenter | |
| comurl | No | Website URL of the commenter | |
| gid | Yes | The ID of the article to comment on | |
| pid | No | Parent comment ID for replies |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"commail": {
"description": "Email of the commenter",
"type": "string"
},
"comment": {
"description": "The comment content",
"type": "string"
},
"comname": {
"description": "Name of the commenter",
"type": "string"
},
"comurl": {
"description": "Website URL of the commenter",
"type": "string"
},
"gid": {
"description": "The ID of the article to comment on",
"type": "number"
},
"pid": {
"description": "Parent comment ID for replies",
"type": "number"
}
},
"required": [
"gid",
"comname",
"comment"
],
"type": "object"
}
Implementation Reference
- src/index.ts:403-428 (handler)The MCP tool handler function for 'add_comment' that validates input, calls the EmlogClient.addComment method, and returns success or error response.async ({ gid, comname, comment, commail, comurl, pid }) => { try { await emlogClient.addComment({ gid, comname, comment, commail, comurl, pid }); return { content: [{ type: "text", text: `Successfully added comment to article ${gid} by ${comname}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/index.ts:394-401 (schema)Zod input schema defining parameters for the add_comment tool: article ID, commenter name, comment text, optional email, URL, and parent comment ID.inputSchema: { gid: z.number().describe("The ID of the article to comment on"), comname: z.string().describe("Name of the commenter"), comment: z.string().describe("The comment content"), commail: z.string().optional().describe("Email of the commenter"), comurl: z.string().optional().describe("Website URL of the commenter"), pid: z.number().optional().describe("Parent comment ID for replies") }
- src/index.ts:389-429 (registration)Registration of the 'add_comment' tool using McpServer.registerTool, including title, description, input schema, and handler function.server.registerTool( "add_comment", { title: "Add Comment", description: "Add a comment to an article", inputSchema: { gid: z.number().describe("The ID of the article to comment on"), comname: z.string().describe("Name of the commenter"), comment: z.string().describe("The comment content"), commail: z.string().optional().describe("Email of the commenter"), comurl: z.string().optional().describe("Website URL of the commenter"), pid: z.number().optional().describe("Parent comment ID for replies") } }, async ({ gid, comname, comment, commail, comurl, pid }) => { try { await emlogClient.addComment({ gid, comname, comment, commail, comurl, pid }); return { content: [{ type: "text", text: `Successfully added comment to article ${gid} by ${comname}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
- src/emlog-client.ts:361-374 (helper)EmlogClient helper method that performs the actual HTTP POST to add a comment via the Emlog API endpoint.async addComment(comment: { gid: number; comname: string; comment: string; commail?: string; comurl?: string; avatar?: string; imgcode?: string; pid?: number; }): Promise<{ cid: number }> { const formData = this.buildFormData({ ...comment, resp: 'json' }); const response = await this.api.post('/index.php?action=addcom', formData); return response.data.data; }