feat(mcp): paginate record lists and describe document inputs

This commit is contained in:
2026-09-14 13:17:37 +02:00
parent 58fc252110
commit 342ad9764e
8 changed files with 302 additions and 123 deletions

View File

@@ -1,14 +1,10 @@
import { limitFromArgs, offsetFromArgs, paginatedResult, paginationProperties } from "../pagination"
import { and, desc, eq, ilike, or } from "drizzle-orm"
import { customers, events, plants, projects, tasks } from "../../../db/schema"
import { insertHistoryItem } from "../../utils/history"
import { activateProjectPhase } from "../projectPhases"
import { McpTool } from "../types"
const limitFromArgs = (args: Record<string, unknown>, fallback = 25) => {
const raw = Number(args.limit ?? fallback)
if (!Number.isFinite(raw)) return fallback
return Math.min(Math.max(Math.trunc(raw), 1), 100)
}
const stringArg = (args: Record<string, unknown>, key: string) => {
const value = args[key]
@@ -30,7 +26,7 @@ export const organisationTools: McpTool[] = [
type: "object",
properties: {
query: { type: "string", description: "Suchtext für Name, Kundennummer, Vorname, Nachname oder Notizen." },
limit: { type: "number", minimum: 1, maximum: 100 },
...paginationProperties,
},
},
async handler(context, args) {
@@ -62,10 +58,11 @@ export const organisationTools: McpTool[] = [
})
.from(customers)
.where(and(...conditions))
.orderBy(customers.name)
.limit(limitFromArgs(args))
.orderBy(customers.name, customers.id)
.limit(limitFromArgs(args) + 1)
.offset(offsetFromArgs(args))
return { rows }
return paginatedResult(rows, args)
},
},
{
@@ -79,7 +76,7 @@ export const organisationTools: McpTool[] = [
query: { type: "string", description: "Suchtext für Name, Projektnummer, Kundenreferenz oder Notizen." },
customer: { type: "number" },
activePhase: { type: "string" },
limit: { type: "number", minimum: 1, maximum: 100 },
...paginationProperties,
},
},
async handler(context, args) {
@@ -104,10 +101,11 @@ export const organisationTools: McpTool[] = [
.select()
.from(projects)
.where(and(...conditions))
.orderBy(desc(projects.createdAt))
.limit(limitFromArgs(args))
.orderBy(desc(projects.createdAt), projects.id)
.limit(limitFromArgs(args) + 1)
.offset(offsetFromArgs(args))
return { rows }
return paginatedResult(rows, args)
},
},
{
@@ -217,7 +215,7 @@ export const organisationTools: McpTool[] = [
properties: {
query: { type: "string", description: "Suchtext für Name." },
customer: { type: "number" },
limit: { type: "number", minimum: 1, maximum: 100 },
...paginationProperties,
},
},
async handler(context, args) {
@@ -233,10 +231,11 @@ export const organisationTools: McpTool[] = [
.select()
.from(plants)
.where(and(...conditions))
.orderBy(plants.name)
.limit(limitFromArgs(args))
.orderBy(plants.name, plants.id)
.limit(limitFromArgs(args) + 1)
.offset(offsetFromArgs(args))
return { rows }
return paginatedResult(rows, args)
},
},
{
@@ -251,7 +250,7 @@ export const organisationTools: McpTool[] = [
project: { type: "number" },
customer: { type: "number" },
eventtype: { type: "string" },
limit: { type: "number", minimum: 1, maximum: 100 },
...paginationProperties,
},
},
async handler(context, args) {
@@ -277,10 +276,11 @@ export const organisationTools: McpTool[] = [
.select()
.from(events)
.where(and(...conditions))
.orderBy(desc(events.startDate))
.limit(limitFromArgs(args))
.orderBy(desc(events.startDate), events.id)
.limit(limitFromArgs(args) + 1)
.offset(offsetFromArgs(args))
return { rows }
return paginatedResult(rows, args)
},
},
{
@@ -294,7 +294,7 @@ export const organisationTools: McpTool[] = [
query: { type: "string", description: "Suchtext für Name, Beschreibung oder Kategorie." },
project: { type: "number" },
customer: { type: "number" },
limit: { type: "number", minimum: 1, maximum: 100 },
...paginationProperties,
},
},
async handler(context, args) {
@@ -318,10 +318,11 @@ export const organisationTools: McpTool[] = [
.select()
.from(tasks)
.where(and(...conditions))
.orderBy(desc(tasks.createdAt))
.limit(limitFromArgs(args))
.orderBy(desc(tasks.createdAt), tasks.id)
.limit(limitFromArgs(args) + 1)
.offset(offsetFromArgs(args))
return { rows }
return paginatedResult(rows, args)
},
},
{