Skip to content

Commit abce5c3

Browse files
committed
Merge remote-tracking branch 'origin/feature/check-publish-status-publisher-plugin' into publisher-plugin-test
2 parents ad2363c + 1abe45d commit abce5c3

2 files changed

Lines changed: 39 additions & 24 deletions

File tree

packages/plugin-dkg-publisher/src/mcp/tools.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ export function registerMcpTools(mcp: any, serviceContainer: ServiceContainer |
133133
"knowledge-asset-list-recent",
134134
{
135135
title: "List Recent Knowledge Assets",
136-
description: "Show, list, or display recent knowledge assets. Use when user asks 'show me recent assets', 'what was published', 'last X assets', etc. Can filter by status (published, failed, publishing, queued). Always returns up to 20 most recent assets (capped at 20).",
136+
description: "Show, list, or display recent knowledge assets. Use when user asks 'show me recent assets', 'what was published', 'last X assets', 'publishes 200-500', etc. Can filter by status (published, failed, publishing, queued). Supports pagination with offset for large queries.",
137137
inputSchema: {
138-
limit: z.number().min(1).max(20).default(5).optional().describe("Number of assets to return (1-20, default: 5)"),
138+
limit: z.number().min(1).default(20).optional().describe("Number of assets to return (default: 20)"),
139+
offset: z.number().min(0).default(0).optional().describe("Number of assets to skip (for pagination, default: 0)"),
139140
status: z.enum(["published", "failed", "publishing", "queued"]).optional().describe("Filter by status (optional)"),
140141
},
141142
},
@@ -145,34 +146,39 @@ export function registerMcpTools(mcp: any, serviceContainer: ServiceContainer |
145146
}
146147

147148
const assetService = serviceContainer.get<AssetService>("assetService");
149+
148150
const assetsList = await assetService.getRecentAssets(
149-
input.limit || 5,
151+
input.limit,
150152
input.status,
153+
input.offset,
151154
);
152155

153156
if (assetsList.length === 0) {
154157
const statusFilter = input.status ? ` with status '${input.status}'` : '';
158+
const rangeText = input.offset > 0 ? ` (range ${input.offset + 1}-${input.offset + input.limit})` : '';
155159
return {
156160
content: [
157161
{
158162
type: "text",
159-
text: `No assets found${statusFilter}.\n\nNo knowledge assets have been published yet.`,
163+
text: `No assets found${statusFilter}${rangeText}.\n\nNo knowledge assets in this range.`,
160164
},
161165
],
162166
};
163167
}
164168

165-
const requestedLimit = input.limit || 5;
166169
const statusFilter = input.status ? ` ${input.status}` : '';
167-
let resultText = `**Last ${assetsList.length}${statusFilter} Assets** (showing most recent, max ${requestedLimit})\n\n`;
170+
const rangeStart = input.offset + 1;
171+
const rangeEnd = input.offset + assetsList.length;
172+
const rangeText = input.offset > 0 ? ` (${rangeStart}-${rangeEnd})` : '';
173+
let resultText = `**${assetsList.length}${statusFilter} Assets${rangeText}**\n\n`;
168174

169175
const db = serviceContainer.get<Database>("db");
170176

171177
// Fetch content IDs for each asset
172178
for (let idx = 0; idx < assetsList.length; idx++) {
173179
const asset = assetsList[idx];
174180

175-
// Try to extract Content ID from stored content
181+
// Attempt to extract Content ID (@id) from the stored JSON-LD content file
176182
let contentId = "Unknown";
177183
try {
178184
const [dbAsset] = await db
@@ -192,7 +198,7 @@ export function registerMcpTools(mcp: any, serviceContainer: ServiceContainer |
192198
}
193199
}
194200
} catch (e) {
195-
// Keep as "Unknown"
201+
console.warn(`Failed to extract Content ID for asset ${asset.id}:`, e instanceof Error ? e.message : String(e));
196202
}
197203

198204
resultText += formatAssetStatus({
@@ -220,10 +226,11 @@ export function registerMcpTools(mcp: any, serviceContainer: ServiceContainer |
220226
"knowledge-asset-query-by-status",
221227
{
222228
title: "Find Knowledge Assets by Status",
223-
description: "Find, show, list, or query knowledge assets by publishing status. Use when user asks 'show me all published', 'failed assets', 'what's publishing', etc. Supports statuses: published (successfully published), failed (publishing failed), publishing (currently being published), queued (waiting to publish). Always returns up to 20 most recent assets matching the status (capped at 20).",
229+
description: "Find, show, list, or query knowledge assets by publishing status. Use when user asks 'show me all published', 'failed assets', 'what's publishing', 'publishes 100-200', etc. Supports statuses: published (successfully published), failed (publishing failed), publishing (currently being published), queued (waiting to publish). Supports pagination with offset for large queries.",
224230
inputSchema: {
225231
status: z.enum(["published", "failed", "publishing", "queued"]).describe("The status to filter by"),
226-
limit: z.number().min(1).max(20).default(10).optional().describe("Maximum number of results (1-20, default: 10)"),
232+
limit: z.number().min(1).default(20).optional().describe("Maximum number of results (default: 20)"),
233+
offset: z.number().min(0).default(0).optional().describe("Number of assets to skip (for pagination, default: 0)"),
227234
},
228235
},
229236
async (input: any, req: any) => {
@@ -232,33 +239,38 @@ export function registerMcpTools(mcp: any, serviceContainer: ServiceContainer |
232239
}
233240

234241
const assetService = serviceContainer.get<AssetService>("assetService");
242+
235243
const assetsList = await assetService.getAssetsByStatusForDisplay(
236244
input.status,
237-
input.limit || 10,
245+
input.limit,
246+
input.offset,
238247
);
239248

240249
if (assetsList.length === 0) {
250+
const rangeText = input.offset > 0 ? ` (range ${input.offset + 1}-${input.offset + input.limit})` : '';
241251
return {
242252
content: [
243253
{
244254
type: "text",
245-
text: `No assets found with status: ${input.status}\n\n` +
246-
`No ${input.status} knowledge assets found.`,
255+
text: `No assets found with status: ${input.status}${rangeText}\n\n` +
256+
`No ${input.status} knowledge assets in this range.`,
247257
},
248258
],
249259
};
250260
}
251261

252-
const requestedLimit = input.limit || 10;
253-
let resultText = `**Last ${assetsList.length} ${input.status.toUpperCase()} Assets** (showing most recent, max ${requestedLimit})\n\n`;
262+
const rangeStart = input.offset + 1;
263+
const rangeEnd = input.offset + assetsList.length;
264+
const rangeText = input.offset > 0 ? ` (${rangeStart}-${rangeEnd})` : '';
265+
let resultText = `**${assetsList.length} ${input.status.toUpperCase()} Assets${rangeText}**\n\n`;
254266

255267
const db = serviceContainer.get<Database>("db");
256268

257269
// Fetch content IDs for each asset
258270
for (let idx = 0; idx < assetsList.length; idx++) {
259271
const asset = assetsList[idx];
260272

261-
// Try to extract Content ID from stored content
273+
// Attempt to extract Content ID (@id) from the stored JSON-LD content file
262274
let contentId = "Unknown";
263275
try {
264276
const [dbAsset] = await db
@@ -278,7 +290,7 @@ export function registerMcpTools(mcp: any, serviceContainer: ServiceContainer |
278290
}
279291
}
280292
} catch (e) {
281-
// Keep as "Unknown"
293+
console.warn(`Failed to extract Content ID for asset ${asset.id}:`, e instanceof Error ? e.message : String(e));
282294
}
283295

284296
resultText += formatAssetStatus({

packages/plugin-dkg-publisher/src/services/AssetService.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,24 +596,25 @@ export class AssetService extends EventEmitter {
596596
* Get recent assets for display (all users, no filtering by userId)
597597
*/
598598
async getRecentAssets(
599-
limit: number = 5,
599+
limit: number = 20,
600600
statusFilter?: "published" | "failed" | "publishing" | "queued",
601+
offset: number = 0,
601602
): Promise<AssetStatus[]> {
602-
const cappedLimit = Math.min(limit, 20); // Cap at 20
603-
604603
let query = this.db
605604
.select()
606605
.from(assets)
607606
.orderBy(desc(assets.createdAt))
608-
.limit(cappedLimit);
607+
.limit(limit)
608+
.offset(offset);
609609

610610
if (statusFilter) {
611611
const results = await this.db
612612
.select()
613613
.from(assets)
614614
.where(eq(assets.status, statusFilter))
615615
.orderBy(desc(assets.createdAt))
616-
.limit(cappedLimit);
616+
.limit(limit)
617+
.offset(offset);
617618

618619
return results.map((asset) => ({
619620
id: asset.id,
@@ -646,14 +647,16 @@ export class AssetService extends EventEmitter {
646647
*/
647648
async getAssetsByStatusForDisplay(
648649
status: "published" | "failed" | "publishing" | "queued",
649-
limit: number = 10,
650+
limit: number = 20,
651+
offset: number = 0,
650652
): Promise<AssetStatus[]> {
651653
const results = await this.db
652654
.select()
653655
.from(assets)
654656
.where(eq(assets.status, status))
655657
.orderBy(desc(assets.createdAt))
656-
.limit(Math.min(limit, 20)); // Cap at 20
658+
.limit(limit)
659+
.offset(offset);
657660

658661
return results.map((asset) => ({
659662
id: asset.id,

0 commit comments

Comments
 (0)