Create Comment
create_commentAdd comments to any document in your AFFiNE workspace to provide feedback or collaborate.
Instructions
Create a comment on a doc.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| workspaceId | No | ||
| docId | Yes | ||
| docTitle | No | ||
| docMode | No | ||
| content | No | ||
| mentions | No |
Implementation Reference
- src/tools/comments.ts:30-46 (handler)The handler function that executes the create_comment tool logic: builds a GraphQL mutation to create a comment, normalizes input content and docMode, and returns a receipt.
const createCommentHandler = async (parsed: { workspaceId?: string; docId: string; docTitle?: string; docMode?: "Page"|"Edgeless"|"page"|"edgeless"; content: any; mentions?: string[] }) => { const workspaceId = parsed.workspaceId || defaults.workspaceId || parsed.workspaceId; if (!workspaceId) throw new Error("workspaceId required (or set AFFINE_WORKSPACE_ID)"); const mutation = `mutation CreateComment($input: CommentCreateInput!){ createComment(input:$input){ id content createdAt updatedAt resolved } }`; const normalizedDocMode = (parsed.docMode || 'page').toLowerCase() === 'edgeless' ? 'edgeless' : 'page'; const normalizedContent = typeof parsed.content === 'string' ? { text: parsed.content } : parsed.content; const input = { content: normalizedContent, docId: parsed.docId, workspaceId, docTitle: parsed.docTitle || "", docMode: normalizedDocMode, mentions: parsed.mentions }; const data = await gql.request<{ createComment: any }>(mutation, { input }); return receipt("comment.create", { workspaceId, docId: parsed.docId, commentId: data.createComment.id, id: data.createComment.id, ...data.createComment, comment: data.createComment, }); }; - src/tools/comments.ts:52-59 (schema)Input schema for create_comment: accepts optional workspaceId, required docId, optional docTitle, optional docMode (Page/Edgeless/page/edgeless), required content (any type), and optional mentions array.
inputSchema: { workspaceId: z.string().optional(), docId: z.string(), docTitle: z.string().optional(), docMode: z.enum(["Page","Edgeless","page","edgeless"]).optional(), content: z.any(), mentions: z.array(z.string()).optional() } - src/tools/comments.ts:47-62 (registration)Registration of the 'create_comment' tool via server.registerTool, with title 'Create Comment' and description 'Create a comment on a doc.'
server.registerTool( "create_comment", { title: "Create Comment", description: "Create a comment on a doc.", inputSchema: { workspaceId: z.string().optional(), docId: z.string(), docTitle: z.string().optional(), docMode: z.enum(["Page","Edgeless","page","edgeless"]).optional(), content: z.any(), mentions: z.array(z.string()).optional() } }, createCommentHandler as any ); - src/index.ts:181-181 (registration)Top-level registration call that wires registerCommentTools into the MCP server at startup.
registerCommentTools(server, gql, { workspaceId: config.defaultWorkspaceId }); - src/util/mcp.ts:26-32 (helper)The 'receipt' helper function used by the handler to format the response with a kind, ok status, and data payload.
export function receipt(kind: string, data: Record<string, unknown>) { return text({ kind, ok: true, ...data, }); }