T-129: edits made in the worktree
This commit is contained in:
parent
73ac978bb3
commit
c48781811c
2 changed files with 38 additions and 13 deletions
|
|
@ -113,6 +113,24 @@ export interface McpToolDescriptor {
|
|||
readonly inputSchema: JsonSchemaObject;
|
||||
}
|
||||
|
||||
/** Valid MCP progress token (`string | finite number`). */
|
||||
export const mcpProgressTokenSchema = z.union([z.string(), z.number().finite()]);
|
||||
export type McpProgressToken = z.infer<typeof mcpProgressTokenSchema>;
|
||||
|
||||
/** Standard optional MCP `_meta` request/notification metadata bag. */
|
||||
export const mcpRequestMetaSchema = z
|
||||
.object({
|
||||
progressToken: mcpProgressTokenSchema.optional(),
|
||||
})
|
||||
.passthrough();
|
||||
export type McpRequestMeta = z.infer<typeof mcpRequestMetaSchema>;
|
||||
|
||||
const jsonObjectSchema = z.custom<Record<string, unknown>>(
|
||||
(value): value is Record<string, unknown> =>
|
||||
typeof value === 'object' && value !== null && !Array.isArray(value),
|
||||
{ message: 'Expected a JSON object.' }
|
||||
);
|
||||
|
||||
/** Strict MCP `initialize` params schema. */
|
||||
export const mcpInitializeParamsSchema = z
|
||||
.object({
|
||||
|
|
@ -125,27 +143,38 @@ export const mcpInitializeParamsSchema = z
|
|||
})
|
||||
.strict()
|
||||
.optional(),
|
||||
_meta: mcpRequestMetaSchema.optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
/** Strict MCP `notifications/initialized` params schema. */
|
||||
export const mcpInitializedNotificationParamsSchema = z.object({}).strict();
|
||||
export const mcpInitializedNotificationParamsSchema = z
|
||||
.object({
|
||||
_meta: mcpRequestMetaSchema.optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
/** Strict MCP `ping` params schema. */
|
||||
export const mcpPingParamsSchema = z.object({}).strict();
|
||||
export const mcpPingParamsSchema = z
|
||||
.object({
|
||||
_meta: mcpRequestMetaSchema.optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
/** Strict MCP `tools/list` params schema. */
|
||||
export const mcpToolsListParamsSchema = z
|
||||
.object({
|
||||
cursor: z.string().min(1).optional(),
|
||||
_meta: mcpRequestMetaSchema.optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
/** Strict MCP `tools/call` params schema. */
|
||||
/** Strict MCP `tools/call` params schema (preserves own keys on `arguments`). */
|
||||
export const mcpToolsCallParamsSchema = z
|
||||
.object({
|
||||
name: z.string().min(1),
|
||||
arguments: z.record(z.unknown()).optional(),
|
||||
arguments: jsonObjectSchema.optional(),
|
||||
_meta: mcpRequestMetaSchema.optional(),
|
||||
})
|
||||
.strict();
|
||||
|
||||
|
|
|
|||
|
|
@ -320,17 +320,13 @@ function formatZodIssues(error: z.ZodError): string {
|
|||
return parts.join('; ');
|
||||
}
|
||||
|
||||
const SAFE_ERROR_NAME_RE = /^[A-Za-z][A-Za-z0-9_]{0,63}$/;
|
||||
|
||||
function sanitizeToolError(err: unknown): string {
|
||||
if (err instanceof Error) {
|
||||
const rawName = typeof err.name === 'string' && err.name.trim().length > 0 ? err.name.trim() : 'Error';
|
||||
const firstLine = (typeof err.message === 'string' ? err.message : '')
|
||||
.split(/\r?\n/, 1)[0]
|
||||
?.replace(/\s+at\s+\S.*$/u, '')
|
||||
.trim();
|
||||
if (firstLine !== undefined && firstLine.length > 0) {
|
||||
return `${rawName}: ${firstLine}`;
|
||||
}
|
||||
return `${rawName}: Tool execution failed.`;
|
||||
const rawName = typeof err.name === 'string' ? err.name.trim() : '';
|
||||
const safeName = SAFE_ERROR_NAME_RE.test(rawName) ? rawName : 'Error';
|
||||
return `${safeName}: Tool execution failed.`;
|
||||
}
|
||||
return 'Error: Tool execution failed.';
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue