Skip to main content
Glama

post_blog

Publish blog articles to a CMS API with structured validation for content management and publishing workflows.

Instructions

Post a blog article to the CMS API using Zod validation

Input Schema

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

Implementation Reference

  • The MCP tool handler for 'post_blog' in the CallToolRequestSchema. It invokes cmsClient.postBlog with tool arguments and formats the 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)}`) } }
  • src/index.ts:140-185 (registration)
    Registration of the 'post_blog' tool in ListToolsRequestSchema handler, defining name, description, and input schema.
    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'], }, },
  • Zod schema BlogPostSchema for validating blog post input data, used in the postBlog 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'), })
  • Core helper function postBlog in CMSBlogClient that performs Zod validation, API POST request to CMS, and error handling.
    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 } }

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