@typeroll/mcp-server 0.45.120 → 0.45.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +17 -0
- package/dist/bundled-content.js +4 -4
- package/dist/client.js +3 -0
- package/dist/rest-reference.js +7 -0
- package/dist/server.js +34 -2
- package/dist/tools/access.js +25 -1
- package/dist/tools/clipboard.js +37 -0
- package/dist/tools/collection.js +73 -0
- package/dist/tools/fonts.js +91 -0
- package/dist/tools/menus.js +251 -0
- package/dist/tools/packages.js +66 -0
- package/dist/tools/reusable-blocks.js +2 -2
- package/dist/tools/settings.js +16 -1
- package/dist/tools/site-fields.js +138 -0
- package/dist/tools/sites.js +27 -3
- package/dist/tools/snippets.js +118 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/tr-brand.md +38 -11
- package/skills/tr-header-footer.md +43 -32
- package/skills/tr-new-site.md +11 -0
package/dist/client.js
CHANGED
|
@@ -125,6 +125,9 @@ export class TyperollClient {
|
|
|
125
125
|
rootPut(path, body) {
|
|
126
126
|
return this.request('PUT', this.rootUrl(path), body);
|
|
127
127
|
}
|
|
128
|
+
rootPatch(path, body) {
|
|
129
|
+
return this.request('PATCH', this.rootUrl(path), body);
|
|
130
|
+
}
|
|
128
131
|
// ── Extension developer API ────────────────────────────────────────────
|
|
129
132
|
/** `/api/developer/{path}` — the Extension developer API used by the
|
|
130
133
|
* `typeroll extension` CLI. Requires an organization-scoped key. */
|
package/dist/rest-reference.js
CHANGED
|
@@ -16,6 +16,13 @@ const EXAMPLE_ARGS = {
|
|
|
16
16
|
import_gsc_performance: { property: 'https://example.com/' },
|
|
17
17
|
update_migration_urls: { ids: ['{id}'], patch: { excluded: true } },
|
|
18
18
|
revoke_preview_link: { preview_url: `${'https://portal.invalid'}/preview/{siteId}/?t={token}` },
|
|
19
|
+
search_fonts: { query: 'grotesk', category: 'sans', variable: true },
|
|
20
|
+
set_site_fonts: { heading: 'Fraunces', body: 'Inter', display: null, load: { body: { weights: [300] } } },
|
|
21
|
+
export_package: { selection: { kind: 'collection', block_templates: ['hero'], styles: 'used' }, meta: { id: 'acme-sections', name: 'Acme sections', version: '1.0.0' } },
|
|
22
|
+
inspect_package: { source_url: 'https://example.com/acme-sections-1.0.0.typeroll', options: { design: 'content' } },
|
|
23
|
+
import_package: { source_url: 'https://example.com/acme-sections-1.0.0.typeroll', options: { design: 'content' } },
|
|
24
|
+
create_site: { name: '{name}', id: '{id}', language: 'en', domain: 'example.com', from_site_id: '{from_site_id}', design: 'full', font_licence_confirmed: true },
|
|
25
|
+
upload_font: { filename: 'BrandSans-Regular.woff2', data_base64: '{data_base64}', licence_confirmed: true, licence_note: 'Web licence, order 1234' },
|
|
19
26
|
};
|
|
20
27
|
const SITE = '{siteId}';
|
|
21
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
package/dist/server.js
CHANGED
|
@@ -13,6 +13,9 @@ import { ownerReviewTools } from './tools/owner-review.js';
|
|
|
13
13
|
import { pageTools } from './tools/pages.js';
|
|
14
14
|
import { structuredDataTools } from './tools/structured-data.js';
|
|
15
15
|
import { partialTools } from './tools/partials.js';
|
|
16
|
+
import { menuTools } from './tools/menus.js';
|
|
17
|
+
import { siteFieldTools } from './tools/site-fields.js';
|
|
18
|
+
import { snippetTools } from './tools/snippets.js';
|
|
16
19
|
import { contentTypeTools } from './tools/content-types.js';
|
|
17
20
|
import { pageTemplateTools } from './tools/page-templates.js';
|
|
18
21
|
import { mediaTools } from './tools/media.js';
|
|
@@ -32,12 +35,16 @@ import { blockTypeTools } from './tools/block-types.js';
|
|
|
32
35
|
import { pageBlockTools } from './tools/page-blocks.js';
|
|
33
36
|
import { workingCopyTools } from './tools/working-copy.js';
|
|
34
37
|
import { settingsTools } from './tools/settings.js';
|
|
38
|
+
import { fontTools } from './tools/fonts.js';
|
|
39
|
+
import { packageTools } from './tools/packages.js';
|
|
35
40
|
import { siteTools } from './tools/sites.js';
|
|
36
41
|
import { domainTools } from './tools/domain.js';
|
|
37
42
|
import { appTools } from './tools/apps.js';
|
|
38
43
|
import { extensionTools, developerExtensionTools } from './tools/extensions.js';
|
|
39
44
|
import { skillTools } from './tools/skills.js';
|
|
40
45
|
import { accessTools } from './tools/access.js';
|
|
46
|
+
import { collectionTools } from './tools/collection.js';
|
|
47
|
+
import { clipboardTools } from './tools/clipboard.js';
|
|
41
48
|
import { workflowTools } from './tools/workflows.js';
|
|
42
49
|
import { fail, ok } from './tools/helpers.js';
|
|
43
50
|
import { VERSION } from './version.js';
|
|
@@ -53,6 +60,9 @@ export const ALL_TOOLS = [
|
|
|
53
60
|
...structuredDataTools,
|
|
54
61
|
...ownerReviewTools,
|
|
55
62
|
...partialTools,
|
|
63
|
+
...menuTools,
|
|
64
|
+
...siteFieldTools,
|
|
65
|
+
...snippetTools,
|
|
56
66
|
...blockTypeTools,
|
|
57
67
|
...pageBlockTools,
|
|
58
68
|
...workingCopyTools,
|
|
@@ -62,10 +72,14 @@ export const ALL_TOOLS = [
|
|
|
62
72
|
...redirectTools,
|
|
63
73
|
...styleTools,
|
|
64
74
|
...reusableBlockTools,
|
|
75
|
+
...packageTools,
|
|
76
|
+
...collectionTools,
|
|
77
|
+
...clipboardTools,
|
|
65
78
|
...migrationTools,
|
|
66
79
|
...formTools,
|
|
67
80
|
...emailTools,
|
|
68
81
|
...settingsTools,
|
|
82
|
+
...fontTools,
|
|
69
83
|
...appTools,
|
|
70
84
|
...extensionTools,
|
|
71
85
|
...developerExtensionTools,
|
|
@@ -105,6 +119,11 @@ export function effectFor(name) {
|
|
|
105
119
|
// Same role as the portal: Settings, lifecycle and media purge are
|
|
106
120
|
// admin actions (the v1 routes enforce it as well).
|
|
107
121
|
|| name === 'update_site_settings'
|
|
122
|
+
// Fonts are settings; an upload also records a licence confirmation.
|
|
123
|
+
|| name === 'set_site_fonts'
|
|
124
|
+
|| name === 'upload_font'
|
|
125
|
+
// Site field definitions are site administration; values are write.
|
|
126
|
+
|| name === 'define_site_fields'
|
|
108
127
|
|| name === 'archive_site'
|
|
109
128
|
|| name === 'restore_site'
|
|
110
129
|
|| name === 'purge_site_media'
|
|
@@ -133,6 +152,8 @@ export function effectFor(name) {
|
|
|
133
152
|
|| name === 'revoke_organization_api_key'
|
|
134
153
|
|| name === 'create_organization_invite'
|
|
135
154
|
|| name === 'revoke_organization_invite'
|
|
155
|
+
|| name === 'update_organization_member_role'
|
|
156
|
+
|| name === 'remove_organization_member'
|
|
136
157
|
|| name === 'set_organization_ai_key'
|
|
137
158
|
|| name === 'remove_organization_ai_key'
|
|
138
159
|
|| name === 'set_organization_ai_site_access'
|
|
@@ -149,7 +170,8 @@ export function effectFor(name) {
|
|
|
149
170
|
|| name === 'set_incoming_email_forwarding')
|
|
150
171
|
return 'admin';
|
|
151
172
|
// Compute an answer and write nothing, like the preview_* tools.
|
|
152
|
-
|
|
173
|
+
// copy_blocks builds a clipboard from a page and writes nothing.
|
|
174
|
+
if (name === 'validate_block_type' || name === 'inspect_package' || name === 'copy_blocks' || name.startsWith('find_'))
|
|
153
175
|
return 'read';
|
|
154
176
|
if (name === 'diff_version')
|
|
155
177
|
return 'read';
|
|
@@ -164,6 +186,16 @@ export function effectFor(name) {
|
|
|
164
186
|
}
|
|
165
187
|
return 'write';
|
|
166
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Admin tools a builder may also run: design work (colours, fonts, the Fonts
|
|
191
|
+
* library, site field definitions). A builder's personal connection reports
|
|
192
|
+
* `design` on its selected site; the REST routes check the same rule again.
|
|
193
|
+
*/
|
|
194
|
+
export const DESIGN_TOOLS = new Set(['update_site_settings', 'set_site_fonts', 'upload_font', 'define_site_fields']);
|
|
195
|
+
/** Whether a site permission (and design capability) may run a tool of this effect. */
|
|
196
|
+
export function toolAllowed(name, effect, permission, design = false) {
|
|
197
|
+
return PERM_RANK[permission] >= PERM_RANK[effect] || (design && permission !== 'read' && DESIGN_TOOLS.has(name));
|
|
198
|
+
}
|
|
167
199
|
const DEFAULT_INFO = { name: 'typeroll', title: 'Typeroll CMS', version: VERSION, websiteUrl: 'https://typeroll.com/docs/' };
|
|
168
200
|
/**
|
|
169
201
|
* Server identity with icons served by a Typeroll portal. Clients such as
|
|
@@ -311,7 +343,7 @@ export function buildServer(options) {
|
|
|
311
343
|
try {
|
|
312
344
|
if (needsSite) {
|
|
313
345
|
const selected = await options.selection.resolve(String(rawArgs.site_context || ''));
|
|
314
|
-
if (
|
|
346
|
+
if (!toolAllowed(tool.name, effect, selected.permission, selected.design))
|
|
315
347
|
return fail(new Error(`This tool requires ${effect} permission; your access is ${selected.permission}.`));
|
|
316
348
|
delete rawArgs.site_context;
|
|
317
349
|
return await tool.handler(rawArgs, { client: selected.client, siteId: selected.siteId });
|
package/dist/tools/access.js
CHANGED
|
@@ -7,6 +7,8 @@ import { z } from 'zod';
|
|
|
7
7
|
import { ok, withErrorBoundary } from './helpers.js';
|
|
8
8
|
const keyId = z.string().regex(/^[a-f0-9]{12}$/).describe('Key id (the 12-hex prefix) from list_api_keys / list_organization_api_keys.');
|
|
9
9
|
const inviteId = z.string().regex(/^[A-Za-z0-9_-]{16,64}$/).describe('Invite id from create_organization_invite or list_organization_invites.');
|
|
10
|
+
const memberId = z.string().regex(/^[A-Za-z0-9._:@-]{1,128}$/).describe('Member id from list_organization_members.');
|
|
11
|
+
const ROLES = 'Roles: owner (everything, including the organization itself), admin (members, publishing, domains, keys and design on every site), builder (structure, design, templates and the organization collection on every site; no members, billing or publishing connections) and editor (pages and content).';
|
|
10
12
|
export const accessTools = [
|
|
11
13
|
{
|
|
12
14
|
name: 'list_api_keys',
|
|
@@ -70,11 +72,12 @@ export const accessTools = [
|
|
|
70
72
|
{
|
|
71
73
|
name: 'create_organization_invite',
|
|
72
74
|
noSite: true,
|
|
73
|
-
description: 'Create a signed invite link to the Organization (organization API key required). The invited person opens invite_url, signs in and joins
|
|
75
|
+
description: 'Create a signed invite link to the Organization (organization API key required). The invited person opens invite_url, signs in and joins with role (admin, builder or editor; default editor; never owner). The link works until expires_at (ttl_days 1–30, default 7) for max_uses people (1–50, default 1: single use); with email set, only a person signed in with that address can redeem it. Returns the invite id; list_organization_invites shows its state and revoke_organization_invite (or DELETE /api/v1/organization/invites/{id}) stops the link immediately. Send the link only to the person the user named.',
|
|
74
76
|
inputSchema: {
|
|
75
77
|
ttl_days: z.number().int().min(1).max(30).optional(),
|
|
76
78
|
max_uses: z.number().int().min(1).max(50).optional().describe('How many people may redeem the link. Default 1 (single use).'),
|
|
77
79
|
email: z.string().email().max(320).optional().describe('Bind the invite to this email address: only a person signed in with it can redeem the link.'),
|
|
80
|
+
role: z.enum(['admin', 'builder', 'editor']).optional().describe('The role the person joins with. Default editor.'),
|
|
78
81
|
},
|
|
79
82
|
handler: withErrorBoundary(async (args, { client }) => ok(await client.rootPost('organization/invites', args))),
|
|
80
83
|
},
|
|
@@ -92,6 +95,27 @@ export const accessTools = [
|
|
|
92
95
|
inputSchema: { invite_id: inviteId },
|
|
93
96
|
handler: withErrorBoundary(async (args, { client }) => ok(await client.rootDelete(`organization/invites/${encodeURIComponent(args.invite_id)}`))),
|
|
94
97
|
},
|
|
98
|
+
{
|
|
99
|
+
name: 'list_organization_members',
|
|
100
|
+
noSite: true,
|
|
101
|
+
description: 'List the Organization\'s members: id, email, display_name, role and joined_at, owners first. ' + ROLES + ' Requires an organization API key, or a personal connection of an owner or administrator.',
|
|
102
|
+
inputSchema: {},
|
|
103
|
+
handler: withErrorBoundary(async (_args, { client }) => ok(await client.rootGet('organization/members'))),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'update_organization_member_role',
|
|
107
|
+
noSite: true,
|
|
108
|
+
description: 'Change a member\'s role (owner, admin, builder or editor). ' + ROLES + ' Only an owner (a personal connection of one) makes someone an owner or changes an owner\'s role; the last owner cannot be demoted (409 last_owner). An organization API key acts as an administrator. Confirm with the user first.',
|
|
109
|
+
inputSchema: { member_id: memberId, role: z.enum(['owner', 'admin', 'builder', 'editor']) },
|
|
110
|
+
handler: withErrorBoundary(async (args, { client }) => ok(await client.rootPatch(`organization/members/${encodeURIComponent(args.member_id)}`, { role: args.role }))),
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'remove_organization_member',
|
|
114
|
+
noSite: true,
|
|
115
|
+
description: 'Remove a member from the Organization: their access to its sites ends at once. Only an owner removes an owner, and the last owner cannot be removed (409 last_owner). Confirm with the user first.',
|
|
116
|
+
inputSchema: { member_id: memberId },
|
|
117
|
+
handler: withErrorBoundary(async (args, { client }) => ok(await client.rootDelete(`organization/members/${encodeURIComponent(args.member_id)}`))),
|
|
118
|
+
},
|
|
95
119
|
{
|
|
96
120
|
name: 'read_organization_ai_settings',
|
|
97
121
|
noSite: true,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copy and paste of blocks between pages and sites, like Cmd/Ctrl+C and V in
|
|
2
|
+
// the block editor. Each tool maps onto /api/v1/sites/{siteId}/clipboard/*.
|
|
3
|
+
// copy_blocks returns the clipboard text; paste_blocks takes it on any site
|
|
4
|
+
// the connection can write, the same or another.
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { ok, versionParam, withErrorBoundary } from './helpers.js';
|
|
7
|
+
const v = (version) => (version ? { version } : undefined);
|
|
8
|
+
const STYLES = 'Into another site, the styles the blocks use are created there, never mapped to "nearest" styles: one the site has with another definition is created under a new id (hero-2, "Hero (imported)") and the pasted blocks are rewritten to it; an identical one is reused. Site block types and free global blocks follow the same rule, app blocks reconnect to the app when the site has it installed, and links to the source site\'s pages become plain addresses. Each media file is copied into the site\'s Media library only when this connection may read the site it came from (an organization key reads the organization\'s sites, a site key only its own); a private file it cannot read is left out with a warning. Into the same site the blocks are placed as they are.';
|
|
9
|
+
export const clipboardTools = [
|
|
10
|
+
{
|
|
11
|
+
name: 'copy_blocks',
|
|
12
|
+
description: 'Copy blocks of a page\'s draft (with everything inside them) to a clipboard, as Cmd/Ctrl+C does in the block editor. Returns { clipboard, count: { top, total }, warnings }: clipboard is a JSON text marked "typeroll_clipboard" that holds the blocks in page order with the styles, site block types and free global blocks they use; media stay at their addresses. Pass clipboard unchanged to paste_blocks on this or another site. A person can paste the same text in the block editor with Cmd/Ctrl+V. Writes nothing.',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
page_id: z.string().min(1),
|
|
15
|
+
block_ids: z.array(z.string().min(1)).min(1).max(200).describe('Ids of the blocks to copy (from read_page); a block inside another listed block comes with it.'),
|
|
16
|
+
version: versionParam,
|
|
17
|
+
},
|
|
18
|
+
handler: withErrorBoundary(async ({ version, ...body }, { client, siteId }) => {
|
|
19
|
+
const result = await client.post(siteId, 'clipboard/copy', body, v(version));
|
|
20
|
+
return ok({ clipboard: result.clipboard_text, count: result.count, warnings: result.warnings });
|
|
21
|
+
}),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'paste_blocks',
|
|
25
|
+
description: 'Paste blocks from copy_blocks (or text a person copied in the block editor) into a page\'s draft, with new block ids: after after_block_id (in that block\'s parent or slot when it is nested), or at position (top level, or in parent_id / slot_index); at the end by default. Returns { report, page: { id, added_ids, blocks }, mode (same_site | other_site), media: { copied, reused, left_out, kept_external }, message }; save the page to publish the change. ' + STYLES,
|
|
26
|
+
inputSchema: {
|
|
27
|
+
clipboard: z.string().min(1).describe('The clipboard text from copy_blocks, unchanged.'),
|
|
28
|
+
page_id: z.string().min(1),
|
|
29
|
+
after_block_id: z.string().optional(),
|
|
30
|
+
position: z.number().int().min(0).optional(),
|
|
31
|
+
parent_id: z.string().nullable().optional(),
|
|
32
|
+
slot_index: z.number().int().min(0).optional(),
|
|
33
|
+
version: versionParam,
|
|
34
|
+
},
|
|
35
|
+
handler: withErrorBoundary(async ({ version, ...body }, { client, siteId }) => ok(await client.post(siteId, 'clipboard/paste', Object.fromEntries(Object.entries(body).filter(([, value]) => value !== undefined)), v(version)))),
|
|
36
|
+
},
|
|
37
|
+
];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// The organization collection: templates, sections, page templates, global
|
|
2
|
+
// blocks, block types and whole packages stored once for an organization and
|
|
3
|
+
// inserted into any of its sites. Each tool maps onto
|
|
4
|
+
// /api/v1/sites/{siteId}/collection/*; the site names the organization whose
|
|
5
|
+
// collection it is and the site an insert goes into.
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { ok, versionParam, withErrorBoundary } from './helpers.js';
|
|
8
|
+
const v = (version) => (version ? { version } : undefined);
|
|
9
|
+
const entryId = z.string().regex(/^[a-z0-9][a-z0-9_-]{0,79}$/).describe('Entry id from list_collection_entries.');
|
|
10
|
+
const WHO = 'The collection belongs to the site\'s organization and is visible to its owners, administrators and builders; a client given one site through a share never sees it (404), nor does a site-scoped key. Typeroll\'s built-in starters are listed as read-only entries.';
|
|
11
|
+
const STYLES = 'Inserting is a package import: every style the entry uses is created on the site, never mapped to a "nearest" style; a differing style with the same id is created under a new id (hero-2, "Hero (imported)") and the inserted content is rewritten to it. Block types and global blocks follow the same rule; media is copied into the site\'s Media library.';
|
|
12
|
+
export const collectionTools = [
|
|
13
|
+
{
|
|
14
|
+
name: 'list_collection_entries',
|
|
15
|
+
description: 'List the organization collection: { entries: [{ id, kind (section | block_template | page_template | global_block | block_type | package), name, description, category, preview_url, languages, source ({ type: site | package | builtin | app, publisher, verified, extension_id }), read_only, updated_at, summary: { block_count, top_level_types, styles, block_types, media } }] }. ' +
|
|
16
|
+
WHO + ' Insert an entry with insert_from_collection.',
|
|
17
|
+
inputSchema: { version: versionParam },
|
|
18
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => ok(await client.get(siteId, 'collection', v(args.version)))),
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'read_collection_entry',
|
|
22
|
+
description: 'Read one collection entry with its whole package (blocks, styles, block types, global blocks, media list).',
|
|
23
|
+
inputSchema: { entry_id: entryId, version: versionParam },
|
|
24
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => ok(await client.get(siteId, `collection/${encodeURIComponent(args.entry_id)}`, v(args.version)))),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'save_to_collection',
|
|
28
|
+
description: 'Save one of this site\'s block templates (kind "section" or "block_template"; the template\'s own kind decides which), page templates, free global blocks or block types to the organization collection, with the styles, block types, global blocks and media it uses. Returns 201 { entry, warnings }. ' + WHO,
|
|
29
|
+
inputSchema: {
|
|
30
|
+
kind: z.enum(['section', 'block_template', 'page_template', 'global_block', 'block_type']),
|
|
31
|
+
id: z.string().min(1).max(100).describe('The site\'s template, global block or block type id.'),
|
|
32
|
+
name: z.string().max(120).optional(), description: z.string().max(500).optional(), category: z.string().max(60).optional(),
|
|
33
|
+
version: versionParam,
|
|
34
|
+
},
|
|
35
|
+
handler: withErrorBoundary(async ({ version, ...body }, { client, siteId }) => ok(await client.post(siteId, 'collection/save', body, v(version)))),
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: 'add_package_to_collection',
|
|
39
|
+
description: 'Add a Typeroll package (.typeroll) to the organization collection without changing the site. A collection package becomes one entry per block template, page template, free global block and block type, each with what it depends on; a site package is kept whole as one entry of kind "package". Its menus, design, settings pages and font files are not entries. The source package, publisher and verified signature are recorded. Returns 201 { entries, warnings }.',
|
|
40
|
+
inputSchema: {
|
|
41
|
+
data_base64: z.string().optional().describe('The .typeroll file, base64-encoded (at most 32 MB). Send this or source_url.'),
|
|
42
|
+
source_url: z.string().optional().describe('An https:// address to download the package from (up to 200 MB).'),
|
|
43
|
+
},
|
|
44
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => ok(await client.post(siteId, 'collection/import', Object.fromEntries(Object.entries(args).filter(([, value]) => value !== undefined))))),
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'insert_from_collection',
|
|
48
|
+
description: 'Insert a collection entry into this site. target "library" adds the block template, page template, global block or block type (a built-in header or footer replaces the site\'s own; a whole package imports its content). target "page" places a section\'s, block template\'s or free global block\'s blocks in the page\'s draft: after after_block_id (in that block\'s parent or slot when it is nested), or at position (top level, or in parent_id / slot_index); at the end by default. Returns { report, page?: { id, added_ids, blocks } }; save the page to publish the change. ' + STYLES,
|
|
49
|
+
inputSchema: {
|
|
50
|
+
entry_id: entryId,
|
|
51
|
+
target: z.enum(['library', 'page']).default('library'),
|
|
52
|
+
page_id: z.string().optional().describe('Required for target "page".'),
|
|
53
|
+
after_block_id: z.string().optional(),
|
|
54
|
+
position: z.number().int().min(0).optional(),
|
|
55
|
+
parent_id: z.string().nullable().optional(),
|
|
56
|
+
slot_index: z.number().int().min(0).optional(),
|
|
57
|
+
version: versionParam,
|
|
58
|
+
},
|
|
59
|
+
handler: withErrorBoundary(async ({ entry_id, version, ...body }, { client, siteId }) => ok(await client.post(siteId, `collection/${encodeURIComponent(entry_id)}/insert`, Object.fromEntries(Object.entries(body).filter(([, value]) => value !== undefined)), v(version)))),
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'update_collection_entry',
|
|
63
|
+
description: 'Change a collection entry\'s name, description or category (an empty description or category removes it). Built-in entries are read-only.',
|
|
64
|
+
inputSchema: { entry_id: entryId, name: z.string().max(120).optional(), description: z.string().max(500).optional(), category: z.string().max(60).optional() },
|
|
65
|
+
handler: withErrorBoundary(async ({ entry_id, ...patch }, { client, siteId }) => ok(await client.patch(siteId, `collection/${encodeURIComponent(entry_id)}`, Object.fromEntries(Object.entries(patch).filter(([, value]) => value !== undefined))))),
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'delete_collection_entry',
|
|
69
|
+
description: 'Remove an entry from the organization collection, and the stored files no other entry uses. Sites it was inserted into keep their copies. Built-in entries cannot be removed. Confirm with the user first.',
|
|
70
|
+
inputSchema: { entry_id: entryId },
|
|
71
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => ok(await client.del(siteId, `collection/${encodeURIComponent(args.entry_id)}`))),
|
|
72
|
+
},
|
|
73
|
+
];
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Fonts: find a family, choose a family per role, and add font files to the
|
|
2
|
+
// site's Fonts library. Each tool maps onto the v1 API: search_fonts reads
|
|
3
|
+
// /fonts/catalog, set_site_fonts patches settings.fonts (with `version`, like
|
|
4
|
+
// update_site_settings), upload_font posts to /fonts.
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { ok, versionParam, withErrorBoundary } from './helpers.js';
|
|
7
|
+
const ROLES = 'A site chooses one family per role: heading (H1–H6), body (running text), mono (code; no webfont unless set), display (large headings and heroes; unset uses the heading family) and accent (eyebrows and quotes; unset uses the body family). ' +
|
|
8
|
+
'Display and accent take effect from render version 15. Styles and blocks choose a role, never a family, so changing a role restyles every style and block that uses it, and templates follow the site they are inserted into.';
|
|
9
|
+
const SOURCES = 'Where a family loads from, in order: the site\'s Fonts library (uploaded files, upload_font), a font service in fonts.services (Adobe Fonts kit, Bunny Fonts or Fontshare stylesheet, loaded from their CDN), "system" (the device\'s own fonts, no download), and otherwise Google Fonts. ' +
|
|
10
|
+
'Google families are self-hosted by default (fonts.delivery "self_hosted": the files are copied into the published site, no request to Google), or loaded from the Google Fonts CDN with delivery "google".';
|
|
11
|
+
const role = z.string().min(1).max(80).describe('A family name, as search_fonts lists it, or "system".');
|
|
12
|
+
const clearableRole = role.nullable().optional();
|
|
13
|
+
const weights = z.array(z.number().int().min(100).max(900).multipleOf(100)).max(9);
|
|
14
|
+
const service = z.union([
|
|
15
|
+
z.object({ provider: z.literal('adobe'), kit: z.string().describe('The Adobe Fonts web project ID from the embed code https://use.typekit.net/<kit>.css.'), families: z.array(z.string()).max(40).describe('The family names the kit defines (its CSS font-family names, e.g. "brand-sans").') }).strict(),
|
|
16
|
+
z.object({ provider: z.enum(['bunny', 'fontshare']), url: z.string().describe('The stylesheet URL: https://fonts.bunny.net/css?family=… or https://api.fontshare.com/v2/css?f[]=…'), families: z.array(z.string()).max(40) }).strict(),
|
|
17
|
+
]);
|
|
18
|
+
export const fontTools = [
|
|
19
|
+
{
|
|
20
|
+
name: 'search_fonts',
|
|
21
|
+
description: 'Search the font catalog (250 open-licence Google Fonts families with their weights, italics, variable weight axis and extended Latin support) and the site\'s own families: uploaded files (`library`) and font services (`services`), matching the same query. ' +
|
|
22
|
+
'Exact names rank first, then names starting with the query. Use it before set_site_fonts to check a family exists and has the weights the design needs. Swedish, Norwegian, Danish, Finnish and German are covered by every catalog family; latin_ext adds Polish, Czech, Turkish and more. ' + SOURCES,
|
|
23
|
+
inputSchema: {
|
|
24
|
+
query: z.string().max(80).optional().describe('Part of a family name, e.g. "grotesk" or "Playfair".'),
|
|
25
|
+
category: z.union([z.enum(['sans', 'serif', 'display', 'handwriting', 'mono']), z.array(z.enum(['sans', 'serif', 'display', 'handwriting', 'mono'])).max(5)]).optional(),
|
|
26
|
+
variable: z.boolean().optional().describe('Only variable families (one file covers every weight).'),
|
|
27
|
+
italic: z.boolean().optional().describe('Only families with italics.'),
|
|
28
|
+
latin_ext: z.boolean().optional().describe('Only families with the extended Latin subset.'),
|
|
29
|
+
limit: z.number().int().min(1).max(250).optional().describe('Catalog results to return (default 50).'),
|
|
30
|
+
},
|
|
31
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => {
|
|
32
|
+
const flag = (value) => value === undefined ? undefined : String(value);
|
|
33
|
+
return ok(await client.get(siteId, 'fonts/catalog', {
|
|
34
|
+
query: args.query,
|
|
35
|
+
category: Array.isArray(args.category) ? args.category.join(',') : args.category,
|
|
36
|
+
variable: flag(args.variable), italic: flag(args.italic), latin_ext: flag(args.latin_ext), limit: args.limit,
|
|
37
|
+
}));
|
|
38
|
+
}),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'set_site_fonts',
|
|
42
|
+
description: 'Choose the site\'s fonts. ' + ROLES + ' ' +
|
|
43
|
+
'From render version 15 a publication loads only the weights and italics the site uses (from its styles, block weight settings and bold or italic text), so there is nothing to list for normal use; `load` adds extra weights per role, for example for custom CSS: { body: { weights: [300], italic: [400] } }. Before version 15 every family loads 400–700. ' +
|
|
44
|
+
SOURCES + ' ' +
|
|
45
|
+
'Only the keys you pass change; null clears mono, display, accent, load, delivery or services. Requires admin permission, like update_site_settings. Pass `version` to change a branch instead of main. ' +
|
|
46
|
+
'The response warns about a family that is not in the catalog, the Fonts library or a font service. Check the result with get_preview_link before publishing.',
|
|
47
|
+
inputSchema: {
|
|
48
|
+
version: versionParam,
|
|
49
|
+
heading: role.optional(),
|
|
50
|
+
body: role.optional(),
|
|
51
|
+
mono: clearableRole.describe('Code and preformatted text. Without it code uses the system monospace stack; null clears.'),
|
|
52
|
+
display: clearableRole.describe('Large headings and heroes (render version 15). null uses the heading family.'),
|
|
53
|
+
accent: clearableRole.describe('Eyebrows and quotes (render version 15). null uses the body family.'),
|
|
54
|
+
load: z.record(z.enum(['heading', 'body', 'mono', 'display', 'accent']), z.object({ weights: weights.optional(), italic: weights.optional() }).strict()).nullable().optional()
|
|
55
|
+
.describe('Extra weights (and italic weights) to load per role beyond those in use, e.g. { "heading": { "weights": [800] } }. null clears.'),
|
|
56
|
+
delivery: z.enum(['self_hosted', 'google']).nullable().optional().describe('Google Fonts delivery: self_hosted (default, files copied into the site) or google (Google Fonts CDN). Uploaded and service fonts are unaffected.'),
|
|
57
|
+
services: z.array(service).max(4).nullable().optional()
|
|
58
|
+
.describe('Font services whose stylesheet loads from their CDN; replaces the list. Adobe Fonts\' licence does not allow self-hosting, so a kit always loads from Adobe (the visitor\'s browser contacts Adobe; mention it in the privacy policy). null clears.'),
|
|
59
|
+
},
|
|
60
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => {
|
|
61
|
+
const { version, ...fonts } = args;
|
|
62
|
+
const patch = Object.fromEntries(Object.entries(fonts).filter(([, value]) => value !== undefined));
|
|
63
|
+
if (!Object.keys(patch).length)
|
|
64
|
+
throw new Error('No fonts supplied. Pass at least one role (heading, body, mono, display, accent), load, delivery or services.');
|
|
65
|
+
return ok(await client.patch(siteId, 'settings', { fonts: patch }, version ? { version } : undefined));
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'upload_font',
|
|
70
|
+
description: 'Add a font file to the site\'s Fonts library (not the media library), so a role can use its family with set_site_fonts. WOFF2, WOFF, TTF or OTF up to 10 MB, one font per file (no .ttc collections); anything but WOFF2 is converted to WOFF2 and the original kept. ' +
|
|
71
|
+
'Family, weight and style default from the file; pass them to correct the file\'s names. A variable font covers a weight range ("100-900"). Upload one file per style (regular, italic) and, for static fonts, per weight. ' +
|
|
72
|
+
'licence_confirmed must be true and means the user confirmed the font\'s licence allows use on this website (a webfont or web licence; most desktop licences do not include it). Ask the user before uploading; never assume it. It is stored with who confirmed it and when. ' +
|
|
73
|
+
'Send the file as data_base64 with filename, or as source_url (https; downloaded by Typeroll). Requires admin permission. The library belongs to the site, not to a branch. ' +
|
|
74
|
+
'Adobe Fonts cannot be uploaded (its licence does not allow self-hosting): add the kit with set_site_fonts services instead.',
|
|
75
|
+
inputSchema: {
|
|
76
|
+
filename: z.string().max(255).optional().describe('The file name, e.g. "BrandSans-Regular.woff2". Required with data_base64.'),
|
|
77
|
+
data_base64: z.string().optional().describe('The file bytes, base64-encoded (a data: URL prefix is allowed).'),
|
|
78
|
+
source_url: z.string().optional().describe('An https:// URL to download the file from, instead of data_base64.'),
|
|
79
|
+
family: z.string().max(80).optional().describe('The family name the roles use. Defaults to the name in the file.'),
|
|
80
|
+
weight: z.union([z.number().int().min(100).max(900), z.string()]).optional().describe('400, or a range such as "100-900" for a variable font. Defaults to the file\'s weight.'),
|
|
81
|
+
style: z.enum(['normal', 'italic']).optional().describe('Defaults to the file\'s style.'),
|
|
82
|
+
category: z.enum(['sans', 'serif']).optional().describe('Chooses the metric-matched fallback shown while the font loads (Arial or Times New Roman). Defaults to sans.'),
|
|
83
|
+
licence_confirmed: z.literal(true).describe('true: the user confirmed the licence allows using this font on this website.'),
|
|
84
|
+
licence_note: z.string().max(500).optional().describe('Where the licence comes from, e.g. "Web licence, order 1234".'),
|
|
85
|
+
},
|
|
86
|
+
handler: withErrorBoundary(async (args, { client, siteId }) => {
|
|
87
|
+
const body = Object.fromEntries(Object.entries(args).filter(([, value]) => value !== undefined));
|
|
88
|
+
return ok(await client.post(siteId, 'fonts', body));
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
];
|