@businesskit/agent 1.0.5 → 1.0.7
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/.superconsole-plugin/plugin.json +61 -31
- package/AGENTS.md +20 -9
- package/README.md +101 -113
- package/bin/businesskit.js +41 -8
- package/commands/brief.md +12 -0
- package/commands/chase.md +12 -0
- package/commands/create-page.md +43 -15
- package/commands/crm.md +13 -0
- package/commands/followups.md +13 -0
- package/commands/pipeline.md +13 -0
- package/commands/update-agent.md +33 -0
- package/commands/update-content.md +1 -0
- package/commands/update-page.md +3 -2
- package/commands/write-blog.md +4 -0
- package/commands/write-docs.md +6 -0
- package/commands/write-guide.md +5 -0
- package/commands/write-newsletter.md +4 -0
- package/dist/server.js +4099 -0
- package/mcp_config.json +6 -2
- package/package.json +23 -5
- package/scripts/setup.sh +70 -35
- package/scripts/setup.ts +58 -21
- package/scripts/update.sh +56 -0
- package/server.json +3 -3
- package/skills/README.md +3 -2
- package/skills/cms/SKILL.md +111 -0
- package/skills/cms/references/cms-hubs.md +84 -0
- package/skills/cms/references/html-blocks.md +177 -0
- package/skills/crm/SKILL.md +15 -29
- package/skills/docs/SKILL.md +65 -0
- package/skills/docs/references/how-to.md +155 -0
- package/skills/pages/SKILL.md +62 -17
- package/skills/pages/references/sections-catalog.json +377 -144
- package/skills/social/SKILL.md +83 -210
- package/skills/social/evals/evals.json +66 -0
- package/skills/social/evals/rubric.md +26 -0
- package/skills/social/examples/repurposing-blog-to-social.md +93 -0
- package/skills/social/examples/weekly-content-calendar.md +30 -0
- package/skills/social/linkedin/SKILL.md +107 -0
- package/skills/social/linkedin/evals/evals.json +106 -0
- package/skills/social/linkedin/evals/rubric.md +28 -0
- package/skills/social/linkedin/examples/gasp-weekly-sprint.md +24 -0
- package/skills/social/linkedin/examples/growth-posts-by-format.md +140 -0
- package/skills/social/linkedin/references/gasp-funnel-and-calibration.md +90 -0
- package/skills/social/linkedin/references/six-growth-formats.md +114 -0
- package/skills/social/references/platforms.md +76 -0
- package/skills/social/references/post-templates.md +105 -0
- package/skills/social/references/reverse-engineering.md +62 -0
- package/src/data/sections-catalog.json +950 -0
- package/src/db.ts +170 -0
- package/src/server.ts +75 -0
- package/src/tools/content.ts +326 -0
- package/src/tools/crm.ts +1416 -0
- package/src/tools/domains.ts +89 -0
- package/src/tools/inbox.ts +270 -0
- package/src/tools/index.ts +116 -0
- package/src/tools/pages.ts +1217 -0
- package/src/tools/shop.ts +771 -0
- package/src/tools/system.ts +94 -0
- package/src/tools/types.ts +17 -0
- package/skills/docs-cms/SKILL.md +0 -53
- package/skills/docs-cms/references/how-to.md +0 -383
package/src/db.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// src/db.ts
|
|
2
|
+
// Direct Turso / LibSQL client connection for BusinessKit MCP Server
|
|
3
|
+
|
|
4
|
+
import { createClient, type Client } from '@libsql/client';
|
|
5
|
+
import dotenv from 'dotenv';
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
|
|
8
|
+
// Load environment variables from .env file
|
|
9
|
+
dotenv.config();
|
|
10
|
+
|
|
11
|
+
let clientInstance: Client | null = null;
|
|
12
|
+
let currentProfileId: string = process.env.PROFILE_ID || process.env.BK_PROFILE_ID || '';
|
|
13
|
+
let profileResolved = false;
|
|
14
|
+
|
|
15
|
+
function cleanVal(v?: string): string {
|
|
16
|
+
if (!v) return '';
|
|
17
|
+
const trimmed = v.trim();
|
|
18
|
+
if (
|
|
19
|
+
trimmed.includes('your-db') ||
|
|
20
|
+
trimmed.includes('your-database') ||
|
|
21
|
+
trimmed.includes('your-token') ||
|
|
22
|
+
trimmed.includes('your-turso-auth-token')
|
|
23
|
+
) {
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
return trimmed;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getTursoConfig(): { url: string; token: string; readOnly: boolean } | null {
|
|
30
|
+
const url =
|
|
31
|
+
cleanVal(process.env.TURSO_DATABASE_URL) ||
|
|
32
|
+
cleanVal(process.env.TURSO_URL) ||
|
|
33
|
+
cleanVal(process.env.BK_TURSO_URL) ||
|
|
34
|
+
cleanVal(process.env.DATABASE_URL);
|
|
35
|
+
|
|
36
|
+
const writeToken =
|
|
37
|
+
cleanVal(process.env.TURSO_AUTH_TOKEN) ||
|
|
38
|
+
cleanVal(process.env.TURSO_TOKEN) ||
|
|
39
|
+
cleanVal(process.env.BK_TURSO_TOKEN) ||
|
|
40
|
+
cleanVal(process.env.AUTH_TOKEN);
|
|
41
|
+
|
|
42
|
+
const roToken =
|
|
43
|
+
cleanVal(process.env.TURSO_READ_ONLY_TOKEN) ||
|
|
44
|
+
cleanVal(process.env.TURSO_RO_TOKEN);
|
|
45
|
+
|
|
46
|
+
const isReadOnly = Boolean(
|
|
47
|
+
(!writeToken && roToken) ||
|
|
48
|
+
process.env.READ_ONLY === 'true' ||
|
|
49
|
+
process.env.TURSO_READONLY === 'true'
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const token = writeToken || roToken;
|
|
53
|
+
|
|
54
|
+
if (!url || !token) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Normalize URL to https or libsql
|
|
59
|
+
let normalizedUrl = url;
|
|
60
|
+
if (normalizedUrl.startsWith('turso://')) {
|
|
61
|
+
normalizedUrl = 'https://' + normalizedUrl.slice(8);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { url: normalizedUrl, token, readOnly: isReadOnly };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function isDbConfigured(): boolean {
|
|
68
|
+
return getTursoConfig() !== null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function isDbReadOnly(): boolean {
|
|
72
|
+
const cfg = getTursoConfig();
|
|
73
|
+
return cfg ? cfg.readOnly : false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function getDbClient(): Client {
|
|
77
|
+
if (clientInstance) {
|
|
78
|
+
return clientInstance;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const config = getTursoConfig();
|
|
82
|
+
if (!config) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
'Turso database credentials not configured. Please define TURSO_DATABASE_URL and TURSO_AUTH_TOKEN in your .env file or environment variables.'
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
clientInstance = createClient({
|
|
89
|
+
url: config.url,
|
|
90
|
+
authToken: config.token,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return clientInstance;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function getActiveProfileId(): Promise<string> {
|
|
97
|
+
if (currentProfileId) {
|
|
98
|
+
return currentProfileId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (profileResolved || !isDbConfigured()) {
|
|
102
|
+
currentProfileId = 'default';
|
|
103
|
+
return currentProfileId;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
profileResolved = true;
|
|
108
|
+
const client = getDbClient();
|
|
109
|
+
// 1. Try querying profiles table
|
|
110
|
+
const result = await client.execute('SELECT id FROM profiles LIMIT 1');
|
|
111
|
+
if (result.rows.length > 0 && result.rows[0].id) {
|
|
112
|
+
currentProfileId = String(result.rows[0].id);
|
|
113
|
+
return currentProfileId;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// 2. Fallback: try shop_items profile_id
|
|
117
|
+
const shopResult = await client.execute('SELECT profile_id FROM shop_items LIMIT 1');
|
|
118
|
+
if (shopResult.rows.length > 0 && shopResult.rows[0].profile_id) {
|
|
119
|
+
currentProfileId = String(shopResult.rows[0].profile_id);
|
|
120
|
+
return currentProfileId;
|
|
121
|
+
}
|
|
122
|
+
} catch (err: any) {
|
|
123
|
+
console.error('[DB] Profile lookup error (defaulting to "default"):', err?.message || err);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
currentProfileId = 'default';
|
|
127
|
+
return currentProfileId;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function setActiveProfileId(id: string): void {
|
|
131
|
+
currentProfileId = id.trim();
|
|
132
|
+
profileResolved = true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function query<T = any>(sql: string, args: any[] = []): Promise<T[]> {
|
|
136
|
+
const client = getDbClient();
|
|
137
|
+
const res = await client.execute({ sql, args });
|
|
138
|
+
return (res.rows as unknown) as T[];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function execute(
|
|
142
|
+
sql: string,
|
|
143
|
+
args: any[] = []
|
|
144
|
+
): Promise<{ rowsAffected: number; lastInsertRowid?: bigint }> {
|
|
145
|
+
if (isDbReadOnly()) {
|
|
146
|
+
throw new Error(
|
|
147
|
+
'Database is connected in read-only mode (read-only token). Write operations (INSERT, UPDATE, DELETE) are not permitted.'
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const client = getDbClient();
|
|
151
|
+
const res = await client.execute({ sql, args });
|
|
152
|
+
return {
|
|
153
|
+
rowsAffected: res.rowsAffected,
|
|
154
|
+
lastInsertRowid: res.lastInsertRowid,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function generateId(prefix: string): string {
|
|
159
|
+
const cleanPrefix = prefix.endsWith('_') ? prefix : `${prefix}_`;
|
|
160
|
+
return `${cleanPrefix}${randomUUID().replace(/-/g, '').slice(0, 12)}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function generateSku(): string {
|
|
164
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
165
|
+
let sku = '';
|
|
166
|
+
for (let i = 0; i < 10; i++) {
|
|
167
|
+
sku += chars.charAt(Math.floor(Math.random() * chars.length));
|
|
168
|
+
}
|
|
169
|
+
return sku;
|
|
170
|
+
}
|
package/src/server.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
// BusinessKit Model Context Protocol (MCP) stdio server
|
|
3
|
+
|
|
4
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
6
|
+
import {
|
|
7
|
+
CallToolRequestSchema,
|
|
8
|
+
ListToolsRequestSchema,
|
|
9
|
+
type CallToolResult,
|
|
10
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
11
|
+
import { getAllToolDefinitions, dispatchTool } from './tools/index.js';
|
|
12
|
+
import { isDbConfigured } from './db.js';
|
|
13
|
+
|
|
14
|
+
export async function startServer(): Promise<void> {
|
|
15
|
+
const server = new Server(
|
|
16
|
+
{
|
|
17
|
+
name: 'io.github.businesskitai/agent',
|
|
18
|
+
version: '1.0.7',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
capabilities: {
|
|
22
|
+
tools: {},
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
// List all available tools
|
|
28
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
29
|
+
return {
|
|
30
|
+
tools: getAllToolDefinitions(),
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Handle tool execution
|
|
35
|
+
server.setRequestHandler(CallToolRequestSchema, async (request): Promise<CallToolResult> => {
|
|
36
|
+
const { name, arguments: args } = request.params;
|
|
37
|
+
try {
|
|
38
|
+
const result = await dispatchTool(name, args || {});
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
isError: false,
|
|
47
|
+
};
|
|
48
|
+
} catch (err: any) {
|
|
49
|
+
console.error(`[MCP Error] tool '${name}' failed:`, err);
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: err?.message || String(err),
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
isError: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const transport = new StdioServerTransport();
|
|
63
|
+
await server.connect(transport);
|
|
64
|
+
|
|
65
|
+
console.error('[BusinessKit MCP] Server listening on stdio transport.');
|
|
66
|
+
console.error(`[BusinessKit MCP] Database connection status: ${isDbConfigured() ? 'CONFIGURED' : 'NOT CONFIGURED (set TURSO_DATABASE_URL and TURSO_AUTH_TOKEN in .env)'}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Auto-run if executed directly
|
|
70
|
+
if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('server.js') || process.argv[1]?.endsWith('server.ts')) {
|
|
71
|
+
startServer().catch((err) => {
|
|
72
|
+
console.error('[BusinessKit MCP] Fatal startup error:', err);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// src/tools/content.ts
|
|
2
|
+
// Content / CMS MCP Tools: Blog Posts, Docs, Newsletters, Guides, and Knowledge Hub
|
|
3
|
+
|
|
4
|
+
import { execute, generateId, query } from '../db.js';
|
|
5
|
+
import type { ToolDefinition, ToolContext } from './types.js';
|
|
6
|
+
|
|
7
|
+
export const contentTools: ToolDefinition[] = [
|
|
8
|
+
{
|
|
9
|
+
name: 'blog_post_create',
|
|
10
|
+
domain: 'content',
|
|
11
|
+
description:
|
|
12
|
+
'Create or publish a rich HTML blog post, newsletter, docs article, guide, or custom CMS entry. Clean semantic HTML body in body_html.',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
title: { type: 'string', description: 'Title of the blog post, newsletter, doc, or guide' },
|
|
17
|
+
body_html: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
description:
|
|
20
|
+
'Clean semantic HTML body supporting all blocks (<h2>, <h3>, <p>, lists, taskList, tables, pre data-filename, info-card, steps, accordion-group, kbd, images, video embeds). NEVER Markdown or <h1>.',
|
|
21
|
+
},
|
|
22
|
+
content_type: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: "Target hub slug: 'blog' (default), 'n' (newsletter), 'docs', 'guides', or custom CMS slug.",
|
|
25
|
+
},
|
|
26
|
+
cms_id: { type: 'string', description: 'Optional target CMS UUID.' },
|
|
27
|
+
collection: { type: 'string', description: 'Collection name, slug, or ID for Docs/Guides.' },
|
|
28
|
+
slug: { type: 'string', description: 'Optional custom URL slug.' },
|
|
29
|
+
excerpt: { type: 'string', description: '1-2 sentence teaser summary.' },
|
|
30
|
+
ai_summary: { type: 'string', description: 'Concise TL;DR summary.' },
|
|
31
|
+
hero_image_url: { type: 'string', description: 'Optional cover/hero image URL.' },
|
|
32
|
+
media_id: { type: 'string', description: 'Optional Media Library item ID.' },
|
|
33
|
+
cta_button_text: { type: 'string', description: 'Optional CTA button label.' },
|
|
34
|
+
cta_button_url: { type: 'string', description: 'Optional CTA button URL.' },
|
|
35
|
+
additional_details: {
|
|
36
|
+
type: 'array',
|
|
37
|
+
items: {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
key: { type: 'string' },
|
|
41
|
+
value: { type: 'string' },
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
seo_title: { type: 'string', description: 'Optional SEO meta title.' },
|
|
46
|
+
seo_description: { type: 'string', description: 'Optional SEO meta description.' },
|
|
47
|
+
seo_keywords: { type: 'string', description: 'Optional SEO keywords.' },
|
|
48
|
+
status: { type: 'string', enum: ['draft', 'publish', 'published'], default: 'draft' },
|
|
49
|
+
published: { type: 'boolean', description: 'Publish immediately (true) or draft (false).' },
|
|
50
|
+
hidden: { type: 'boolean', default: false },
|
|
51
|
+
hide_author: { type: 'boolean', default: false },
|
|
52
|
+
},
|
|
53
|
+
required: ['title', 'body_html'],
|
|
54
|
+
},
|
|
55
|
+
handler: async (args: Record<string, any>, ctx: ToolContext) => {
|
|
56
|
+
const profileId = ctx.profileId;
|
|
57
|
+
const title = String(args.title || '').trim();
|
|
58
|
+
const bodyHtml = String(args.body_html || '');
|
|
59
|
+
const contentType = args.content_type || 'blog';
|
|
60
|
+
|
|
61
|
+
const postId = generateId('post');
|
|
62
|
+
const rawSlug =
|
|
63
|
+
args.slug ||
|
|
64
|
+
title
|
|
65
|
+
.toLowerCase()
|
|
66
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
67
|
+
.replace(/^-|-$/g, '');
|
|
68
|
+
const slug = rawSlug || `post-${Date.now()}`;
|
|
69
|
+
|
|
70
|
+
const isPublished = args.published === true || args.status === 'publish' || args.status === 'published' ? 1 : 0;
|
|
71
|
+
const isHidden = args.hidden ? 1 : 0;
|
|
72
|
+
const isHideAuthor = args.hide_author ? 1 : 0;
|
|
73
|
+
|
|
74
|
+
const plainText = bodyHtml.replace(/<[^>]+>/g, ' ');
|
|
75
|
+
const words = plainText.trim().split(/\s+/).filter(Boolean);
|
|
76
|
+
const wordCount = words.length;
|
|
77
|
+
const readingTime = Math.max(1, Math.ceil(wordCount / 200));
|
|
78
|
+
|
|
79
|
+
await execute(
|
|
80
|
+
`INSERT INTO content
|
|
81
|
+
(id, profile_id, category_id, collection_id, cms_id, slug, title, body_html, excerpt, ai_summary, hero_image_url, media_id, cta_button_text, cta_button_url, additional_details, seo_title, seo_description, seo_keywords, published, hidden, hide_author, word_count, reading_time_mins, created_at, updated_at)
|
|
82
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%s','now'), strftime('%s','now'))`,
|
|
83
|
+
[
|
|
84
|
+
postId,
|
|
85
|
+
profileId,
|
|
86
|
+
contentType,
|
|
87
|
+
args.collection || null,
|
|
88
|
+
args.cms_id || null,
|
|
89
|
+
slug,
|
|
90
|
+
title,
|
|
91
|
+
bodyHtml,
|
|
92
|
+
args.excerpt || null,
|
|
93
|
+
args.ai_summary || null,
|
|
94
|
+
args.hero_image_url || null,
|
|
95
|
+
args.media_id || null,
|
|
96
|
+
args.cta_button_text || null,
|
|
97
|
+
args.cta_button_url || null,
|
|
98
|
+
args.additional_details ? JSON.stringify(args.additional_details) : '[]',
|
|
99
|
+
args.seo_title || title,
|
|
100
|
+
args.seo_description || args.excerpt || null,
|
|
101
|
+
args.seo_keywords || null,
|
|
102
|
+
isPublished,
|
|
103
|
+
isHidden,
|
|
104
|
+
isHideAuthor,
|
|
105
|
+
wordCount,
|
|
106
|
+
readingTime,
|
|
107
|
+
]
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
id: postId,
|
|
112
|
+
title,
|
|
113
|
+
slug,
|
|
114
|
+
content_type: contentType,
|
|
115
|
+
published: isPublished === 1,
|
|
116
|
+
word_count: wordCount,
|
|
117
|
+
reading_time_mins: readingTime,
|
|
118
|
+
status: isPublished === 1 ? 'published' : 'draft',
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'content_list',
|
|
124
|
+
domain: 'content',
|
|
125
|
+
description: 'List existing blog posts, newsletters, docs, guides, and custom hub entries for the active profile.',
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
content_type: { type: 'string', description: "Optional hub slug filter (e.g. 'blog', 'n', 'docs', 'guides')." },
|
|
130
|
+
cms_id: { type: 'string', description: 'Optional target CMS UUID filter.' },
|
|
131
|
+
published_only: { type: 'boolean', description: 'If true, return only published entries.', default: false },
|
|
132
|
+
limit: { type: 'integer', description: 'Maximum rows to return (default 30, max 100).' },
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
handler: async (args: Record<string, any>, ctx: ToolContext) => {
|
|
136
|
+
const profileId = ctx.profileId;
|
|
137
|
+
const limit = Math.min(Number(args.limit || 30), 100);
|
|
138
|
+
|
|
139
|
+
let sql = 'SELECT id, title, slug, excerpt, category_id, published, word_count, created_at FROM content WHERE profile_id = ?';
|
|
140
|
+
const params: any[] = [profileId];
|
|
141
|
+
|
|
142
|
+
if (args.content_type) {
|
|
143
|
+
sql += ' AND category_id = ?';
|
|
144
|
+
params.push(args.content_type);
|
|
145
|
+
}
|
|
146
|
+
if (args.cms_id) {
|
|
147
|
+
sql += ' AND cms_id = ?';
|
|
148
|
+
params.push(args.cms_id);
|
|
149
|
+
}
|
|
150
|
+
if (args.published_only) {
|
|
151
|
+
sql += ' AND published = 1';
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
sql += ' ORDER BY created_at DESC LIMIT ?';
|
|
155
|
+
params.push(limit);
|
|
156
|
+
|
|
157
|
+
const rows = await query(sql, params);
|
|
158
|
+
return {
|
|
159
|
+
total: rows.length,
|
|
160
|
+
items: rows.map((r: any) => ({
|
|
161
|
+
id: r.id,
|
|
162
|
+
title: r.title,
|
|
163
|
+
slug: r.slug,
|
|
164
|
+
excerpt: r.excerpt,
|
|
165
|
+
content_type: r.category_id,
|
|
166
|
+
published: Boolean(r.published),
|
|
167
|
+
word_count: r.word_count,
|
|
168
|
+
created_at: r.created_at,
|
|
169
|
+
})),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'content_get',
|
|
175
|
+
domain: 'content',
|
|
176
|
+
description:
|
|
177
|
+
'Fetch full HTML content and metadata for an existing blog post, newsletter, doc, guide, or custom hub entry by ID or slug.',
|
|
178
|
+
inputSchema: {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties: {
|
|
181
|
+
content_id_or_slug: { type: 'string', description: "Content ID (e.g. 'post_...') or URL slug." },
|
|
182
|
+
content_type: { type: 'string', description: 'Optional hub slug filter.' },
|
|
183
|
+
cms_id: { type: 'string', description: 'Optional target CMS UUID filter.' },
|
|
184
|
+
},
|
|
185
|
+
required: ['content_id_or_slug'],
|
|
186
|
+
},
|
|
187
|
+
handler: async (args: Record<string, any>, ctx: ToolContext) => {
|
|
188
|
+
const profileId = ctx.profileId;
|
|
189
|
+
const ref = String(args.content_id_or_slug).trim();
|
|
190
|
+
|
|
191
|
+
const rows = await query(
|
|
192
|
+
'SELECT * FROM content WHERE profile_id = ? AND (id = ? OR slug = ?) LIMIT 1',
|
|
193
|
+
[profileId, ref, ref]
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
if (rows.length === 0) {
|
|
197
|
+
throw new Error(`Content not found with identifier: ${ref}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const row = rows[0];
|
|
201
|
+
return {
|
|
202
|
+
id: row.id,
|
|
203
|
+
title: row.title,
|
|
204
|
+
slug: row.slug,
|
|
205
|
+
body_html: row.body_html,
|
|
206
|
+
excerpt: row.excerpt,
|
|
207
|
+
ai_summary: row.ai_summary,
|
|
208
|
+
hero_image_url: row.hero_image_url,
|
|
209
|
+
content_type: row.category_id,
|
|
210
|
+
published: Boolean(row.published),
|
|
211
|
+
word_count: row.word_count,
|
|
212
|
+
reading_time_mins: row.reading_time_mins,
|
|
213
|
+
seo_title: row.seo_title,
|
|
214
|
+
seo_description: row.seo_description,
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
name: 'content_update',
|
|
220
|
+
domain: 'content',
|
|
221
|
+
description:
|
|
222
|
+
'Update an existing blog post, newsletter, doc, guide, or custom hub entry (HTML body, title, slug, collection, publish status, CTA, SEO).',
|
|
223
|
+
inputSchema: {
|
|
224
|
+
type: 'object',
|
|
225
|
+
properties: {
|
|
226
|
+
content_id_or_slug: { type: 'string', description: 'Target content ID or URL slug.' },
|
|
227
|
+
title: { type: 'string' },
|
|
228
|
+
slug: { type: 'string' },
|
|
229
|
+
body_html: { type: 'string' },
|
|
230
|
+
collection: { type: 'string' },
|
|
231
|
+
excerpt: { type: 'string' },
|
|
232
|
+
ai_summary: { type: 'string' },
|
|
233
|
+
hero_image_url: { type: 'string' },
|
|
234
|
+
cta_button_text: { type: 'string' },
|
|
235
|
+
cta_button_url: { type: 'string' },
|
|
236
|
+
seo_title: { type: 'string' },
|
|
237
|
+
seo_description: { type: 'string' },
|
|
238
|
+
seo_keywords: { type: 'string' },
|
|
239
|
+
status: { type: 'string', enum: ['draft', 'publish', 'published'] },
|
|
240
|
+
published: { type: 'boolean' },
|
|
241
|
+
hidden: { type: 'boolean' },
|
|
242
|
+
hide_author: { type: 'boolean' },
|
|
243
|
+
},
|
|
244
|
+
required: ['content_id_or_slug'],
|
|
245
|
+
},
|
|
246
|
+
handler: async (args: Record<string, any>, ctx: ToolContext) => {
|
|
247
|
+
const profileId = ctx.profileId;
|
|
248
|
+
const ref = String(args.content_id_or_slug).trim();
|
|
249
|
+
|
|
250
|
+
const rows = await query<{ id: string }>('SELECT id FROM content WHERE profile_id = ? AND (id = ? OR slug = ?) LIMIT 1', [
|
|
251
|
+
profileId,
|
|
252
|
+
ref,
|
|
253
|
+
ref,
|
|
254
|
+
]);
|
|
255
|
+
|
|
256
|
+
if (rows.length === 0) {
|
|
257
|
+
throw new Error(`Content not found with identifier: ${ref}`);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const id = rows[0].id;
|
|
261
|
+
const updates: string[] = [];
|
|
262
|
+
const params: any[] = [];
|
|
263
|
+
|
|
264
|
+
const stringFields = [
|
|
265
|
+
'title',
|
|
266
|
+
'slug',
|
|
267
|
+
'body_html',
|
|
268
|
+
'collection',
|
|
269
|
+
'excerpt',
|
|
270
|
+
'ai_summary',
|
|
271
|
+
'hero_image_url',
|
|
272
|
+
'cta_button_text',
|
|
273
|
+
'cta_button_url',
|
|
274
|
+
'seo_title',
|
|
275
|
+
'seo_description',
|
|
276
|
+
'seo_keywords',
|
|
277
|
+
];
|
|
278
|
+
|
|
279
|
+
for (const field of stringFields) {
|
|
280
|
+
if (args[field] !== undefined) {
|
|
281
|
+
const col = field === 'collection' ? 'collection_id' : field;
|
|
282
|
+
updates.push(`${col} = ?`);
|
|
283
|
+
params.push(args[field]);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (args.published !== undefined) {
|
|
288
|
+
updates.push('published = ?');
|
|
289
|
+
params.push(args.published ? 1 : 0);
|
|
290
|
+
} else if (args.status !== undefined) {
|
|
291
|
+
updates.push('published = ?');
|
|
292
|
+
params.push(args.status === 'publish' || args.status === 'published' ? 1 : 0);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (args.hidden !== undefined) {
|
|
296
|
+
updates.push('hidden = ?');
|
|
297
|
+
params.push(args.hidden ? 1 : 0);
|
|
298
|
+
}
|
|
299
|
+
if (args.hide_author !== undefined) {
|
|
300
|
+
updates.push('hide_author = ?');
|
|
301
|
+
params.push(args.hide_author ? 1 : 0);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (args.body_html) {
|
|
305
|
+
const words = args.body_html.replace(/<[^>]+>/g, ' ').trim().split(/\s+/).filter(Boolean);
|
|
306
|
+
updates.push('word_count = ?', 'reading_time_mins = ?');
|
|
307
|
+
params.push(words.length, Math.max(1, Math.ceil(words.length / 200)));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (updates.length === 0) {
|
|
311
|
+
return { id, status: 'no_changes' };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
updates.push("updated_at = strftime('%s','now')");
|
|
315
|
+
params.push(id, profileId);
|
|
316
|
+
|
|
317
|
+
await execute(`UPDATE content SET ${updates.join(', ')} WHERE id = ? AND profile_id = ?`, params);
|
|
318
|
+
|
|
319
|
+
return {
|
|
320
|
+
id,
|
|
321
|
+
status: 'updated',
|
|
322
|
+
updated_fields: Object.keys(args).filter((k) => k !== 'content_id_or_slug'),
|
|
323
|
+
};
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
];
|