How to Integrate dcg with MCP Servers: Using the Built-In Model Context Protocol

You integrate dcg with MCP servers by running the dcg mcp-server sub-command, which exposes check_command, scan_file, and explain_pattern tools over stdio using the rust-mcp-sdk crate.

The destructive_command_guard (dcg) project natively supports the Model Context Protocol (MCP), allowing AI agents and IDE integrations to query the guard without relying on shell hooks. According to the Dicklesworthstone/destructive_command_guard source code, the binary includes a first-party MCP server implementation registered under the mcp-server CLI argument. This server reuses the same rule engine and JSON response schema as the interactive hook mode, so clients receive consistent severity ratings, confidence scores, and remediation advice across both interfaces.

Start the Built-In MCP Server

The fastest way to integrate dcg with MCP servers is to launch the stdio-based server shipped with the CLI.

In src/cli.rs, the command definition adds the mcp-server sub-command and forwards execution to crate::mcp::run_mcp_server(). The binary entry point in src/main.rs parses this argument and surfaces it in the help output.

dcg mcp-server

Once started, the server listens on stdin/stdout and remains alive until it receives a termination request. The implementation in src/mcp.rs relies on the rust-mcp-sdk crate—declared in Cargo.toml with features server, stdio, and macros—to create the McpServer instance via run_mcp_server_async and manage the stdio transport.

Available MCP Tools and JSON Schema

The dcg MCP server registers three tools that mirror the core guard functionality:

  • check_command — Evaluates a shell command against the destructive pattern database.
  • scan_file — Scans a file or directory path for known dangerous operations.
  • explain_pattern — Returns documentation for a specific rule ID.

When an MCP-compatible client invokes any tool, the server returns structured JSON that includes the rule ID, severity, confidence, and remediation fields. This schema matches the regular hook mode output exactly, so parsers can be reused across both integration styles.

Calling dcg Tools from an MCP Client

Because the server uses stdio transport, any MCP client that supports stdio can connect to the running dcg process directly.

Check a Command

use rust_mcp_sdk::client::McpClient;
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect to the running dcg process (stdin/stdout)
    let client = McpClient::stdio().await?;

    // Call the "check_command" tool
    let response = client
        .call_tool("check_command", json!({ "command": "git reset --hard HEAD~5" }))
        .await?;

    println!("MCP response: {}", response);
    Ok(())
}

Scan a Directory

let response = client
    .call_tool("scan_file", json!({ "path": "/path/to/project" }))
    .await?;
println!("Scan result: {}", response);

Explain a Rule Pattern

let response = client
    .call_tool("explain_pattern", json!({ "pattern_id": "core.git:reset-hard" }))
    .await?;
println!("Explanation: {}", response);

Windows PowerShell Support

Windows users can leverage the helper script at scripts/win_mcp_stdio.ps1 to launch the server and execute a full MCP handshake over a redirected stdio pipe. This proves that the stdio transport works on Windows and provides a drop-in starting point for PowerShell-based clients that need to integrate dcg with MCP servers without writing additional Rust code.

Summary

  • Run dcg mcp-server to start the built-in stdio MCP server defined in src/cli.rs and src/mcp.rs.
  • The server exposes three tools—check_command, scan_file, and explain_pattern—with JSON responses that match the standard hook schema.
  • Client code can connect via McpClient::stdio() from the rust-mcp-sdk crate and call tools asynchronously.
  • Windows deployments are supported through scripts/win_mcp_stdio.ps1, which handles server startup and handshake verification.

Frequently Asked Questions

How do I start the dcg MCP server?

Run the command dcg mcp-server in your terminal. The binary defined in src/main.rs and src/cli.rs will invoke crate::mcp::run_mcp_server(), which initializes an McpServer over stdio via run_mcp_server_async and waits for client requests until termination.

What MCP tools does dcg expose?

The server registers three tools in src/mcp.rs: check_command for evaluating shell commands, scan_file for scanning filesystem paths, and explain_pattern for retrieving rule documentation. Each returns structured JSON containing severity, confidence, and remediation details.

Can I use the dcg MCP server on Windows?

Yes. The repository includes scripts/win_mcp_stdio.ps1, which launches the server and completes a full MCP handshake over a redirected stdio pipe. This confirms that the rust-mcp-sdk stdio transport functions correctly on Windows.

Do I need to install anything besides the dcg binary to use MCP integration?

No. The MCP functionality is compiled into the default binary because Cargo.toml already declares rust-mcp-sdk with the required server, stdio, and macros features. Simply build or install dcg and run dcg mcp-server.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →