Skip to content

Commit 205d173

Browse files
feat: implement cloudflare worker for mcp sse protocol (#475)
* docs: add cloudflare worker implementation plan for mcp sse * feat: extract core tool logic into registry pattern - Create MCPToolRegistry interface and class for tool management - Add IDevCycleApiClient interface for API abstraction - Refactor project tools to use registry pattern - Add central tool registration coordination - Maintain backward compatibility with legacy exports - Add comprehensive registry tests (7 test cases) This enables sharing tool implementations between local and remote MCP servers while preserving existing functionality. Phase 1.1 of Cloudflare Worker plan. * feat: create abstracted API client interface for dual-mode operation - Add dedicated API interface module (src/mcp/api/interface.ts) - Create IDevCycleApiClient, IAuthContext, and factory interfaces - Implement LocalDevCycleApiClient wrapping existing DevCycleApiClient - Add WorkerDevCycleApiClient skeleton for Cloudflare Worker support - Move interface from registry to dedicated API module - Add comprehensive interface tests (8 test cases) - Create API abstraction documentation This enables same tool implementations to work with different auth strategies: - Local: file system, environment variables, SSO tokens - Worker: OAuth JWT tokens from Cloudflare Worker context Phase 1.2 of Cloudflare Worker plan. * refactor(mcp): eliminate duplication in tool definitions and make legacy exports single source of truth * refactor: consolidate tool registration into centralized registry pattern * feat: starting CF Worker MCP setup * feat: move MCP Worker logic to /mcp-worker * feat: MCP Worker auth mostly working * feat: calling MCP tools working now * feat: fix tests, add project selection tool * feat: add projectSelectionTools.ts * feat: new mcp tool format working with zod schemas * chore: fix missing file * feat: new format of tool calls working in worker + CLI * feat: cleanup no project error messages * feat: update worker to support HTTP and SSE * feat: re-use error handling * feat: add errorHandling.ts * docs: update mcp-worker README * docs: update mcp.md * feat: fix audit log query params and results * feat: update audit log types * feat: remove un-used registry, disable project/env create/update tools, disable custom props tools * feat: rename tool to: select_project * feat: combine enableTargeting/disableTargeting to set_feature_targeting tool * docs: update readmes * docs: update worker docs link * feat: setup yarn workspace for mcp-worker * fix: tests / linting * revert: restore README.md table of contents and formatting * chore: cleanup
1 parent 60a1651 commit 205d173

41 files changed

Lines changed: 13514 additions & 5198 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ tmp
99
.yarn/cache
1010
.yarn/install-state.gz
1111
tsconfig.tsbuildinfo
12+
13+
# MCP Worker build outputs
14+
mcp-worker/dist/
15+
mcp-worker/.wrangler/

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.12
1+
22.*

README.md

Lines changed: 112 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
DevCycle CLI
2-
=================
1+
DevCycle CLI & MCP Server
2+
=========================
33

4-
DevCycle CLI for interacting with DevCycle features from the command line.
4+
This repository contains the DevCycle CLI for managing feature flags from the command line, plus an MCP (Model Context Protocol) server that enables AI coding assistants to interact with DevCycle.
55

66
Major features include:
7+
78
- Fully manage your Features, Variables, Variations and Targeting Rules from the command line
89
- Detect and list DevCycle Variable usages in your codebase
910
- Manage your Self-Targeting Overrides to quickly switch between Variable values
@@ -17,34 +18,84 @@ The CLI can be customized in several ways using command-line args or by creating
1718
[![License](https://img.shields.io/npm/l/@devcycle/cli.svg)](https://github.com/DevCycleHQ/cli/blob/main/package.json)
1819

1920
<!-- toc -->
20-
* [Setup](#setup)
21-
* [Authentication](#authentication)
22-
* [Usage](#usage)
23-
* [Command Topics](#command-topics)
24-
* [MCP Server for AI Assistants](#mcp-server-for-ai-assistants)
25-
* [This installs both 'dvc' CLI and 'dvc-mcp' server](#this-installs-both-dvc-cli-and-dvc-mcp-server)
26-
* [Access via: npx dvc-mcp](#access-via-npx-dvc-mcp)
27-
* [Repo Configuration](#repo-configuration)
21+
- [MCP Server for AI Assistants](#mcp-server-for-ai-assistants)
22+
- [CLI Documentation](#cli-documentation)
23+
- [Setup](#setup)
24+
- [Authentication](#authentication)
25+
- [Usage](#usage)
26+
- [Command Topics](#command-topics)
27+
- [Repo Configuration](#repo-configuration)
2828
<!-- tocstop -->
29-
# Setup
3029

31-
## Install the CLI
30+
## MCP Server for AI Assistants
31+
32+
The DevCycle MCP (Model Context Protocol) server enables AI coding assistants like Cursor and Claude to manage feature flags directly from your development environment. DevCycle offers a hosted MCP server that requires no local installation.
33+
34+
### Quick Setup (No Installation Required)
35+
36+
1. **Configure your AI assistant to use the hosted MCP server:**
37+
38+
- **Cursor**: Add to `.cursor/mcp_settings.json`:
39+
40+
```json
41+
{
42+
"mcpServers": {
43+
"devcycle": {
44+
"url": "https://mcp.devcycle.com/mcp"
45+
}
46+
}
47+
}
48+
```
49+
50+
- **Claude Desktop**: Add to your Claude config file:
51+
52+
```json
53+
{
54+
"mcpServers": {
55+
"devcycle": {
56+
"command": "npx",
57+
"args": [
58+
"mcp-remote",
59+
"https://mcp.devcycle.com/mcp"
60+
]
61+
}
62+
}
63+
}
64+
```
65+
66+
2. **That's it!** The server will guide you through OAuth authentication when you first use it.
67+
68+
Your AI assistant can now create, update, and manage feature flags on your behalf.
69+
70+
For local installation options, detailed configuration, available tools, and advanced usage, see the [complete MCP documentation](docs/mcp.md).
71+
72+
## CLI Documentation
73+
74+
## Setup
75+
76+
### Install the CLI
77+
3278
Using NPM
79+
3380
```sh-session
3481
$ npm install -g @devcycle/cli
3582
```
83+
3684
Or alternatively, using homebrew
3785

3886
```sh-session
3987
$ brew tap devcyclehq/cli
4088
$ brew install devcycle
4189
```
42-
# Authentication
90+
91+
## Authentication
92+
4393
Many of the CLI commands require DevCycle API authorization. There are several ways to provide these credentials.
4494

45-
## Using Access Tokens (preferred)
95+
### Using Access Tokens (preferred)
96+
97+
#### Login Command
4698

47-
### Login Command
4899
By using the [`login sso` command](docs/login.md#dvc-login-sso), the CLI will retrieve and store an access token, which is valid for 24 hours.
49100

50101
The [`login again` command](docs/login.md#dvc-login-again) can be used to retrieve a new access token using the saved project and organization without prompting for them.
@@ -55,12 +106,14 @@ To switch organizations once logged in, the [`organizations select` command](doc
55106

56107
If executing the CLI in a containerized environment, please ensure one of the following PORTs can be accessed via Port Forwarding: 2194 (default), 2195, 2196 or 8080. This will allow the authentication process to complete and set the access token appropriately.
57108

58-
### Repo Init Command
109+
#### Repo Init Command
110+
59111
The [`repo init` command](docs/repo.md#dvc-repo-init) behaves in the same way as `login sso`, but creates a [repo configuration file](#repo-configuration) and stores the project and organization choices there instead.
60112

61-
## Using Client Credentials
113+
### Using Client Credentials
114+
115+
#### Client Credentials in Auth File
62116

63-
### Client Credentials in Auth File
64117
Use the [`dvc status` command](docs/status.md#dvc-status) to find the configuration file location for your platform. The credentials can be stored in the file pointed to by the Auth config path. Create the file if it does not exist, with the following contents.
65118

66119
```yaml
@@ -75,15 +128,16 @@ The default location is based on the [oclif configDir](https://oclif.io/docs/con
75128
76129
If you intend to run the CLI using options that override config file locations, the [`dvc status` command](docs/status.md#dvc-status) command can be run with those options to confirm that the file locations are as expected.
77130

78-
## Project Selection
131+
### Project Selection
79132

80133
You also need to specify the default project ID for the CLI to use.
81134

82135
If there is a repo configuration file, the [`dvc diff`](docs/diff.md) and [`dvc usages`](docs/usages.md) commands will use the project defined there.
83136

84137
Otherwise, this is chosen during login or set using the [project select command](docs/projects.md#dvc-projects-select)
85138

86-
## Environment Variables
139+
### Environment Variables
140+
87141
Set the following environment variables:
88142

89143
```sh-session
@@ -92,27 +146,27 @@ $ export DEVCYCLE_CLIENT_SECRET=<your client secret>
92146
$ export DEVCYCLE_PROJECT_KEY=<your project key>
93147
```
94148

95-
## Command-Line Arguments
149+
### Command-Line Arguments
96150

97151
The CLI can be run with the following arguments:
98152

99153
```sh-session
100154
$ dvc --client-id=<your client id> --client-secret=<your client secret> --project=<your project key>
101155
```
102156

103-
## Github Action
157+
### Github Action
104158

105159
The Devcycle Github actions are configured with auth information through the `project-key`, `client-id` and `client-secret` configuration parameters. This is passed to the CLI via command line arguments.
106160

107-
# Usage
161+
## Usage
108162

109163
<!-- usage -->
110164
```sh-session
111165
$ npm install -g @devcycle/cli
112166
$ dvc COMMAND
113167
running command...
114168
$ dvc (--version)
115-
@devcycle/cli/5.21.2 darwin-arm64 node-v22.12.0
169+
@devcycle/cli/5.21.2 darwin-arm64 node-v22.17.1
116170
$ dvc --help [COMMAND]
117171
USAGE
118172
$ dvc COMMAND
@@ -121,130 +175,33 @@ USAGE
121175
<!-- usagestop -->
122176

123177
<!-- commands -->
124-
# Command Topics
125-
126-
* [`dvc alias`](docs/alias.md) - Manage repository variable aliases.
127-
* [`dvc autocomplete`](docs/autocomplete.md) - display autocomplete installation instructions
128-
* [`dvc cleanup`](docs/cleanup.md) - Replace a DevCycle variable with a static value in the current version of your code. Currently only JavaScript is supported.
129-
* [`dvc diff`](docs/diff.md) - Print a diff of DevCycle variable usage between two versions of your code.
130-
* [`dvc environments`](docs/environments.md) - Create a new Environment for an existing Feature.
131-
* [`dvc features`](docs/features.md) - Create, view, or modify Features with the Management API.
132-
* [`dvc generate`](docs/generate.md) - Generate Devcycle related files.
133-
* [`dvc help`](docs/help.md) - Display help for dvc.
134-
* [`dvc identity`](docs/identity.md) - View or manage your DevCycle Identity.
135-
* [`dvc keys`](docs/keys.md) - Retrieve SDK keys from the Management API.
136-
* [`dvc login`](docs/login.md) - Log in to DevCycle.
137-
* [`dvc logout`](docs/logout.md) - Discards any auth configuration that has been stored in the auth configuration file.
138-
* [`dvc organizations`](docs/organizations.md) - List or switch organizations.
139-
* [`dvc overrides`](docs/overrides.md) - Create, view, or modify Overrides for a Project with the Management API.
140-
* [`dvc projects`](docs/projects.md) - Create, or view Projects with the Management API.
141-
* [`dvc repo`](docs/repo.md) - Manage repository configuration.
142-
* [`dvc status`](docs/status.md) - Check CLI status.
143-
* [`dvc targeting`](docs/targeting.md) - Create, view, or modify Targeting Rules for a Feature with the Management API.
144-
* [`dvc usages`](docs/usages.md) - Print all DevCycle variable usages in the current version of your code.
145-
* [`dvc variables`](docs/variables.md) - Create, view, or modify Variables with the Management API.
146-
* [`dvc variations`](docs/variations.md) - Create a new Variation for an existing Feature.
178+
## Command Topics
179+
180+
- [`dvc alias`](docs/alias.md) - Manage repository variable aliases.
181+
- [`dvc autocomplete`](docs/autocomplete.md) - display autocomplete installation instructions
182+
- [`dvc cleanup`](docs/cleanup.md) - Replace a DevCycle variable with a static value in the current version of your code. Currently only JavaScript is supported.
183+
- [`dvc diff`](docs/diff.md) - Print a diff of DevCycle variable usage between two versions of your code.
184+
- [`dvc environments`](docs/environments.md) - Create a new Environment for an existing Feature.
185+
- [`dvc features`](docs/features.md) - Create, view, or modify Features with the Management API.
186+
- [`dvc generate`](docs/generate.md) - Generate Devcycle related files.
187+
- [`dvc help`](docs/help.md) - Display help for dvc.
188+
- [`dvc identity`](docs/identity.md) - View or manage your DevCycle Identity.
189+
- [`dvc keys`](docs/keys.md) - Retrieve SDK keys from the Management API.
190+
- [`dvc login`](docs/login.md) - Log in to DevCycle.
191+
- [`dvc logout`](docs/logout.md) - Discards any auth configuration that has been stored in the auth configuration file.
192+
- [`dvc organizations`](docs/organizations.md) - List or switch organizations.
193+
- [`dvc overrides`](docs/overrides.md) - Create, view, or modify Overrides for a Project with the Management API.
194+
- [`dvc projects`](docs/projects.md) - Create, or view Projects with the Management API.
195+
- [`dvc repo`](docs/repo.md) - Manage repository configuration.
196+
- [`dvc status`](docs/status.md) - Check CLI status.
197+
- [`dvc targeting`](docs/targeting.md) - Create, view, or modify Targeting Rules for a Feature with the Management API.
198+
- [`dvc usages`](docs/usages.md) - Print all DevCycle variable usages in the current version of your code.
199+
- [`dvc variables`](docs/variables.md) - Create, view, or modify Variables with the Management API.
200+
- [`dvc variations`](docs/variations.md) - Create a new Variation for an existing Feature.
147201

148202
<!-- commandsstop -->
203+
## Repo Configuration
149204

150-
# MCP Server for AI Assistants
151-
152-
The DevCycle CLI includes an MCP (Model Context Protocol) server that enables AI coding assistants like Cursor and Claude to manage feature flags directly. This allows you to create, update, and manage feature flags without leaving your coding environment.
153-
154-
## Installation
155-
156-
### Option 1: Global Installation (Recommended)
157-
```bash
158-
npm install -g @devcycle/cli
159-
# This installs both 'dvc' CLI and 'dvc-mcp' server
160-
```
161-
162-
### Option 2: Project-Specific Installation
163-
```bash
164-
npm install --save-dev @devcycle/cli
165-
# Access via: npx dvc-mcp
166-
```
167-
168-
### Verify Installation
169-
```bash
170-
dvc-mcp --version # Should display the DevCycle CLI version
171-
dvc --version # Verify CLI is also installed
172-
```
173-
174-
## Configuration
175-
176-
### For Cursor
177-
Add to `.cursor/mcp_settings.json`:
178-
```json
179-
{
180-
"mcpServers": {
181-
"devcycle": {
182-
"command": "dvc-mcp"
183-
}
184-
}
185-
}
186-
```
187-
188-
### For Claude Desktop
189-
Add to your Claude configuration file:
190-
191-
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
192-
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
193-
194-
```json
195-
{
196-
"mcpServers": {
197-
"devcycle": {
198-
"command": "dvc-mcp"
199-
}
200-
}
201-
}
202-
```
203-
204-
### For Project-Specific Installation
205-
If you installed locally, update the command path:
206-
```json
207-
{
208-
"mcpServers": {
209-
"devcycle": {
210-
"command": "npx",
211-
"args": ["dvc-mcp"]
212-
}
213-
}
214-
}
215-
```
216-
217-
## Authentication
218-
219-
The MCP server uses the same authentication as the CLI:
220-
221-
1. **Authenticate with DevCycle:**
222-
```bash
223-
dvc login sso
224-
```
225-
226-
2. **Select your project:**
227-
```bash
228-
dvc projects select
229-
```
230-
231-
3. **Verify setup:**
232-
```bash
233-
dvc status
234-
```
235-
236-
Your AI assistant can now manage feature flags on your behalf.
237-
238-
## Troubleshooting
239-
240-
- **Command not found:** Ensure the CLI is installed globally or use `npx dvc-mcp`
241-
- **Authentication errors:** Run `dvc login sso` to re-authenticate
242-
- **No project selected:** Run `dvc projects select` to choose a project
243-
- **Permission issues:** On Unix systems, you may need to restart your terminal after global installation
244-
245-
For detailed documentation and advanced usage, see [docs/mcp.md](docs/mcp.md).
246-
247-
# Repo Configuration
248205
The following commands can only be run from the root of a configured repository
249206

250207
- [`dvc diff`](docs/diff.md)
@@ -288,10 +245,11 @@ codeInsights:
288245
- "dist/*"
289246
```
290247

291-
## Match Patterns
292-
When identifying variable usages in the code, the CLI will identify DevCycle SDK methods by default. To capture
293-
other usages you may define match patterns. Match patterns are defined by file extension, and each pattern should
294-
contain exactly one capture group which matches the key of the variable. Make sure the captured value contains the
248+
### Match Patterns
249+
250+
When identifying variable usages in the code, the CLI will identify DevCycle SDK methods by default. To capture
251+
other usages you may define match patterns. Match patterns are defined by file extension, and each pattern should
252+
contain exactly one capture group which matches the key of the variable. Make sure the captured value contains the
295253
entire key parameter (including quotes, if applicable).
296254

297255
Match patterns can be defined in the configuration file, for example:
@@ -312,11 +270,13 @@ codeInsights:
312270
```
313271

314272
Match patterns can also be passed directly to relevant commands using the `--match-pattern` flag:
315-
```
273+
274+
```bash
316275
dvc usages --match-pattern ts="customVariableGetter\(\s*[\"']([^\"']*)[\"']" js="customVariableGetter\(\s*[\"']([^\"']*)[\"']"
317276
```
318277

319278
When testing your regex the `--show-regex` flag can be helpful. This will print all patterns used to find matches in your codebase.
320-
```
279+
280+
```bash
321281
dvc usages --show-regex
322282
```

0 commit comments

Comments
 (0)