Skip to main content
Glama

validate_blog

Validate blog post data against a Zod schema to ensure required fields and proper formatting before publishing.

Instructions

Validate blog data using Zod schema without posting

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes
descriptionYes
contentYes
slugYes
statusNo
cover_urlNo
author_nameNo
author_avatar_urlNo
localeNo

Implementation Reference

  • Handler for the 'validate_blog' tool that invokes cmsClient.validateBlogData and formats success/error responses.
    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)}`) } }
  • Zod schema (BlogPostSchema) used for validating the input data structure of the blog post.
    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:186-204 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and input schema matching the Zod schema.
    { 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'], }, },
  • Core validation logic in CMSBlogClient.validateBlogData method using BlogPostSchema.parse, returns structured success/error response.
    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: ['未知验证错误'] } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/La-fe/seo-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server