Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@missionsquad/mcp-wordpress",
"version": "0.2.3",
"version": "0.2.4",
"description": "A Model Context Protocol server for interacting with WordPress.",
"type": "module",
"main": "./build/server.js",
Expand Down
29 changes: 27 additions & 2 deletions src/tools/acf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,32 @@ type ToolWithZodSchema = Tool & {
export const getAcfSchemaSchema = z
.object({
target: z
.enum(['content', 'term', 'user'])
.preprocess((value) => {
if (typeof value !== 'string') {
return value
}

const normalized = value.trim().toLowerCase()
const aliases: Record<string, string> = {
post: 'content',
posts: 'content',
page: 'content',
pages: 'content',
cpt: 'content',
custom_post_type: 'content',
custom_post: 'content',
taxonomy: 'term',
terms: 'term',
category: 'term',
categories: 'term',
tag: 'term',
tags: 'term',
users: 'user',
}

return aliases[normalized] ?? normalized
}, z.enum(['content', 'term', 'user']))
.default('content')
.describe('Schema target. Use content for posts/pages/CPTs, term for taxonomy terms, and user for users.'),
content_type: z
.preprocess((value) => (typeof value === 'string' && value.trim() === '' ? undefined : value), z.string().default('post'))
Expand All @@ -42,7 +67,7 @@ export const getAcfSchemaSchema = z
.optional()
.describe('Optional target ID. For users, this may also be "me". Omit to inspect the collection schema.'),
})
.strict()
.passthrough()

type GetAcfSchemaParams =
| { target: 'content'; content_type: string; id?: number }
Expand Down
67 changes: 67 additions & 0 deletions test/acf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { describe, expect, it } from 'vitest'
import { getAcfSchemaSchema } from '../src/tools/acf.js'

describe('getAcfSchemaSchema', () => {
it('defaults a target-only content schema request to posts', () => {
const parsed = getAcfSchemaSchema.parse({
target: 'content',
})

expect(parsed).toEqual({
target: 'content',
content_type: 'post',
taxonomy: 'category',
})
})

it('accepts blank optional form fields for a content schema request', () => {
const parsed = getAcfSchemaSchema.parse({
target: 'content',
content_type: 'post',
taxonomy: '',
id: '',
})

expect(parsed).toEqual({
target: 'content',
content_type: 'post',
taxonomy: 'category',
id: undefined,
})
})

it('coerces numeric string ids from form inputs', () => {
const parsed = getAcfSchemaSchema.parse({
target: 'content',
content_type: 'post',
id: '123',
})

expect(parsed.id).toBe(123)
})

it('accepts common target aliases and extra llm-supplied fields', () => {
const parsed = getAcfSchemaSchema.parse({
target: 'posts',
content_type: 'page',
reason: 'inspect ACF fields',
})

expect(parsed).toMatchObject({
target: 'content',
content_type: 'page',
taxonomy: 'category',
reason: 'inspect ACF fields',
})
})

it('defaults an omitted target to content', () => {
const parsed = getAcfSchemaSchema.parse({})

expect(parsed).toMatchObject({
target: 'content',
content_type: 'post',
taxonomy: 'category',
})
})
})
Loading