Skip to content

Commit 3049529

Browse files
committed
improvement(search-mcp): log the field names a rejected tool call's arguments carry
1 parent 86817f3 commit 3049529

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { toolCallInputIssues } from '@/lib/knowledge/mcp/tool-arguments'
6+
7+
const searchCall = (args: Record<string, unknown>) => ({
8+
jsonrpc: '2.0',
9+
id: 1,
10+
method: 'tools/call',
11+
params: { name: 'search', arguments: args },
12+
})
13+
14+
describe('toolCallInputIssues', () => {
15+
it('names the fields a native query carries that the schema does not know', () => {
16+
const issues = toolCallInputIssues(
17+
searchCall({
18+
query: 'roadmap',
19+
nativeQueries: [{ provider: 'jira', query: 'roadmap', limit: 5 }],
20+
})
21+
)
22+
expect(issues?.issues).toContainEqual({
23+
code: 'unrecognized_keys',
24+
path: 'nativeQueries.0',
25+
keys: ['limit'],
26+
})
27+
})
28+
})

‎apps/sim/lib/knowledge/mcp/tool-arguments.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ export function repairToolCallMessage(message: Record<string, unknown>) {
8787
return { message: { ...message, params: { ...call, arguments: args } }, repairs: [...repairs] }
8888
}
8989

90+
/** Unrecognized field names a rejection records, each cut short, so a log line stays bounded. */
91+
const MAX_LOGGED_KEYS = 5
92+
const MAX_LOGGED_KEY_CHARACTERS = 64
93+
9094
/**
9195
* Where a tool call's arguments fail its input schema, as field paths and issue codes without
92-
* values. The SDK rejects such a call before the tool runs, so nothing else records it.
96+
* values, plus the names of fields the schema does not know, so a repeated client mistake can be
97+
* told apart from a new one. The SDK rejects such a call before the tool runs, so nothing else
98+
* records it.
9399
*/
94100
export function toolCallInputIssues(message: Record<string, unknown>) {
95101
const call = readToolCall(message)
@@ -99,6 +105,14 @@ export function toolCallInputIssues(message: Record<string, unknown>) {
99105
if (parsed.success) return undefined
100106
return {
101107
toolName: call.name,
102-
issues: parsed.error.issues.map(({ code, path }) => ({ code, path: path.join('.') })),
108+
issues: parsed.error.issues.map((issue) => ({
109+
code: issue.code,
110+
path: issue.path.join('.'),
111+
...(issue.code === 'unrecognized_keys' && {
112+
keys: issue.keys
113+
.slice(0, MAX_LOGGED_KEYS)
114+
.map((key) => key.slice(0, MAX_LOGGED_KEY_CHARACTERS)),
115+
}),
116+
})),
103117
}
104118
}

0 commit comments

Comments
 (0)