feat(mcp): paginate record lists and describe document inputs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { limitFromArgs, offsetFromArgs, paginatedResult, paginationProperties } from "../pagination"
|
||||
import { and, asc, eq, ilike, isNull } from "drizzle-orm"
|
||||
import { wikiPages } from "../../../db/schema"
|
||||
import { McpContext, McpTool } from "../types"
|
||||
@@ -27,17 +28,7 @@ const pageIdArg = (args: Record<string, unknown>, key = "id") => {
|
||||
return value
|
||||
}
|
||||
|
||||
const limitFromArgs = (args: Record<string, unknown>) => {
|
||||
const value = Number(args.limit ?? 50)
|
||||
if (!Number.isFinite(value)) return 50
|
||||
return Math.min(Math.max(Math.trunc(value), 1), 100)
|
||||
}
|
||||
|
||||
const offsetFromArgs = (args: Record<string, unknown>) => {
|
||||
const value = Number(args.offset ?? 0)
|
||||
if (!Number.isFinite(value)) return 0
|
||||
return Math.max(Math.trunc(value), 0)
|
||||
}
|
||||
|
||||
export function prepareWikiScope(args: Record<string, unknown>): WikiScope {
|
||||
const entityType = stringArg(args, "entityType")
|
||||
@@ -144,8 +135,8 @@ export const wikiTools: McpTool[] = [
|
||||
...entityScopeProperties,
|
||||
query: { type: "string", description: "Optionaler Suchtext im Titel." },
|
||||
parentId: { type: ["string", "null"], format: "uuid", description: "Optional auf direkte Kinder dieses Ordners einschränken; null steht für die oberste Ebene." },
|
||||
limit: { type: "integer", minimum: 1, maximum: 100, default: 50 },
|
||||
offset: { type: "integer", minimum: 0, default: 0 },
|
||||
...paginationProperties,
|
||||
limit: { ...paginationProperties.limit, default: 50 },
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -173,11 +164,11 @@ export const wikiTools: McpTool[] = [
|
||||
})
|
||||
.from(wikiPages)
|
||||
.where(and(...conditions))
|
||||
.orderBy(asc(wikiPages.sortOrder), asc(wikiPages.title))
|
||||
.limit(limitFromArgs(args))
|
||||
.orderBy(asc(wikiPages.sortOrder), asc(wikiPages.title), wikiPages.id)
|
||||
.limit(limitFromArgs(args, 50) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args, 50)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user