Skip to content

Commit d91053b

Browse files
fix(mcp-server): return prompt validation errors for invalid networks (#345)
* fix(mcp-server): return validation errors for invalid networks Co-authored-by: Cursor <cursoragent@cursor.com> * chore(mcp-server): add prompt validation changeset Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5d52ab3 commit d91053b

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sei-js/mcp-server': patch
3+
---
4+
5+
Return MCP validation errors for unsupported `compare_networks` entries instead of throwing an internal error.

‎packages/mcp-server/src/core/prompts.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@ import { isWalletEnabled } from './config.js';
55

66
const networkListSchema = z
77
.string()
8-
.superRefine((value, context) => {
8+
.transform((value, context) => {
99
const networks = value.split(',').map((network) => network.trim());
1010
if (networks.length === 0 || networks.some((network) => network.length === 0)) {
1111
context.addIssue({ code: z.ZodIssueCode.custom, message: 'At least one supported network is required.' });
12-
return;
12+
return z.NEVER;
1313
}
14+
15+
const normalizedNetworks: string[] = [];
1416
for (const network of networks) {
1517
try {
16-
normalizeNetwork(network);
18+
normalizedNetworks.push(normalizeNetwork(network));
1719
} catch {
1820
context.addIssue({ code: z.ZodIssueCode.custom, message: `Unsupported network: ${network}` });
1921
}
2022
}
23+
24+
return normalizedNetworks.length === networks.length ? normalizedNetworks.join(',') : z.NEVER;
2125
})
22-
.transform((value) =>
23-
value
24-
.split(',')
25-
.map((network) => normalizeNetwork(network.trim()))
26-
.join(',')
27-
)
2826
.describe("Comma-separated supported networks (for example, 'sei,1328' or '0x531,sei-testnet').");
2927

3028
/**

0 commit comments

Comments
 (0)