Skip to content

Commit e60dc19

Browse files
committed
fix(search-mcp): state the people search word cap and always send report counts
1 parent 93fb876 commit e60dc19

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎apps/sim/lib/api/contracts/knowledge/mcp.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
} from '@/lib/api/contracts/mothership-assistant-tools'
99
import { organizationIdSchema } from '@/lib/api/contracts/primitives'
1010
import { defineRouteContract } from '@/lib/api/contracts/types'
11-
import { PEOPLE_ID_MAX_LENGTH, PEOPLE_SEARCH_MAX_LENGTH } from '@/lib/people/validation'
11+
import {
12+
PEOPLE_ID_MAX_LENGTH,
13+
PEOPLE_SEARCH_MAX_LENGTH,
14+
PEOPLE_SEARCH_MAX_TERMS,
15+
} from '@/lib/people/validation'
1216

1317
export const organizationKnowledgeMcpContract = defineRouteContract({
1418
method: 'POST',
@@ -136,7 +140,7 @@ export const searchPeopleMcpSchema = z
136140
.max(PEOPLE_SEARCH_MAX_LENGTH)
137141
.optional()
138142
.describe(
139-
'Words from a name, email, title, department, or location; a person matches when every word appears in one of them.'
143+
`Up to ${PEOPLE_SEARCH_MAX_TERMS} words from a name, email, title, department, or location; a person matches when every word appears in one of them.`
140144
),
141145
personId: z
142146
.string()

‎apps/sim/lib/knowledge/mcp/people.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function reportFacts(report: PersonSummary & { department: string | null; report
6262
return {
6363
...summaryFacts(report),
6464
...(report.department ? { department: report.department } : {}),
65-
...(report.reportCount ? { directReports: report.reportCount } : {}),
65+
directReports: report.reportCount,
6666
}
6767
}
6868

‎apps/sim/lib/people/repository.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { OrchestrationError } from '@/lib/core/orchestration/types'
2424
import { acquireAdvisoryXactLock, withLockTimeout } from '@/lib/db/advisory-locks'
2525
import type { DbOrTx, DbTransaction } from '@/lib/db/types'
2626
import type { PeopleImportMember } from '@/lib/people/import'
27-
import type { MemberProfileFields } from '@/lib/people/validation'
27+
import { type MemberProfileFields, PEOPLE_SEARCH_MAX_TERMS } from '@/lib/people/validation'
2828

2929
const PAGE_SIZE = 50
3030
/** A search matches people whose name, email, title, department, or location holds every word. */
@@ -35,7 +35,6 @@ const SEARCHED_COLUMNS = [
3535
sql`p.department`,
3636
sql`p.location`,
3737
]
38-
const MAX_SEARCH_TERMS = 8
3938
const MAX_CHAIN_DEPTH = 25
4039
const PROFILE_LOCK_TIMEOUT_MS = 5_000
4140
/** Eight bound parameters a row keeps a chunk far below Postgres's 65,535-parameter limit. */
@@ -181,7 +180,7 @@ export async function listPeople(
181180
: department
182181
? eq(sql`p.department`, department)
183182
: undefined
184-
const terms = search?.trim().split(/\s+/).filter(Boolean).slice(0, MAX_SEARCH_TERMS) ?? []
183+
const terms = search?.trim().split(/\s+/).filter(Boolean).slice(0, PEOPLE_SEARCH_MAX_TERMS) ?? []
185184
const where = and(
186185
...terms.map((term) => or(...SEARCHED_COLUMNS.map((column) => searchFilter(column, term)))),
187186
departmentFilter,

‎apps/sim/lib/people/validation.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { z } from 'zod'
22

33
export const PEOPLE_SEARCH_MAX_LENGTH = 200
4+
/** Words a people search matches; later words are ignored. */
5+
export const PEOPLE_SEARCH_MAX_TERMS = 8
46
export const PEOPLE_ID_MAX_LENGTH = 255
57
export const PEOPLE_DEPARTMENT_KEY_PATTERN = /^[0-9a-f]{64}$/
68
export const PROFILE_TEXT_MAX_LENGTH = 200

0 commit comments

Comments
 (0)