getv2askanythinggeneratebrief
Generate concise account or deal briefs using workspace ID, CRM entity ID, and time period inputs to streamline business insights for gong-mcp.
Instructions
Generate account/deal brief
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| brief-name | Yes | ||
| crm-entity-id | Yes | ||
| entity-type | Yes | ||
| from-date-time | No | ||
| period-type | Yes | ||
| to-date-time | No | ||
| workspace-id | Yes |
Implementation Reference
- src/index.ts:273-382 (handler)Generic handler function that executes the tool by validating inputs with Zod (derived from inputSchema), constructing the API URL with path/query params, authenticating via Basic Auth using GONG_ACCESS_KEY and GONG_SECRET env vars, and calling the Gong API endpoint /v2/askanything/generate-brief via Axios.async function executeApiTool( toolName: string, definition: McpToolDefinition, toolArgs: JsonObject, allSecuritySchemes: Record<string, any> ): Promise<CallToolResult> { try { // Validate input arguments using Zod const zodSchema = getZodSchemaFromJsonSchema(definition.inputSchema, toolName); const validatedArgs = zodSchema.parse(toolArgs); // Build the request URL let url = API_BASE_URL + definition.pathTemplate; // Replace path parameters for (const param of definition.executionParameters) { if (param.in === 'path') { const value = validatedArgs[param.name]; if (value !== undefined) { url = url.replace(`{${param.name}}`, encodeURIComponent(value)); } } } // Build query parameters const queryParams: Record<string, string> = {}; for (const param of definition.executionParameters) { if (param.in === 'query') { const value = validatedArgs[param.name]; if (value !== undefined) { queryParams[param.name] = value; } } } if (Object.keys(queryParams).length > 0) { url += '?' + new URLSearchParams(queryParams).toString(); } // Debug logging (safe) console.error('Debug - Making API request to:', url); // Get credentials from environment const accessKey = process.env.GONG_ACCESS_KEY || ''; const secret = process.env.GONG_SECRET || ''; if (!accessKey || !secret) { throw new Error('Missing Gong credentials in environment'); } // Create authorization header const authHeader = `Basic ${Buffer.from(`${accessKey}:${secret}`).toString('base64')}`; // Build request config const config: AxiosRequestConfig = { method: definition.method, url, headers: { 'Accept': 'application/json', 'Authorization': authHeader } }; // Add request body if needed if (definition.requestBodyContentType) { config.headers!['Content-Type'] = definition.requestBodyContentType; if (validatedArgs.requestBody) { config.data = validatedArgs.requestBody; } } // Make the request const response = await axios(config); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2) } ] }; } catch (error: any) { if (error instanceof ZodError) { return { content: [{ type: 'text', text: `Validation error: ${error.message}` }] }; } if (axios.isAxiosError(error)) { return { content: [{ type: 'text', text: formatApiError(error) }] }; } return { content: [{ type: 'text', text: `Unexpected error: ${error.message}` }] }; } }
- src/index.ts:110-119 (registration)Registration of the tool in toolDefinitionMap, including name, description, inputSchema, HTTP method, path, parameters, and security requirements. Used by ListTools and CallTool handlers.["getv2askanythinggeneratebrief", { name: "getv2askanythinggeneratebrief", description: `Generate account/deal brief`, inputSchema: {"type":"object","properties":{"workspace-id":{"type":"string"},"brief-name":{"type":"string"},"entity-type":{"type":"string","enum":["Deal","Account"]},"crm-entity-id":{"type":"string"},"period-type":{"type":"string"},"from-date-time":{"type":"string","format":"date-time"},"to-date-time":{"type":"string","format":"date-time"}},"required":["workspace-id","brief-name","entity-type","crm-entity-id","period-type"]}, method: "get", pathTemplate: "/v2/askanything/generate-brief", executionParameters: [{"name":"workspace-id","in":"query"},{"name":"brief-name","in":"query"},{"name":"entity-type","in":"query"},{"name":"crm-entity-id","in":"query"},{"name":"period-type","in":"query"},{"name":"from-date-time","in":"query"},{"name":"to-date-time","in":"query"}], requestBodyContentType: undefined, securityRequirements: [{"basicAuth":[]}] }],
- src/index.ts:113-113 (schema)JSON Schema defining the input parameters for the tool: workspace-id, brief-name, entity-type (Deal/Account), crm-entity-id, period-type, optional from/to date-time.inputSchema: {"type":"object","properties":{"workspace-id":{"type":"string"},"brief-name":{"type":"string"},"entity-type":{"type":"string","enum":["Deal","Account"]},"crm-entity-id":{"type":"string"},"period-type":{"type":"string"},"from-date-time":{"type":"string","format":"date-time"},"to-date-time":{"type":"string","format":"date-time"}},"required":["workspace-id","brief-name","entity-type","crm-entity-id","period-type"]},
- src/index.ts:143-151 (handler)MCP CallTool request handler that looks up the tool definition by name and delegates execution to executeApiTool.server.setRequestHandler(CallToolRequestSchema, async (request: CallToolRequest): Promise<CallToolResult> => { const { name: toolName, arguments: toolArgs } = request.params; const toolDefinition = toolDefinitionMap.get(toolName); if (!toolDefinition) { console.error(`Error: Unknown tool requested: ${toolName}`); return { content: [{ type: "text", text: `Error: Unknown tool requested: ${toolName}` }] }; } return await executeApiTool(toolName, toolDefinition, toolArgs ?? {}, securitySchemes); });
- src/index.ts:462-477 (helper)Helper function to convert the tool's JSON inputSchema to a Zod schema for runtime validation in executeApiTool.function getZodSchemaFromJsonSchema(jsonSchema: any, toolName: string): z.ZodTypeAny { if (typeof jsonSchema !== 'object' || jsonSchema === null) { return z.object({}).passthrough(); } try { const zodSchemaString = jsonSchemaToZod(jsonSchema); const zodSchema = eval(zodSchemaString); if (typeof zodSchema?.parse !== 'function') { throw new Error('Eval did not produce a valid Zod schema.'); } return zodSchema as z.ZodTypeAny; } catch (err: any) { console.error(`Failed to generate/evaluate Zod schema for '${toolName}':`, err); return z.object({}).passthrough(); } }