writing_feedback
Analyze writing for clarity, grammar, style, and structure to improve essays, articles, and technical documentation with actionable feedback.
Instructions
Provides feedback on a piece of writing, such as an essay, article, or technical documentation, focusing on clarity, grammar, style, structure, and overall effectiveness.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The text to review | |
| writing_type | Yes | The type of writing (e.g., 'essay', 'article', 'documentation') |
Implementation Reference
- The main handler function that executes the tool logic: checks rate limits, validates and sanitizes inputs, constructs a specialized prompt using type-specific guidance, calls the Deepseek API, and formats the response or handles errors.export async function handler(args: unknown): Promise<ToolResponse> { // Check rate limit first if (!checkRateLimit()) { return { content: [ { type: 'text', text: 'Rate limit exceeded. Please try again later.', }, ], isError: true, }; } // Validate arguments if (!args || typeof args !== 'object') { return { content: [ { type: 'text', text: 'Invalid arguments provided.', }, ], isError: true, }; } try { // Type guard for WritingFeedbackArgs if (!('text' in args) || !('writing_type' in args) || typeof args.text !== 'string' || typeof args.writing_type !== 'string') { return { content: [ { type: 'text', text: 'Both text and writing_type are required and must be strings.', }, ], isError: true, }; } const typedArgs = args as WritingFeedbackArgs; // Sanitize inputs const sanitizedText = sanitizeInput(typedArgs.text); const sanitizedType = sanitizeInput(typedArgs.writing_type.toLowerCase()); // Get type-specific prompts const typePrompts = WRITING_TYPE_PROMPTS[sanitizedType] || WRITING_TYPE_PROMPTS.default; // Create the complete prompt const prompt = createPrompt( { ...BASE_PROMPT_TEMPLATE, template: BASE_PROMPT_TEMPLATE.template.replace( '{type_specific_prompts}', typePrompts ), }, { writing_type: sanitizedType, text: sanitizedText, } ); // Make the API call const response = await makeDeepseekAPICall(prompt, SYSTEM_PROMPT); if (response.isError) { return { content: [ { type: 'text', text: `Error generating writing feedback: ${response.errorMessage || 'Unknown error'}`, }, ], isError: true, }; } // Return the formatted response return { content: [ { type: 'text', text: response.text, }, ], }; } catch (error) { console.error('Writing feedback tool error:', error); return { content: [ { type: 'text', text: `Error processing writing feedback: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], isError: true, }; } }
- ToolDefinition object including the inputSchema that defines the expected parameters (text and writing_type) for the writing_feedback tool.export const definition: ToolDefinition = { name: 'writing_feedback', description: 'Provides feedback on a piece of writing, such as an essay, article, or technical documentation, focusing on clarity, grammar, style, structure, and overall effectiveness.', inputSchema: { type: 'object', properties: { text: { type: 'string', description: 'The text to review', }, writing_type: { type: 'string', description: "The type of writing (e.g., 'essay', 'article', 'documentation')", }, }, required: ['text', 'writing_type'], }, };
- src/server.ts:56-64 (registration)Registration of the writing_feedback tool by including its definition in the list returned for ListToolsRequest, making it discoverable by clients.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ secondOpinion.definition, codeReview.definition, designCritique.definition, writingFeedback.definition, brainstormEnhancements.definition, ], }));
- src/server.ts:114-122 (registration)Dispatch logic in CallToolRequest handler that validates args using type guard and invokes the writing_feedback handler.case "writing_feedback": { if (!isWritingFeedbackArgs(args)) { throw new McpError( ErrorCode.InvalidParams, "Invalid parameters for writing feedback" ); } response = await writingFeedback.handler(args); break;
- src/types/index.ts:69-72 (schema)TypeScript interface defining the shape of arguments for the writing_feedback tool.export interface WritingFeedbackArgs { text: string; writing_type: string; }
- src/types/index.ts:105-111 (helper)Type guard function used in server.ts to validate incoming arguments before dispatching to the handler.export function isWritingFeedbackArgs(args: unknown): args is WritingFeedbackArgs { if (!args || typeof args !== 'object') return false; const a = args as Record<string, unknown>; return 'text' in a && 'writing_type' in a && typeof a.text === 'string' && typeof a.writing_type === 'string'; }