Skip to main content

MCP server for AI-assisted code transformations via CEDARScript

Project description

CEDARScript MCP Server

AI-Assisted Code Transformations via Model Context Protocol

License Python

Overview

CEDARScript MCP Server exposes the powerful CEDARScript Editor through the Model Context Protocol (MCP), enabling AI agents like Claude to perform intelligent, semantic-aware code transformations.

Key Features

  • ๐Ÿ”’ Secure by Default: Path validation, sandboxing, read-only mode
  • ๐ŸŽฏ Dry-Run Mode: Preview changes before applying
  • ๐ŸŒฒ Tree-Sitter Powered: Language-aware code analysis
  • ๐Ÿ“ก STDIO Transport: Simple subprocess integration (no HTTP overhead)
  • ๐Ÿ› ๏ธ Production-Ready: Comprehensive logging, error handling, testing

Quick Start

Installation

pip install cedarscript-mcp-server

Usage with Claude Desktop

  1. Open Claude Desktop configuration (usually ~/.config/Claude/claude_desktop_config.json)

  2. Add CEDARScript MCP server:

{
  "mcpServers": {
    "cedarscript": {
      "command": "python",
      "args": [
        "-m",
        "cedarscript_mcp.server",
        "--root",
        "/path/to/your/project"
      ]
    }
  }
}
  1. Restart Claude Desktop

  2. Ask Claude to use CEDARScript:

    • "Parse this CEDARScript command: UPDATE myfile.py SET imports.append('import os')"
    • "Apply this transformation (preview first): UPDATE calculator.py SET function:calculate REPLACE 'x + 1' WITH 'x + 2'"

Command-Line Usage

# Start server (STDIO mode)
python -m cedarscript_mcp.server --root /path/to/project

# With custom options
python -m cedarscript_mcp.server \
  --root /path/to/project \
  --read-only \
  --log-level DEBUG \
  --max-file-size 10485760

Architecture

CEDARScript MCP Server is a thin adapter layer that:

  1. Accepts JSON-RPC requests over STDIO
  2. Validates paths and security constraints
  3. Delegates to CEDARScript Editor for execution
  4. Returns structured results or error messages
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Claude Desktop / VS Code      โ”‚
โ”‚        (MCP Client)             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚ JSON-RPC over STDIO
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  CEDARScript MCP Server         โ”‚
โ”‚  โ€ข Security (path validation)   โ”‚
โ”‚  โ€ข Tools (parse, apply, list)   โ”‚
โ”‚  โ€ข Adapters (protocol mapping)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
             โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   CEDARScript Editor (core)     โ”‚
โ”‚  โ€ข AST parsing                  โ”‚
โ”‚  โ€ข Tree-sitter analysis         โ”‚
โ”‚  โ€ข File transformations         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Available Tools

parse_cedarscript

Parse and validate CEDARScript commands without execution.

Parameters:

  • content (string): CEDARScript commands

Returns: Parsed AST commands

Example:

{
  "content": "UPDATE myfile.py SET imports.append('import os')"
}

apply_cedarscript

Apply CEDARScript transformations to code files.

Parameters:

  • commands (string): CEDARScript commands
  • root (string): Project root directory path
  • dry_run (boolean, default: true): Preview changes without writing

Returns: Results, diffs (if dry_run), affected files

Example:

{
  "commands": "UPDATE calculator.py SET function:add REPLACE 'x + y' WITH 'x + y + 1'",
  "root": "/path/to/project",
  "dry_run": true
}

list_capabilities

List server capabilities and supported features.

Returns: Server version, features, security settings

Configuration

Environment Variables

  • CEDARSCRIPT_ROOT: Default project root (default: current directory)
  • CEDARSCRIPT_LOG_LEVEL: Logging level (DEBUG, INFO, WARNING, ERROR)
  • CEDARSCRIPT_LOG_FORMAT: Log format (text, json)
  • CEDARSCRIPT_READ_ONLY: Force read-only mode (true/false)
  • CEDARSCRIPT_MAX_FILE_SIZE: Max file size in bytes (default: 10485760)

