fix: expose portable Mastodon hashtag schemas for MCP clients
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
import { mastodonSourceSchema } from "./mastodon-source";
|
||||
|
||||
it.each(["日本語_123", "café", "AB12", " hello_world "])(
|
||||
"accepts Unicode hashtag %s",
|
||||
(target) => {
|
||||
expect(mastodonSourceSchema.parse({ platform: "mastodon", kind: "hashtag", target })).toEqual({
|
||||
platform: "mastodon",
|
||||
kind: "hashtag",
|
||||
target: target.trim(),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["", " ", "#tag", "two words", "tag-name", "😀", "a".repeat(129)])(
|
||||
"rejects invalid hashtag %s",
|
||||
(target) => {
|
||||
expect(
|
||||
mastodonSourceSchema.safeParse({ platform: "mastodon", kind: "hashtag", target }).success,
|
||||
).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it("describes hashtag constraints without requiring Unicode regex support in MCP clients", () => {
|
||||
const schema = z.toJSONSchema(mastodonSourceSchema.options[2].shape.target, { io: "input" });
|
||||
expect(schema).toEqual({
|
||||
$schema: "https://json-schema.org/draft/2020-12/schema",
|
||||
type: "string",
|
||||
minLength: 1,
|
||||
maxLength: 128,
|
||||
description: "Hashtag without #, containing only Unicode letters, numbers, and underscores.",
|
||||
});
|
||||
});
|
||||
@@ -22,8 +22,13 @@ export const mastodonSourceSchema = z.discriminatedUnion("kind", [
|
||||
target: z
|
||||
.string()
|
||||
.trim()
|
||||
.regex(/^[\p{L}\p{N}_]+$/u)
|
||||
.max(128),
|
||||
.min(1)
|
||||
.max(128)
|
||||
// JSON Schema consumers do not all support Unicode property escapes.
|
||||
.refine((value) => /^[\p{L}\p{N}_]+$/u.test(value), {
|
||||
message: "Use only letters, numbers, and underscores in a hashtag.",
|
||||
})
|
||||
.describe("Hashtag without #, containing only Unicode letters, numbers, and underscores."),
|
||||
})
|
||||
.strict(),
|
||||
z
|
||||
|
||||
Reference in New Issue
Block a user