Skip to content

Commit 93fb876

Browse files
committed
fix(search-mcp): validate people lookup arguments and commit before validating the check
1 parent ad32c7b commit 93fb876

4 files changed

Lines changed: 31 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,7 @@ export const searchPeopleMcpSchema = z
154154
.describe('nextCursor from the previous page of the same query.'),
155155
})
156156
.strict()
157+
.refine((input) => !input.personId || (input.query === undefined && !input.cursor), {
158+
path: ['personId'],
159+
message: 'Pass either personId or a query with its cursor, not both.',
160+
})

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export function registerSearchPeopleTool(
105105
...(chain.length ? { managerChain: chain.map(summaryFacts) } : {}),
106106
...(reports.length ? { directReports: reports.map(reportFacts) } : {}),
107107
totalDirectReports: totalReports,
108+
...(totalReports > reports.length
109+
? {
110+
note: `directReports lists the first ${reports.length} of ${totalReports}; search by department or title to find the others.`,
111+
}
112+
: {}),
108113
},
109114
}
110115
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** BENCHMARK HARNESS ONLY: turns the per-org `people` flag on (staging AppConfig is unreachable without SSO). */
2+
import { plugin } from 'bun'
3+
4+
plugin({
5+
name: 'bench-people-flag',
6+
setup(build) {
7+
build.onLoad({ filter: /lib\/people\/feature-flag\.ts$/ }, async (args) => {
8+
const source = await Bun.file(args.path).text()
9+
const patched = source.replace(
10+
"return isFeatureEnabled('people', { orgId: organizationId })",
11+
'return Promise.resolve(true)'
12+
)
13+
if (patched === source) throw new Error('bench-people-flag: patch target not found')
14+
return { loader: 'ts', contents: patched }
15+
})
16+
},
17+
})
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
-- Admits the search_people Search MCP tool in activity rows. NOT VALID swaps the check as a metadata
2-
-- change in one statement, so no insert sees the table without one; VALIDATE then scans under a lock
3-
-- that does not block writes. Replay-safe: the drop is IF EXISTS and the re-added check is identical.
2+
-- change in one statement, so no insert sees the table without one. The COMMIT releases that
3+
-- statement's ACCESS EXCLUSIVE lock before VALIDATE scans the table under a lock that does not block
4+
-- writes. Replay-safe: the drop is IF EXISTS, the re-added check is identical, and validating twice
5+
-- is harmless.
46
-- migration-safe: only widens the allowed tool names; every row the deployed app writes still satisfies the check.
57
ALTER TABLE "organization_search_mcp_invocation"
68
DROP CONSTRAINT IF EXISTS "organization_search_mcp_invocation_tool_check",
79
ADD CONSTRAINT "organization_search_mcp_invocation_tool_check" CHECK ("organization_search_mcp_invocation"."tool_name" IN ('search', 'read_document', 'chat', 'search_people')) NOT VALID;--> statement-breakpoint
10+
COMMIT;--> statement-breakpoint
811
ALTER TABLE "organization_search_mcp_invocation" VALIDATE CONSTRAINT "organization_search_mcp_invocation_tool_check";

0 commit comments

Comments
 (0)