list_lostreasons
Retrieve all configured opportunity-loss reasons to analyze closed-lost opportunities. Understand why deals are lost to improve sales processes.
Instructions
List all configured opportunity-loss reasons (e.g. 'Poor Qualification', 'Lost to competitor'). Useful for analysing closed-lost opportunities by reason.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | ||
| perPage | No | Page size, max 100. Defaults to 100 for reference data. |
Implementation Reference
- src/tools/metadata.ts:42-51 (handler)The handler function and schema for list_lostreasons. Makes a GET request to /lostreasons with pagination and returns the data (including lostReasons array) plus a nextPage cursor.
export const listLostReasonsSchema = z.object({ ...paginationFields }); export async function listLostReasons(input: z.infer<typeof listLostReasonsSchema>) { // Note response key: `lostReasons` (camelCase plural). const { data, nextPage } = await capsuleGet<{ lostReasons: unknown[] }>("/lostreasons", { page: input.page ?? 1, perPage: input.perPage ?? 100, }); return { ...data, nextPage }; } - src/tools/metadata.ts:42-42 (schema)Zod schema for list_lostreasons input: accepts optional page (positive int) and perPage (1-100, defaults to 100) fields via spread of paginationFields.
export const listLostReasonsSchema = z.object({ ...paginationFields }); - src/server.ts:887-893 (registration)Registration of the 'list_lostreasons' tool via registerTool helper, with description and reference to the schema/handler imported from metadata.ts.
registerTool( server, "list_lostreasons", "List all configured opportunity-loss reasons (e.g. 'Poor Qualification', 'Lost to competitor'). Useful for analysing closed-lost opportunities by reason.", listLostReasonsSchema, listLostReasons, ); - src/server/register-tool.ts:39-59 (helper)The registerTool helper that wraps the handler in MCP's text-content response format and registers it on the McpServer.
export function registerTool<Schema extends z.ZodObject<ZodRawShape>>( server: McpServer, name: string, description: string, schema: Schema, handler: (input: z.infer<Schema>) => Promise<unknown>, ): void { // Use the SDK config-form registerTool with the full Zod schema. The // deprecated shape overload rebuilds z.object(schema.shape), which drops // object-level refinements such as superRefine. const registerWithSchema = server.registerTool.bind(server) as ( toolName: string, config: { description: string; inputSchema: Schema }, callback: (input: z.infer<Schema>) => Promise<CallToolResult>, ) => void; registerWithSchema(name, { description, inputSchema: schema }, async (input) => { const result = await handler(input); return wrapAsText(result); }); } - src/tools/opportunities.ts:165-172 (helper)Reference to list_lostreasons in the lostReasonId field description of the opportunity update schema - tells users to discover valid IDs via list_lostreasons.
lostReasonId: z .number() .int() .positive() .optional() .describe( "Reason the opportunity was lost. Only meaningful when transitioning to a Lost milestone — Capsule silently drops it for other milestones. Without this set, a connector-driven Lost-close leaves `lostReason: null`. Discover IDs via list_lostreasons.", ),