list_segments
Retrieve all segments within a specified namespace to manage and evaluate feature flag targeting and user groupings effectively.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| namespaceKey | Yes |
Implementation Reference
- src/index.ts:428-453 (handler)The MCP tool handler function for 'list_segments' that fetches segments via fliptClient.listSegments, formats the response as JSON text content with metadata URI, or returns an error response.try { const segments = await fliptClient.listSegments(args.namespaceKey); return { content: [ { type: 'text', text: JSON.stringify(segments, null, 2), }, ], _meta: { uri: `flipt://namespaces/${args.namespaceKey}/segments`, }, }; } catch (error: any) { console.error(`Error listing segments for namespace ${args.namespaceKey}:`, error); return { content: [ { type: 'text', text: `Failed to list segments: ${error.message}`, }, ], isError: true, }; } }
- src/index.ts:425-427 (schema)Zod input schema for the 'list_segments' tool, requiring a non-empty namespaceKey string.namespaceKey: z.string().min(1), }, async args => {
- src/index.ts:423-454 (registration)Registration of the 'list_segments' MCP tool using server.tool, including name, schema, and handler.'list_segments', { namespaceKey: z.string().min(1), }, async args => { try { const segments = await fliptClient.listSegments(args.namespaceKey); return { content: [ { type: 'text', text: JSON.stringify(segments, null, 2), }, ], _meta: { uri: `flipt://namespaces/${args.namespaceKey}/segments`, }, }; } catch (error: any) { console.error(`Error listing segments for namespace ${args.namespaceKey}:`, error); return { content: [ { type: 'text', text: `Failed to list segments: ${error.message}`, }, ], isError: true, }; } } );
- src/services/fliptClient.ts:279-292 (helper)Helper method in FliptClient class that invokes the generated SegmentsServiceApi.listSegments, extracts segments from response, and handles errors by returning empty array.async listSegments(namespaceKey: string) { try { const response = await this.segmentsApi.listSegments(namespaceKey); if (response && response.segments) { return response.segments; } else { console.error('Unexpected response structure:', response); return []; } } catch (error) { console.error(`Error getting segments for namespace ${namespaceKey}:`, error); return []; } }