-
Notifications
You must be signed in to change notification settings - Fork 51
fix(mcp-server): return prompt validation errors for invalid networks #345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sei-js/mcp-server': patch | ||
| --- | ||
|
|
||
| Return MCP validation errors for unsupported `compare_networks` entries instead of throwing an internal error. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,26 +5,24 @@ import { isWalletEnabled } from './config.js'; | |
|
|
||
| const networkListSchema = z | ||
| .string() | ||
| .superRefine((value, context) => { | ||
| .transform((value, context) => { | ||
| const networks = value.split(',').map((network) => network.trim()); | ||
| if (networks.length === 0 || networks.some((network) => network.length === 0)) { | ||
| context.addIssue({ code: z.ZodIssueCode.custom, message: 'At least one supported network is required.' }); | ||
| return; | ||
| return z.NEVER; | ||
| } | ||
|
|
||
| const normalizedNetworks: string[] = []; | ||
| for (const network of networks) { | ||
| try { | ||
| normalizeNetwork(network); | ||
| normalizedNetworks.push(normalizeNetwork(network)); | ||
| } catch { | ||
| context.addIssue({ code: z.ZodIssueCode.custom, message: `Unsupported network: ${network}` }); | ||
| } | ||
| } | ||
|
|
||
| return normalizedNetworks.length === networks.length ? normalizedNetworks.join(',') : z.NEVER; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] The Not worth blocking on — if you prefer keeping it as belt-and-braces against a future edit that pushes to the array on the failure path, that's a reasonable call. |
||
| }) | ||
| .transform((value) => | ||
| value | ||
| .split(',') | ||
| .map((network) => normalizeNetwork(network.trim())) | ||
| .join(',') | ||
| ) | ||
| .describe("Comma-separated supported networks (for example, 'sei,1328' or '0x531,sei-testnet')."); | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Using
normalizedNetworks.length === networks.lengthas the success signal works today, but it's an indirect proxy for "no issues were added" and would silently break if thecatchever pushed a fallback value. A explicit flag reads more clearly and is robust to that: