vk_wall_get_comments
Retrieve comments from a VK wall post. Filter by owner, post, sort order, and include likes or thread details.
Instructions
Returns a list of comments on a post on a user wall or community wall.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner_id | No | User ID or community ID. Use a negative value to designate a community ID. | |
| post_id | No | Post ID. | |
| need_likes | No | '1' - to return the 'likes' field, '0' - not to return the 'likes' field (default) | |
| start_comment_id | No | ||
| offset | No | Offset needed to return a specific subset of comments. | |
| count | No | Number of comments to return (maximum 100). | |
| sort | No | Sort order: 'asc' - chronological, 'desc' - reverse chronological | |
| preview_length | No | Number of characters at which to truncate comments when previewed. By default, '90'. Specify '0' if you do not want to truncate comments. | |
| extended | No | ||
| fields | No | ||
| comment_id | No | Comment ID. | |
| thread_items_count | No | Count items in threads. |
Implementation Reference
- src/tool-registry.js:19-24 (registration)Tool registration/construction: maps each VK API method (including 'wall.getComments') to an MCP tool named 'vk_wall_get_comments' via getToolName().
export function buildTools(methods) { return methods.map(method => ({ name: getToolName(method.name), description: cleanDescription(method.description, method.name), inputSchema: buildInputSchema(method.parameters), })); - src/tool-registry.js:27-73 (handler)Handler: the generic handler function that routes 'vk_wall_get_comments' calls to vkClient.call('wall.getComments', ...).
export function buildHandler(methods, vkClient) { const methodMap = new Map(); for (const method of methods) { methodMap.set(getToolName(method.name), method.name); } return async function handler(params) { const { name, arguments: args } = params; if (!methodMap.has(name)) { return { content: [ { type: 'text', text: JSON.stringify({ error: `Unknown tool: ${name}` }, null, 2), }, ], isError: true, }; } const vkMethod = methodMap.get(name); try { const result = await vkClient.call(vkMethod, args || {}); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: JSON.stringify({ error: error.message }, null, 2), }, ], isError: true, }; } }; } - src/tool-registry.js:3-8 (helper)Helper: transforms VK API method name 'wall.getComments' into tool name 'vk_wall_get_comments'.
function getToolName(methodName) { return `vk_${methodName .replace(/\./g, '_') .replace(/([a-z0-9])([A-Z])/g, '$1_$2') .toLowerCase()}`; } - src/vk-client.js:1-69 (helper)Helper: VKClient.call() executes the actual VK API request for the 'wall.getComments' method when invoked.
export class VKClient { constructor(accessToken) { this.accessToken = accessToken; this.apiVersion = '5.199'; this.baseUrl = 'https://api.vk.com/method'; } async call(method, params = {}, { timeoutMs = 30000 } = {}) { const normalized = {}; for (const [k, v] of Object.entries(params)) { if (v === undefined || v === null) continue; if (typeof v === 'boolean') { normalized[k] = v ? '1' : '0'; } else if (Array.isArray(v)) { normalized[k] = v.join(','); } else { normalized[k] = String(v); } } const body = new URLSearchParams({ ...normalized, access_token: this.accessToken, v: this.apiVersion, }); const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), timeoutMs); try { const response = await fetch(`${this.baseUrl}/${method}`, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: body.toString(), signal: controller.signal, }); const text = await response.text(); if (!response.ok) { const safeText = text.replace(this.accessToken, '***'); throw new Error(`VK HTTP Error ${response.status}: ${safeText}`); } let data; try { data = JSON.parse(text); } catch { const safeText = text.replace(this.accessToken, '***'); throw new Error(`VK API returned non-JSON response: ${safeText}`); } if (data.error) { const code = data.error.error_code; const msg = data.error.error_msg; throw new Error(`VK API Error ${code}: ${msg}`); } return data.response; } catch (err) { if (err.name === 'AbortError') { throw new Error(`VK API timeout after ${timeoutMs}ms for method ${method}`); } throw err; } finally { clearTimeout(timeout); } } } - src/param-converter.js:70-100 (schema)Schema: buildInputSchema generates the JSON input schema for 'vk_wall_get_comments' from the VK API method's parameter definitions.
export function buildInputSchema(parameters) { if (!parameters || parameters.length === 0) { return { type: 'object', properties: {}, additionalProperties: false, }; } const properties = {}; const required = []; for (const param of parameters) { properties[param.name] = convertParam(param); if (param.required === true) { required.push(param.name); } } const schema = { type: 'object', properties, additionalProperties: false, }; if (required.length > 0) { schema.required = required; } return schema; }