feat(journal): add category show/update API routes and MCP tools

This commit is contained in:
Jakub Zych
2026-11-28 15:05:45 +01:00
parent a047d4284f
commit daa29c8aa8
8 changed files with 580 additions and 58 deletions

40
mcp.go
View File

@@ -15,10 +15,13 @@ var _ pact.HasMCP = (*Plugin)(nil)
// to the MCP user (the routes resolve the backend principal themselves).
const mcpGuard = "backend"
// mcpAccessPosts is the permission every Journal tool and the prompt are
// mcpAccessPosts is the permission every Journal post tool and the prompt are
// listed with (the routes check it, and access_publish, themselves).
const mcpAccessPosts = "golem15.journal.access_posts"
// mcpAccessCategories is the permission for editing Journal categories.
const mcpAccessCategories = "golem15.journal.access_categories"
// mcpListPostsInput is the query of GET /_journal/api/v1/posts.
type mcpListPostsInput struct {
Page int `json:"page,omitempty" query:"page" jsonschema:"the page number, from 1"`
@@ -69,6 +72,21 @@ type mcpDeletePostInput struct {
ID uint `json:"id" path:"id" jsonschema:"the post id"`
}
// mcpShowCategoryInput names one category by slug or id.
type mcpShowCategoryInput struct {
Slug string `json:"slug" path:"slug" jsonschema:"the category slug or numeric id"`
}
// mcpUpdateCategoryInput is PUT /_journal/api/v1/categories/{id}: only the
// fields sent are changed.
type mcpUpdateCategoryInput struct {
ID uint `json:"id" path:"id" jsonschema:"the category id"`
Name *string `json:"name,omitempty" jsonschema:"the category name"`
Slug *string `json:"slug,omitempty" jsonschema:"the URL slug"`
Description *string `json:"description,omitempty" jsonschema:"a short category description; empty clears it"`
Content *string `json:"content,omitempty" jsonschema:"the category page HTML body (sanitized with the Journal policy, H1 converted to H2 while the H1 setting is on); empty clears it"`
}
// mcpManageSettings is the permission of the settings and heading tools.
const mcpManageSettings = "golem15.journal.manage_settings"
@@ -155,6 +173,26 @@ func (p *Plugin) MCP() pact.MCP {
Input: struct{}{},
Permissions: []string{mcpAccessPosts},
},
{
Name: "show_category",
Title: "Show category",
Description: "Shows one Journal category by slug or id, including its description, HTML content, and translations.",
Guard: mcpGuard,
Method: http.MethodGet,
Path: "/_journal/api/v1/categories/{slug}",
Input: mcpShowCategoryInput{},
Permissions: []string{mcpAccessPosts},
},
{
Name: "update_category",
Title: "Update category",
Description: "Changes the fields sent of one Journal category by id (name, slug, description, and sanitized HTML content).",
Guard: mcpGuard,
Method: http.MethodPut,
Path: "/_journal/api/v1/categories/{id}",
Input: mcpUpdateCategoryInput{},
Permissions: []string{mcpAccessCategories},
},
{
Name: "list_tags",
Title: "List tags",