Skip to content

Commit a752320

Browse files
authored
CM-49113 - Add Cycode MCP (Model Context Protocol) (#316)
1 parent 367f17d commit a752320

File tree

9 files changed

+1065
-35
lines changed

9 files changed

+1065
-35
lines changed

.github/workflows/build_executable.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
os: [ ubuntu-22.04, macos-13, macos-14, windows-2019 ]
18+
os: [ ubuntu-22.04, macos-13, macos-14, windows-2022 ]
1919
mode: [ 'onefile', 'onedir' ]
2020
exclude:
2121
- os: ubuntu-22.04
2222
mode: onedir
23-
- os: windows-2019
23+
- os: windows-2022
2424
mode: onedir
2525

2626
runs-on: ${{ matrix.os }}

README.md

Lines changed: 252 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ This guide walks you through both installation and usage.
1616
2. [On Windows](#on-windows)
1717
2. [Install Pre-Commit Hook](#install-pre-commit-hook)
1818
3. [Cycode CLI Commands](#cycode-cli-commands)
19-
4. [Scan Command](#scan-command)
19+
4. [MCP Command](#mcp-command-experiment)
20+
1. [Starting the MCP Server](#starting-the-mcp-server)
21+
2. [Available Options](#available-options)
22+
3. [MCP Tools](#mcp-tools)
23+
4. [Usage Examples](#usage-examples)
24+
5. [Scan Command](#scan-command)
2025
1. [Running a Scan](#running-a-scan)
2126
1. [Options](#options)
2227
1. [Severity Threshold](#severity-option)
@@ -48,10 +53,10 @@ This guide walks you through both installation and usage.
4853
4. [Ignoring a Secret, IaC, or SCA Rule](#ignoring-a-secret-iac-sca-or-sast-rule)
4954
5. [Ignoring a Package](#ignoring-a-package)
5055
6. [Ignoring via a config file](#ignoring-via-a-config-file)
51-
5. [Report command](#report-command)
56+
6. [Report command](#report-command)
5257
1. [Generating SBOM Report](#generating-sbom-report)
53-
6. [Scan logs](#scan-logs)
54-
7. [Syntax Help](#syntax-help)
58+
7. [Scan logs](#scan-logs)
59+
8. [Syntax Help](#syntax-help)
5560

5661
# Prerequisites
5762

@@ -293,29 +298,258 @@ The following are the options and commands available with the Cycode CLI applica
293298
|-------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|
294299
| [auth](#using-the-auth-command) | Authenticate your machine to associate the CLI with your Cycode account. |
295300
| [configure](#using-the-configure-command) | Initial command to configure your CLI client authentication. |
296-
| [ignore](#ignoring-scan-results) | Ignore a specific value, path or rule ID. |
301+
| [ignore](#ignoring-scan-results) | Ignore a specific value, path or rule ID. |
302+
| [mcp](#mcp-command-experiment) | Start the Model Context Protocol (MCP) server to enable AI integration with Cycode scanning capabilities. |
297303
| [scan](#running-a-scan) | Scan the content for Secrets/IaC/SCA/SAST violations. You`ll need to specify which scan type to perform: commit-history/path/repository/etc. |
298-
| [report](#report-command) | Generate report. You will need to specify which report type to perform as SBOM. |
304+
| [report](#report-command) | Generate report. You will need to specify which report type to perform as SBOM. |
299305
| status | Show the CLI status and exit. |
300306

307+
# MCP Command \[EXPERIMENT\]
308+
309+
> [!WARNING]
310+
> The MCP command is available only for Python 3.10 and above. If you're using an earlier Python version, this command will not be available.
311+
312+
The Model Context Protocol (MCP) command allows you to start an MCP server that exposes Cycode's scanning capabilities to AI systems and applications. This enables AI models to interact with Cycode CLI tools via a standardized protocol.
313+
314+
> [!TIP]
315+
> For the best experience, install Cycode CLI globally on your system using `pip install cycode` or `brew install cycode`, then authenticate once with `cycode auth`. After global installation and authentication, you won't need to configure `CYCODE_CLIENT_ID` and `CYCODE_CLIENT_SECRET` environment variables in your MCP configuration files.
316+
317+
[![Add MCP Server to Cursor using UV](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/install-mcp?name=cycode&config=eyJjb21tYW5kIjoidXZ4IGN5Y29kZSBtY3AiLCJlbnYiOnsiQ1lDT0RFX0NMSUVOVF9JRCI6InlvdXItY3ljb2RlLWlkIiwiQ1lDT0RFX0NMSUVOVF9TRUNSRVQiOiJ5b3VyLWN5Y29kZS1zZWNyZXQta2V5IiwiQ1lDT0RFX0FQSV9VUkwiOiJodHRwczovL2FwaS5jeWNvZGUuY29tIiwiQ1lDT0RFX0FQUF9VUkwiOiJodHRwczovL2FwcC5jeWNvZGUuY29tIn19)
318+
319+
320+
## Starting the MCP Server
321+
322+
To start the MCP server, use the following command:
323+
324+
```bash
325+
cycode mcp
326+
```
327+
328+
By default, this starts the server using the `stdio` transport, which is suitable for local integrations and AI applications that can spawn subprocesses.
329+
330+
### Available Options
331+
332+
| Option | Description |
333+
|-------------------|--------------------------------------------------------------------------------------------|
334+
| `-t, --transport` | Transport type for the MCP server: `stdio`, `sse`, or `streamable-http` (default: `stdio`) |
335+
| `-H, --host` | Host address to bind the server (used only for non stdio transport) (default: `127.0.0.1`) |
336+
| `-p, --port` | Port number to bind the server (used only for non stdio transport) (default: `8000`) |
337+
| `--help` | Show help message and available options |
338+
339+
### MCP Tools
340+
341+
The MCP server provides the following tools that AI systems can use:
342+
343+
| Tool Name | Description |
344+
|----------------------|---------------------------------------------------------------------------------------------|
345+
| `cycode_secret_scan` | Scan files for hardcoded secrets |
346+
| `cycode_sca_scan` | Scan files for Software Composition Analysis (SCA) - vulnerabilities and license issues |
347+
| `cycode_iac_scan` | Scan files for Infrastructure as Code (IaC) misconfigurations |
348+
| `cycode_sast_scan` | Scan files for Static Application Security Testing (SAST) - code quality and security flaws |
349+
| `cycode_status` | Get Cycode CLI version, authentication status, and configuration information |
350+
351+
### Usage Examples
352+
353+
#### Basic Command Examples
354+
355+
Start the MCP server with default settings (stdio transport):
356+
```bash
357+
cycode mcp
358+
```
359+
360+
Start the MCP server with explicit stdio transport:
361+
```bash
362+
cycode mcp -t stdio
363+
```
364+
365+
Start the MCP server with Server-Sent Events (SSE) transport:
366+
```bash
367+
cycode mcp -t sse -p 8080
368+
```
369+
370+
Start the MCP server with streamable HTTP transport on custom host and port:
371+
```bash
372+
cycode mcp -t streamable-http -H 0.0.0.0 -p 9000
373+
```
374+
375+
Learn more about MCP Transport types in the [MCP Protocol Specification – Transports](https://modelcontextprotocol.io/specification/2025-03-26/basic/transports).
376+
377+
#### Configuration Examples
378+
379+
##### Using MCP with Cursor/VS Code/Claude Desktop/etc (mcp.json)
380+
381+
> [!NOTE]
382+
> For EU Cycode environments, make sure to set the appropriate `CYCODE_API_URL` and `CYCODE_APP_URL` values in the environment variables (e.g., `https://api.eu.cycode.com` and `https://app.eu.cycode.com`).
383+
384+
Follow [this guide](https://code.visualstudio.com/docs/copilot/chat/mcp-servers) to configure the MCP server in your **VS Code/GitHub Copilot**. Keep in mind that in `settings.json`, there is an `mcp` object containing a nested `servers` sub-object, rather than a standalone `mcpServers` object.
385+
386+
For **stdio transport** (direct execution):
387+
```json
388+
{
389+
"mcpServers": {
390+
"cycode": {
391+
"command": "cycode",
392+
"args": ["mcp"],
393+
"env": {
394+
"CYCODE_CLIENT_ID": "your-cycode-id",
395+
"CYCODE_CLIENT_SECRET": "your-cycode-secret-key",
396+
"CYCODE_API_URL": "https://api.cycode.com",
397+
"CYCODE_APP_URL": "https://app.cycode.com"
398+
}
399+
}
400+
}
401+
}
402+
```
403+
404+
For **stdio transport** with `pipx` installation:
405+
```json
406+
{
407+
"mcpServers": {
408+
"cycode": {
409+
"command": "pipx",
410+
"args": ["run", "cycode", "mcp"],
411+
"env": {
412+
"CYCODE_CLIENT_ID": "your-cycode-id",
413+
"CYCODE_CLIENT_SECRET": "your-cycode-secret-key",
414+
"CYCODE_API_URL": "https://api.cycode.com",
415+
"CYCODE_APP_URL": "https://app.cycode.com"
416+
}
417+
}
418+
}
419+
}
420+
```
421+
422+
For **stdio transport** with `uvx` installation:
423+
```json
424+
{
425+
"mcpServers": {
426+
"cycode": {
427+
"command": "uvx",
428+
"args": ["cycode", "mcp"],
429+
"env": {
430+
"CYCODE_CLIENT_ID": "your-cycode-id",
431+
"CYCODE_CLIENT_SECRET": "your-cycode-secret-key",
432+
"CYCODE_API_URL": "https://api.cycode.com",
433+
"CYCODE_APP_URL": "https://app.cycode.com"
434+
}
435+
}
436+
}
437+
}
438+
```
439+
440+
For **SSE transport** (Server-Sent Events):
441+
```json
442+
{
443+
"mcpServers": {
444+
"cycode": {
445+
"url": "http://127.0.0.1:8000/sse"
446+
}
447+
}
448+
}
449+
```
450+
451+
For **SSE transport** on custom port:
452+
```json
453+
{
454+
"mcpServers": {
455+
"cycode": {
456+
"url": "http://127.0.0.1:8080/sse"
457+
}
458+
}
459+
}
460+
```
461+
462+
For **streamable HTTP transport**:
463+
```json
464+
{
465+
"mcpServers": {
466+
"cycode": {
467+
"url": "http://127.0.0.1:8000/mcp"
468+
}
469+
}
470+
}
471+
```
472+
473+
##### Running MCP Server in Background
474+
475+
For **SSE transport** (start server first, then configure client):
476+
```bash
477+
# Start the MCP server in the background
478+
cycode mcp -t sse -p 8000 &
479+
480+
# Configure in mcp.json
481+
{
482+
"mcpServers": {
483+
"cycode": {
484+
"url": "http://127.0.0.1:8000/sse"
485+
}
486+
}
487+
}
488+
```
489+
490+
For **streamable HTTP transport**:
491+
```bash
492+
# Start the MCP server in the background
493+
cycode mcp -t streamable-http -H 127.0.0.2 -p 9000 &
494+
495+
# Configure in mcp.json
496+
{
497+
"mcpServers": {
498+
"cycode": {
499+
"url": "http://127.0.0.2:9000/mcp"
500+
}
501+
}
502+
}
503+
```
504+
505+
> [!NOTE]
506+
> The MCP server requires proper Cycode CLI authentication to function. Make sure you have authenticated using `cycode auth` or configured your credentials before starting the MCP server.
507+
508+
### Troubleshooting MCP
509+
510+
If you encounter issues with the MCP server, you can enable debug logging to get more detailed information about what's happening. There are two ways to enable debug logging:
511+
512+
1. Using the `-v` or `--verbose` flag:
513+
```bash
514+
cycode -v mcp
515+
```
516+
517+
2. Using the `CYCODE_CLI_VERBOSE` environment variable:
518+
```bash
519+
CYCODE_CLI_VERBOSE=1 cycode mcp
520+
```
521+
522+
The debug logs will show detailed information about:
523+
- Server startup and configuration
524+
- Connection attempts and status
525+
- Tool execution and results
526+
- Any errors or warnings that occur
527+
528+
This information can be helpful when:
529+
- Diagnosing connection issues
530+
- Understanding why certain tools aren't working
531+
- Identifying authentication problems
532+
- Debugging transport-specific issues
533+
534+
301535
# Scan Command
302536
303537
## Running a Scan
304538
305539
The Cycode CLI application offers several types of scans so that you can choose the option that best fits your case. The following are the current options and commands available:
306540
307-
| Option | Description |
308-
|------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
309-
| `-t, --scan-type [secret\|iac\|sca\|sast]` | Specify the scan you wish to execute (`secret`/`iac`/`sca`/`sast`), the default is `secret`. |
310-
| `--show-secret BOOLEAN` | Show secrets in plain text. See [Show/Hide Secrets](#showhide-secrets) section for more details. |
311-
| `--soft-fail BOOLEAN` | Run scan without failing, always return a non-error status code. See [Soft Fail](#soft-fail) section for more details. |
312-
| `--severity-threshold [INFO\|LOW\|MEDIUM\|HIGH\|CRITICAL]` | Show only violations at the specified level or higher. |
313-
| `--sca-scan` | Specify the SCA scan you wish to execute (`package-vulnerabilities`/`license-compliance`). The default is both. |
314-
| `--monitor` | When specified, the scan results will be recorded in Cycode. |
315-
| `--cycode-report` | Display a link to the scan report in the Cycode platform in the console output. |
316-
| `--no-restore` | When specified, Cycode will not run the restore command. This will scan direct dependencies ONLY! |
317-
| `--gradle-all-sub-projects` | Run gradle restore command for all sub projects. This should be run from the project root directory ONLY! |
318-
| `--help` | Show options for given command. |
541+
| Option | Description |
542+
|------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
543+
| `-t, --scan-type [secret\|iac\|sca\|sast]` | Specify the scan you wish to execute (`secret`/`iac`/`sca`/`sast`), the default is `secret`. |
544+
| `--show-secret BOOLEAN` | Show secrets in plain text. See [Show/Hide Secrets](#showhide-secrets) section for more details. |
545+
| `--soft-fail BOOLEAN` | Run scan without failing, always return a non-error status code. See [Soft Fail](#soft-fail) section for more details. |
546+
| `--severity-threshold [INFO\|LOW\|MEDIUM\|HIGH\|CRITICAL]` | Show only violations at the specified level or higher. |
547+
| `--sca-scan` | Specify the SCA scan you wish to execute (`package-vulnerabilities`/`license-compliance`). The default is both. |
548+
| `--monitor` | When specified, the scan results will be recorded in Cycode. |
549+
| `--cycode-report` | Display a link to the scan report in the Cycode platform in the console output. |
550+
| `--no-restore` | When specified, Cycode will not run the restore command. This will scan direct dependencies ONLY! |
551+
| `--gradle-all-sub-projects` | Run gradle restore command for all sub projects. This should be run from the project root directory ONLY! |
552+
| `--help` | Show options for given command. |
319553
320554
| Command | Description |
321555
|----------------------------------------|-----------------------------------------------------------------|

cycode/cli/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import sys
23
from typing import Annotated, Optional
34

45
import typer
@@ -9,6 +10,10 @@
910

1011
from cycode import __version__
1112
from cycode.cli.apps import ai_remediation, auth, configure, ignore, report, scan, status
13+
14+
if sys.version_info >= (3, 10):
15+
from cycode.cli.apps import mcp
16+
1217
from cycode.cli.cli_types import OutputTypeOption
1318
from cycode.cli.consts import CLI_CONTEXT_SETTINGS
1419
from cycode.cli.printers import ConsolePrinter
@@ -47,6 +52,8 @@
4752
app.add_typer(report.app)
4853
app.add_typer(scan.app)
4954
app.add_typer(status.app)
55+
if sys.version_info >= (3, 10):
56+
app.add_typer(mcp.app)
5057

5158

5259
def check_latest_version_on_close(ctx: typer.Context) -> None:

cycode/cli/apps/mcp/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import typer
2+
3+
from cycode.cli.apps.mcp.mcp_command import mcp_command
4+
5+
app = typer.Typer()
6+
7+
_mcp_command_docs = 'https://github.com/cycodehq/cycode-cli/blob/main/README.md#mcp-command-experiment'
8+
_mcp_command_epilog = f'[bold]Documentation:[/] [link={_mcp_command_docs}]{_mcp_command_docs}[/link]'
9+
10+
app.command(
11+
name='mcp',
12+
short_help='[EXPERIMENT] Start the Cycode MCP (Model Context Protocol) server.',
13+
epilog=_mcp_command_epilog,
14+
)(mcp_command)

0 commit comments

Comments
 (0)