Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion docs/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Both implementations share the same underlying tools, schemas, and utilities, en
- [Available Tools](#available-tools)
- [Feature Management](#feature-management)
- [Variable Management](#variable-management)
- [Custom Properties](#custom-properties)
- [Environment Management](#environment-management)
- [Project Management](#project-management)
- [SDK Installation](#sdk-installation)
- [Self-Targeting & Overrides](#self-targeting--overrides)
Expand Down Expand Up @@ -294,6 +296,83 @@ Delete a variable from ALL environments.

- `key`: Variable key to delete

### Custom Properties

Custom properties define the custom user data (`customData`) that audiences and targeting rules can target.

#### `list_custom_properties`

List all custom properties in the current project.

**Parameters:**

- `search` (optional): Search query to filter by name or key
- `page` (optional): Page number
- `perPage` (optional): Items per page
- `sortBy` (optional): Sort field (`createdAt`, `updatedAt`, `name`, `key`, `createdBy`, `propertyKey`)
- `sortOrder` (optional): Sort order (`asc`, `desc`)
- `type` (optional): Property type (`String`, `Boolean`, `Number`)

#### `create_custom_property`

Create a new custom property.

**Parameters:**

- `key`: Unique custom property key (pattern: `^[a-z0-9-_.]+$`)
- `name`: Display name
- `type`: Property type (`String`, `Boolean`, `Number`)
- `propertyKey`: The key in the user's `customData` that the SDK sends

#### `update_custom_property` ⚠️

Update an existing custom property.

**Parameters:**

- `key`: Custom property key to update
- `name` (optional): New name
- `type` (optional): New type
- `propertyKey` (optional): New `customData` key

#### `delete_custom_property` ⚠️⚠️

Delete a custom property from ALL environments.

**Parameters:**

- `key`: Custom property key to delete

### Environment Management

Use `select_project` or `get_current_project` to list environments and read their SDK keys.

#### `create_environment`

Create a new environment in the current project.

**Parameters:**

- `key`: Unique environment key (pattern: `^[a-z0-9-_.]+$`)
- `name`: Environment name
- `type`: Environment type (`development`, `staging`, `production`, `disaster_recovery`)
- `description` (optional): Environment description
- `color` (optional): Hex color (e.g. `#FF0000`)
- `settings` (optional): Environment settings

#### `update_environment` ⚠️

Update an existing environment.

**Parameters:**

- `key`: Environment key to update
- `name` (optional): New name
- `description` (optional): New description
- `color` (optional): New hex color
- `type` (optional): New environment type
- `settings` (optional): New environment settings

### Project Management

#### `get_current_project`
Expand Down Expand Up @@ -545,7 +624,7 @@ Key differences:

### Notes on Environments

- Dedicated environment tools are not exposed via MCP. Use `get_current_project` or `select_project` to retrieve environments and SDK keys for the selected project.
- There are no dedicated tools for listing environments or reading SDK keys. Use `get_current_project` or `select_project` to retrieve environments and SDK keys for the selected project, and `create_environment` / `update_environment` to manage them.

## Development & Local Testing

Expand Down
4 changes: 3 additions & 1 deletion mcp-worker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ All DevCycle CLI MCP tools are available. See [complete reference](../docs/mcp.m

**Variables**: `list_variables`, `create_variable`, `update_variable`, `delete_variable`

**Environments**: `list_environments`, `get_sdk_keys`
**Custom Properties**: `list_custom_properties`, `create_custom_property`, `update_custom_property`, `delete_custom_property`

**Environments**: `create_environment`, `update_environment`

**Self-Targeting**: `get_self_targeting_identity`, `update_self_targeting_identity`, `list_self_targeting_overrides`, `set_self_targeting_override`, `clear_feature_self_targeting_overrides`

Expand Down
31 changes: 19 additions & 12 deletions src/api/customProperties.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import { z } from 'zod'
import apiClient from './apiClient'
import { buildHeaders } from './common'
import { CreateCustomPropertyDto, UpdateCustomPropertyDto } from './zodSchemas'

const BASE_URL = '/v1/projects/:project/customProperties'

export const fetchCustomProperties = async (
token: string,
project_id: string,
queries: {
page?: number
perPage?: number
sortBy?:
| 'createdAt'
| 'updatedAt'
| 'name'
| 'key'
| 'createdBy'
| 'propertyKey'
sortOrder?: 'asc' | 'desc'
search?: string
type?: 'String' | 'Boolean' | 'Number'
} = {},
) => {
return apiClient.get(`${BASE_URL}`, {
headers: buildHeaders(token),
params: {
project: project_id,
},
queries,
})
}

export const createCustomProperty = async (
token: string,
project_id: string,
data: {
name: string
key: string
type: 'String' | 'Boolean' | 'Number'
propertyKey: string
},
data: z.infer<typeof CreateCustomPropertyDto>,
) => {
return apiClient.post(`${BASE_URL}`, data, {
headers: buildHeaders(token),
Expand All @@ -37,12 +49,7 @@ export const updateCustomProperty = async (
token: string,
project_id: string,
key: string,
data: {
name?: string
key?: string
propertyKey?: string
type?: 'String' | 'Boolean' | 'Number'
},
data: z.infer<typeof UpdateCustomPropertyDto>,
) => {
return apiClient.patch(`${BASE_URL}/:key`, data, {
headers: buildHeaders(token),
Expand Down
11 changes: 11 additions & 0 deletions src/mcp/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ describe('DevCycleMCPServer', () => {
expect(registeredToolNames).to.include(
'get_self_targeting_identity',
)
expect(registeredToolNames).to.include.members([
'list_custom_properties',
'create_custom_property',
'update_custom_property',
'delete_custom_property',
'create_environment',
'update_environment',
])
// Covered by select_project
expect(registeredToolNames).to.not.include('list_environments')
expect(registeredToolNames).to.not.include('get_sdk_keys')
})

it('should register tools with proper configurations', () => {
Expand Down
127 changes: 127 additions & 0 deletions src/mcp/tools/customPropertiesTools.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { expect } from '@oclif/test'
import sinon from 'sinon'
import nock from 'nock'
import { BASE_URL } from '../../api/common'
import { DevCycleApiClient } from '../utils/api'
import { DevCycleAuth } from '../utils/auth'
import {
listCustomPropertiesHandler,
createCustomPropertyHandler,
updateCustomPropertyHandler,
deleteCustomPropertyHandler,
} from './customPropertiesTools'

const customProperty = {
_id: '61450f3daec96f5cf4a49970',
_project: '61450f3daec96f5cf4a49950',
key: 'plan',
name: 'Plan',
_createdBy: 'user-id',
propertyKey: 'plan',
type: 'String',
createdAt: '2025-07-24T19:41:53.000Z',
updatedAt: '2025-07-24T19:41:53.000Z',
}

describe('customPropertiesTools', () => {
let apiClient: DevCycleApiClient

beforeEach(() => {
const authStub = sinon.createStubInstance(DevCycleAuth)
authStub.getAuthToken.returns('mock-auth-token')
authStub.getProjectKey.returns('selected-project')
authStub.getOrgId.returns('test-org-id')
apiClient = new DevCycleApiClient(authStub)
})

afterEach(() => {
sinon.restore()
nock.cleanAll()
})

it('lists custom properties, forwarding filters but not projectKey', async () => {
const scope = nock(BASE_URL)
.get('/v1/projects/arg-project/customProperties')
.query({ search: 'plan', type: 'String', perPage: '50' })
.reply(200, [customProperty])

const response = await listCustomPropertiesHandler(
{
projectKey: 'arg-project',
search: 'plan',
type: 'String',
perPage: 50,
},
apiClient,
)

expect(scope.isDone()).to.equal(true)
expect(response.result).to.eql([customProperty])
expect(response.dashboardLink).to.equal(
'https://app.devcycle.com/o/test-org-id/p/arg-project/custom-properties',
)
})

it('creates a custom property in the selected project', async () => {
let body: Record<string, unknown> = {}
const scope = nock(BASE_URL)
.post('/v1/projects/selected-project/customProperties', (b) => {
body = b
return true
})
.reply(201, customProperty)

await createCustomPropertyHandler(
{
key: 'plan',
name: 'Plan',
type: 'String',
propertyKey: 'plan',
},
apiClient,
)

expect(scope.isDone()).to.equal(true)
expect(body).to.eql({
key: 'plan',
name: 'Plan',
type: 'String',
propertyKey: 'plan',
})
})

it('updates a custom property by key without sending key or projectKey in the body', async () => {
let body: Record<string, unknown> = {}
const scope = nock(BASE_URL)
.patch('/v1/projects/arg-project/customProperties/plan', (b) => {
body = b
return true
})
.reply(200, { ...customProperty, name: 'Billing Plan' })

const response = await updateCustomPropertyHandler(
{ projectKey: 'arg-project', key: 'plan', name: 'Billing Plan' },
apiClient,
)

expect(scope.isDone()).to.equal(true)
expect(body).to.eql({ name: 'Billing Plan' })
expect(response.result).to.include({ name: 'Billing Plan' })
})

it('deletes a custom property', async () => {
const scope = nock(BASE_URL)
.delete('/v1/projects/selected-project/customProperties/plan')
.reply(200)

const response = await deleteCustomPropertyHandler(
{ key: 'plan' },
apiClient,
)

expect(scope.isDone()).to.equal(true)
expect(response.result).to.eql({
message: "Custom property 'plan' deleted successfully",
})
})
})
Loading