Skip to main content
Glama

post_blog

Publish blog articles to a CMS with structured validation for title, description, content, and slug fields to ensure proper formatting and data integrity.

Instructions

Post a blog article to the CMS API using Zod validation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
author_avatar_urlNoAuthor avatar URL
author_nameNoAuthor name
contentYesContent of the blog post
cover_urlNoCover image URL
descriptionYesDescription of the blog post
localeNoLanguage locale
slugYesURL slug for the blog post
statusNoStatus of the blog post (draft), only draft is supported
titleYesTitle of the blog post

Implementation Reference

  • MCP server tool handler for 'post_blog' that invokes cmsClient.postBlog with user arguments and returns the API response.
    case 'post_blog': { try { // 使用 CMS 客户端发布博客,内置 Zod 验证 const result = await cmsClient.postBlog(request.params.arguments || {}) return { content: [ { type: 'text', text: `Successfully posted blog!\nResponse: ${JSON.stringify(result, null, 2)}`, }, ], } } catch (error) { throw new Error(`Failed to post blog: ${error instanceof Error ? error.message : String(error)}`) } }
  • Input schema definition for the 'post_blog' tool returned by ListToolsRequestHandler.
    { name: 'post_blog', description: 'Post a blog article to the CMS API using Zod validation', inputSchema: { type: 'object', properties: { title: { type: 'string', description: 'Title of the blog post', }, description: { type: 'string', description: 'Description of the blog post', }, content: { type: 'string', description: 'Content of the blog post', }, slug: { type: 'string', description: 'URL slug for the blog post', }, status: { type: 'string', description: 'Status of the blog post (draft), only draft is supported', enum: ['draft'], }, cover_url: { type: 'string', description: 'Cover image URL', }, author_name: { type: 'string', description: 'Author name', }, author_avatar_url: { type: 'string', description: 'Author avatar URL', }, locale: { type: 'string', description: 'Language locale', }, }, required: ['title', 'description', 'content', 'slug'], }, },
  • Core implementation of postBlog method in CMSBlogClient that validates input with Zod, makes POST request to CMS API, and handles responses/errors.
    async postBlog(blogData: Partial<BlogPost>): Promise<BlogApiResponse> { try { // 使用 Zod 验证和标准化数据 const validatedData = BlogPostSchema.parse(blogData) console.log('Posting blog with data:', validatedData) const response = await fetch(`${this.apiUrl}/blog`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(validatedData), }) if (!response.ok) { throw new Error(`HTTP error! status: ${response.status} ${response.statusText}`) } const result = (await response.json()) as BlogApiResponse if (!result.success) { throw new Error(`API error: ${result.errMsg || 'Unknown error'}`) } return result } catch (error) { if (error instanceof z.ZodError) { // 处理验证错误 const errorMessages = error.issues.map((err: any) => `${err.path.join('.')}: ${err.message}`).join(', ') throw new Error(`数据验证失败: ${errorMessages}`) } console.error('Failed to post blog:', error) throw error } }
  • Zod schema used for validating blog post data in the postBlog implementation.
    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'), })

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