update_segment
Modify feature flag segments in Flipt MCP Server by updating namespace, key, name, match type, and description to refine targeting and behavior for AI-driven interactions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | ||
| key | Yes | ||
| matchType | Yes | ||
| name | Yes | ||
| namespaceKey | Yes |
Implementation Reference
- src/index.ts:547-601 (handler)MCP tool handler for 'update_segment': retrieves current segment, merges provided updates (name, description, matchType), calls fliptClient.updateSegment, and returns the updated segment or error.async args => { try { const currentSegment = await fliptClient.getSegment(args.namespaceKey, args.key); if (!currentSegment) { return { content: [ { type: 'text', text: `Segment ${args.key} in namespace ${args.namespaceKey} not found`, }, ], isError: true, }; } // update changed fields const updatedSegment = { ...currentSegment, name: args.name || currentSegment.name, description: args.description || currentSegment.description, matchType: args.matchType || currentSegment.matchType, }; const segment = await fliptClient.updateSegment( currentSegment.namespaceKey!, currentSegment.key!, updatedSegment.name!, updatedSegment.description, updatedSegment.matchType ); return { content: [ { type: 'text', text: JSON.stringify(segment, null, 2), }, ], _meta: { uri: `flipt://namespaces/${args.namespaceKey}/segments/${args.key}`, }, }; } catch (error: any) { console.error('Error updating segment:', error); return { content: [ { type: 'text', text: `Failed to update segment: ${error.message}`, }, ], isError: true, }; } }
- src/index.ts:540-546 (schema)Zod input schema defining parameters for the update_segment tool: namespaceKey, key, name (required), description and matchType (optional with enum).{ namespaceKey: z.string().min(1), key: z.string().min(1), name: z.string().min(1), description: z.string().optional(), matchType: z.enum(['ALL_MATCH_TYPE', 'ANY_MATCH_TYPE']), },
- src/index.ts:538-602 (registration)Registration of the 'update_segment' MCP tool using server.tool, including schema and inline handler function.server.tool( 'update_segment', { namespaceKey: z.string().min(1), key: z.string().min(1), name: z.string().min(1), description: z.string().optional(), matchType: z.enum(['ALL_MATCH_TYPE', 'ANY_MATCH_TYPE']), }, async args => { try { const currentSegment = await fliptClient.getSegment(args.namespaceKey, args.key); if (!currentSegment) { return { content: [ { type: 'text', text: `Segment ${args.key} in namespace ${args.namespaceKey} not found`, }, ], isError: true, }; } // update changed fields const updatedSegment = { ...currentSegment, name: args.name || currentSegment.name, description: args.description || currentSegment.description, matchType: args.matchType || currentSegment.matchType, }; const segment = await fliptClient.updateSegment( currentSegment.namespaceKey!, currentSegment.key!, updatedSegment.name!, updatedSegment.description, updatedSegment.matchType ); return { content: [ { type: 'text', text: JSON.stringify(segment, null, 2), }, ], _meta: { uri: `flipt://namespaces/${args.namespaceKey}/segments/${args.key}`, }, }; } catch (error: any) { console.error('Error updating segment:', error); return { content: [ { type: 'text', text: `Failed to update segment: ${error.message}`, }, ], isError: true, }; } } );
- src/services/fliptClient.ts:244-267 (helper)FliptClient service method that maps parameters to UpdateSegmentRequest and calls the generated segmentsApi.updateSegment.async updateSegment( namespaceKey: string, key: string, name: string, description?: string, matchType?: string ) { try { const segmentMatchType = matchType === 'ALL_MATCH_TYPE' ? UpdateSegmentRequestMatchTypeEnum.AllMatchType : UpdateSegmentRequestMatchTypeEnum.AnyMatchType; const response = await this.segmentsApi.updateSegment(namespaceKey, key, { name, description, matchType: segmentMatchType, }); return response; } catch (error) { console.error('Error updating segment:', error); throw error; } }