validate_blog
Validate blog post data against schema requirements to ensure proper formatting and completeness before publication.
Instructions
Validate blog data using Zod schema without posting
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| author_avatar_url | No | ||
| author_name | No | ||
| content | Yes | ||
| cover_url | No | ||
| description | Yes | ||
| locale | No | ||
| slug | Yes | ||
| status | No | ||
| title | Yes |
Implementation Reference
- src/index.ts:274-301 (handler)Handler for the 'validate_blog' tool call, which invokes cmsClient.validateBlogData and formats the response.case 'validate_blog': { try { // 验证博客数据但不发布 const validation = cmsClient.validateBlogData(request.params.arguments || {}) if (validation.success) { return { content: [ { type: 'text', text: `✅ Blog data validation successful!\nValidated data: ${JSON.stringify(validation.data, null, 2)}`, }, ], } } else { return { content: [ { type: 'text', text: `❌ Blog data validation failed!\nErrors: ${validation.errors?.join(', ')}`, }, ], } } } catch (error) { throw new Error(`Validation error: ${error instanceof Error ? error.message : String(error)}`) } }
- src/cms-blog.ts:11-21 (schema)Zod schema used for validating blog post data in validateBlogData method.export const BlogPostSchema = z.object({ title: z.string().min(1, '标题不能为空'), description: z.string().min(1, '描述不能为空'), content: z.string().min(1, '内容不能为空'), slug: z.string().min(1, 'URL 地址不能为空'), status: z.enum(['draft', 'published']).default('draft'), cover_url: z.url('封面图片 URL 格式不正确').default('https://example.com/cover.jpg'), author_name: z.string().default('Lafe'), author_avatar_url: z.url('作者头像 URL 格式不正确').default('https://example.com/avatar.jpg'), locale: z.string().default('en'), })
- src/index.ts:187-204 (registration)Tool registration in ListToolsRequestSchema handler, including name, description, and inputSchema.name: 'validate_blog', description: 'Validate blog data using Zod schema without posting', inputSchema: { type: 'object', properties: { title: { type: 'string' }, description: { type: 'string' }, content: { type: 'string' }, slug: { type: 'string' }, status: { type: 'string' }, cover_url: { type: 'string' }, author_name: { type: 'string' }, author_avatar_url: { type: 'string' }, locale: { type: 'string' }, }, required: ['title', 'description', 'content', 'slug'], }, },
- src/cms-blog.ts:100-111 (helper)Core validation logic that uses BlogPostSchema to validate input data and returns success/data or errors.validateBlogData(blogData: any): { success: boolean; data?: BlogPost; errors?: string[] } { try { const validatedData = BlogPostSchema.parse(blogData) return { success: true, data: validatedData } } catch (error) { if (error instanceof z.ZodError) { const errors = error.issues.map((err: any) => `${err.path.join('.')}: ${err.message}`) return { success: false, errors } } return { success: false, errors: ['未知验证错误'] } } }