feat(mcp): paginate record lists and describe document inputs
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { outgoingAddressSchema, outgoingRowsSchema, outgoingReportSchema } from "../documentSchemas"
|
||||
import { limitFromArgs, offsetFromArgs, paginatedResult, paginationProperties } from "../pagination"
|
||||
import { and, desc, eq, ilike, or } from "drizzle-orm"
|
||||
import { randomUUID } from "node:crypto"
|
||||
import {
|
||||
@@ -27,11 +29,6 @@ import { McpTool } from "../types"
|
||||
|
||||
export { prepareStatementAllocationInput } from "../statementAllocations"
|
||||
|
||||
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]
|
||||
@@ -456,7 +453,7 @@ export const accountingTools: McpTool[] = [
|
||||
state: { type: "string", description: "Optionaler Statusfilter, z. B. Entwurf oder Gebucht." },
|
||||
customer: { type: "number" },
|
||||
project: { type: "number" },
|
||||
limit: { type: "number", minimum: 1, maximum: 100 },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -479,10 +476,11 @@ export const accountingTools: McpTool[] = [
|
||||
.select()
|
||||
.from(createddocuments)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(createddocuments.createdAt))
|
||||
.limit(limitFromArgs(args))
|
||||
.orderBy(desc(createddocuments.createdAt), createddocuments.id)
|
||||
.limit(limitFromArgs(args) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -542,12 +540,12 @@ export const accountingTools: McpTool[] = [
|
||||
description: { type: "string" },
|
||||
startText: { type: "string" },
|
||||
endText: { type: "string" },
|
||||
address: { type: "object" },
|
||||
rows: { type: "array" },
|
||||
address: outgoingAddressSchema,
|
||||
rows: outgoingRowsSchema,
|
||||
letterhead: { type: "number" },
|
||||
availableInPortal: { type: "boolean" },
|
||||
customSurchargePercentage: { type: "number" },
|
||||
report: { type: "object" },
|
||||
report: outgoingReportSchema,
|
||||
serialConfig: serialConfigSchema,
|
||||
},
|
||||
},
|
||||
@@ -598,12 +596,12 @@ export const accountingTools: McpTool[] = [
|
||||
description: { type: "string" },
|
||||
startText: { type: "string" },
|
||||
endText: { type: "string" },
|
||||
address: { type: "object" },
|
||||
rows: { type: "array" },
|
||||
address: outgoingAddressSchema,
|
||||
rows: outgoingRowsSchema,
|
||||
letterhead: { type: "number" },
|
||||
availableInPortal: { type: "boolean" },
|
||||
customSurchargePercentage: { type: "number" },
|
||||
report: { type: "object" },
|
||||
report: outgoingReportSchema,
|
||||
serialConfig: serialConfigSchema,
|
||||
},
|
||||
},
|
||||
@@ -720,8 +718,8 @@ export const accountingTools: McpTool[] = [
|
||||
enum: ["Standard", "13b UStG", "19 UStG", "12.3 UStG"],
|
||||
description: "Steuertyp des gesamten Ausgangsdokuments, nicht der einzelne USt-Satz einer Position.",
|
||||
},
|
||||
rows: { type: "array" },
|
||||
report: { type: "object" },
|
||||
rows: outgoingRowsSchema,
|
||||
report: outgoingReportSchema,
|
||||
availableInPortal: { type: "boolean" },
|
||||
},
|
||||
},
|
||||
@@ -803,7 +801,7 @@ export const accountingTools: McpTool[] = [
|
||||
type: "object",
|
||||
properties: {
|
||||
status: { type: "string", enum: ["draft", "completed", "error"] },
|
||||
limit: { type: "number", minimum: 1, maximum: 100 },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -815,10 +813,11 @@ export const accountingTools: McpTool[] = [
|
||||
.select()
|
||||
.from(serialExecutions)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(serialExecutions.createdAt))
|
||||
.limit(limitFromArgs(args))
|
||||
.orderBy(desc(serialExecutions.createdAt), serialExecutions.id)
|
||||
.limit(limitFromArgs(args) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -878,7 +877,7 @@ export const accountingTools: McpTool[] = [
|
||||
type: "object",
|
||||
properties: {
|
||||
query: { type: "string", description: "Suchtext für Kontonummer, Bezeichnung oder Beschreibung." },
|
||||
limit: { type: "number", minimum: 1, maximum: 100 },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -908,10 +907,11 @@ export const accountingTools: McpTool[] = [
|
||||
.select()
|
||||
.from(accounts)
|
||||
.where(whereCond)
|
||||
.orderBy(accounts.number)
|
||||
.limit(limit)
|
||||
.orderBy(accounts.number, accounts.id)
|
||||
.limit(limit + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { accountChart, rows }
|
||||
return { accountChart, ...paginatedResult(rows, args) }
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -924,7 +924,7 @@ export const accountingTools: McpTool[] = [
|
||||
properties: {
|
||||
state: { type: "string", description: "Optionaler Statusfilter." },
|
||||
paid: { type: "boolean", description: "Optionaler Zahlungsstatus." },
|
||||
limit: { type: "number", minimum: 1, maximum: 100 },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -939,10 +939,11 @@ export const accountingTools: McpTool[] = [
|
||||
.select()
|
||||
.from(incominginvoices)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(incominginvoices.createdAt))
|
||||
.limit(limitFromArgs(args))
|
||||
.orderBy(desc(incominginvoices.createdAt), incominginvoices.id)
|
||||
.limit(limitFromArgs(args) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -981,6 +982,7 @@ export const accountingTools: McpTool[] = [
|
||||
required: ["id"],
|
||||
properties: {
|
||||
id: { type: "number" },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -995,9 +997,11 @@ export const accountingTools: McpTool[] = [
|
||||
eq(files.tenant, context.tenantId),
|
||||
eq(files.archived, false)
|
||||
))
|
||||
.orderBy(desc(files.createdAt))
|
||||
.orderBy(desc(files.createdAt), files.id)
|
||||
.limit(limitFromArgs(args) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1311,7 +1315,7 @@ export const accountingTools: McpTool[] = [
|
||||
type: "object",
|
||||
properties: {
|
||||
account: { type: "number", description: "Optionale Bankkonto-ID." },
|
||||
limit: { type: "number", minimum: 1, maximum: 100 },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -1326,9 +1330,10 @@ export const accountingTools: McpTool[] = [
|
||||
.from(bankstatements)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(bankstatements.date), desc(bankstatements.id))
|
||||
.limit(limitFromArgs(args))
|
||||
.limit(limitFromArgs(args) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args)
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -1367,7 +1372,7 @@ export const accountingTools: McpTool[] = [
|
||||
properties: {
|
||||
bankstatement: { type: "number" },
|
||||
incominginvoice: { type: "number" },
|
||||
limit: { type: "number", minimum: 1, maximum: 100 },
|
||||
...paginationProperties,
|
||||
},
|
||||
},
|
||||
async handler(context, args) {
|
||||
@@ -1383,10 +1388,11 @@ export const accountingTools: McpTool[] = [
|
||||
.select()
|
||||
.from(statementallocations)
|
||||
.where(and(...conditions))
|
||||
.orderBy(desc(statementallocations.created_at))
|
||||
.limit(limitFromArgs(args))
|
||||
.orderBy(desc(statementallocations.created_at), statementallocations.id)
|
||||
.limit(limitFromArgs(args) + 1)
|
||||
.offset(offsetFromArgs(args))
|
||||
|
||||
return { rows }
|
||||
return paginatedResult(rows, args)
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user