CLI Arguments

python -m cedarscript_mcp.server \
  --root /path/to/project \         # Project root directory
  --read-only \                     # Enable read-only mode
  --log-level DEBUG \               # Logging level
  --max-file-size 10485760          # Max file size (bytes)

Security

Path Validation

  • All file paths are validated against the specified root directory
  • Path traversal attacks (../../../etc/passwd) are blocked
  • Symlinks are resolved and validated

Denylist Patterns

Files matching these patterns are automatically rejected:

  • .git/**, node_modules/**, __pycache__/**
  • .env, *.env, .env.*
  • credentials.json, *.key, *.pem

Read-Only Mode

When enabled, all write operations are rejected (parsing/analysis only).

File Size Limits

Configurable maximum file size (default: 10MB) to prevent resource exhaustion.

Development

Setup

# Clone repository
git clone https://github.com/CEDARScript/cedarscript-mcp-server.git
cd cedarscript-mcp-server

# Install development dependencies
make install

# Run tests
make test

# Run with coverage
make test-cov

# Format and lint
make check

Makefile Targets

make help              # Show all available targets
make install           # Install with dev dependencies
make test              # Run full test suite
make test-fast         # Run tests (skip integration)
make check             # Format, lint, security checks
make run               # Launch server (demo mode)
make build             # Build distribution packages

See planning/MAKEFILE_DESIGN.md for complete target documentation.

Testing

# Run all tests
make test

# With coverage report
make test-cov

# Watch mode (auto-rerun on changes)
make test-watch

# Test against multiple cedarscript-editor versions
make test-matrix

Documentation

Examples

Claude Desktop Configuration

See examples/claude_desktop.json for drop-in configuration.

VS Code MCP Client

See examples/vscode_mcp.json for VS Code setup.

Programmatic Usage

from cedarscript_mcp import PathValidator, apply_cedarscript_tool

# Create validator
validator = PathValidator(Path("/path/to/project"))

# Apply transformation (dry-run)
result = apply_cedarscript_tool(
    commands="UPDATE myfile.py SET imports.append('import os')",
    root="/path/to/project",
    dry_run=True,
    validator=validator
)

print(result)

Troubleshooting

Server Not Starting

Issue: ModuleNotFoundError: No module named 'mcp'

Solution: Install MCP SDK: pip install mcp>=1.0.0

Path Validation Errors

Issue: SecurityError: Path escape attempt

Solution: Ensure file paths are within the specified root directory.

Read-Only Mode Blocking Writes

Issue: SecurityError: Write operation rejected

Solution: Remove --read-only flag or set CEDARSCRIPT_READ_ONLY=false.

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Run make check test before committing
  4. Submit a pull request

License

Apache License 2.0 - see LICENSE for details.

Related Projects

Support


Made with โค๏ธ by the CEDARScript Team

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cedarscript_mcp_server-0.1.0.tar.gz (41.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cedarscript_mcp_server-0.1.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file cedarscript_mcp_server-0.1.0.tar.gz.

File metadata

  • Download URL: cedarscript_mcp_server-0.1.0.tar.gz
  • Upload date:
  • Size: 41.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for cedarscript_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0a04cc69f45b31276c5b792cd073b0978183df0ec577c2c212d794ef07c3d63d
MD5 56e701bf722dd07b32f28b1f48527602
BLAKE2b-256 4903f6b1e2a60fb4e91c5b619292842520a37d82fc5a75098ae1f3d53714bead

See more details on using hashes here.

File details

Details for the file cedarscript_mcp_server-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cedarscript_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23570d531f0795b9037cb8a6c36250d0ac4b1f1f44e6e1861ad2f933fd454739
MD5 172cc58543dffbbd0a0bb7c3c34283ec
BLAKE2b-256 d76fd61e602aba2edf629a7ff7a86f58ff360db445a34d2b1a519365e96dd24d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page