MCP CLI Tools Path Safety

Workflow and deploy MCP tools accept only YAML files inside the current working directory

Workflow and deploy MCP tools accept only YAML files inside the current working directory for security.

python
from praisonaiagents import Agent

agent = Agent(name="safe-agent", instructions="Use MCP tools with path safety checks.")
agent.start("Read the file at /home/user/docs/report.txt safely.")

The user references a YAML workflow by filename; path safety ensures only files under the current working directory are accepted.

Diagram

Yes

No

📄 file_path

🔍 _resolve_cwd_yaml_path

✅ Valid YAML in CWD?

🟢 Allow

🔴 ValueError

Quick Start

  1. Valid Usage
    python
    # MCP tools accept bare YAML filenames
    workflow_validate("project.yaml")  # ✅ Works
    workflow_show("config.yml")        # ✅ Works
    deploy_validate("deploy.yaml")     # ✅ Works
  2. Rejected Usage
    python
    # These paths are rejected for security
    workflow_validate("../config.yaml")     # ❌ ValueError
    workflow_validate("/etc/passwd")        # ❌ ValueError
    workflow_validate("subdir/file.yaml")   # ❌ ValueError

How It Works

Three MCP tools now enforce strict path validation:

ToolPurposePath Requirement
workflow_validateValidate workflow YAMLBare filename in CWD
workflow_showDisplay workflow contentBare filename in CWD
deploy_validateValidate deployment configBare filename in CWD
Diagram
File System_resolve_cwd_yaml_pathCLI ToolMCP ClientFile System_resolve_cwd_yaml_pathCLI ToolMCP Clientalt[Path valid][Path invalid]call with file_path_resolve_cwd_yaml_path(file_path)Check path rulesRead from CWDFile contentPath objectSuccess resultValueErrorError message

What Gets Refused

Path PatternExampleError Message
Contains / or \subdir/file.yamlinvalid file_path: 'subdir/file.yaml'
Contains NUL bytefile\x00.yamlinvalid file_path: 'file\x00.yaml'
Starts with ..hidden.yamlinvalid file_path: '.hidden.yaml'
Not YAML extensionconfig.jsonfile_path must be a .yaml or .yml file
Absolute path/etc/passwdinvalid file_path: '/etc/passwd'
Parent directory../config.yamlinvalid file_path: '../config.yaml'
Resolves outside CWDsymlink.yaml → ../outside.yamlinvalid file_path: 'symlink.yaml'

Migration

If you previously used these MCP tools with absolute paths or subdirectory paths:

  1. Move Files to CWD
    bash
    # Before (worked previously)
    workflow_validate("/home/user/project/workflows/main.yaml")
    workflow_validate("workflows/deploy.yaml")
    
    # After (required now)
    cp /home/user/project/workflows/main.yaml ./main.yaml
    cp workflows/deploy.yaml ./deploy.yaml
    workflow_validate("main.yaml")
    workflow_validate("deploy.yaml")
  2. Update Tool Calls
    python
    # Before
    deploy_validate("configs/production.yaml")
    
    # After  
    deploy_validate("production.yaml")  # file must be in CWD

Common Patterns

Workflow Management

python
# Validate workflow in current directory
result = workflow_validate("workflow.yaml")
if "valid" in result:
    content = workflow_show("workflow.yaml")
    print(content)

Deployment Validation

python
# Check deployment config
result = deploy_validate("deploy.yml") 
if "valid" in result:
    print("Deployment config is valid")
else:
    print(f"Validation failed: {result}")

Error Handling

python
try:
    content = workflow_show("../outside.yaml")
except Exception as e:
    print(f"Error: {e}")
    # Error: invalid file_path: '../outside.yaml'

Best Practices

Keep YAML Files in Project Root

Place workflow and deployment YAML files in the project root directory, not in subdirectories. This matches the MCP security model.

Use Descriptive Filenames

Since you can’t use paths, use descriptive filenames like production-deploy.yaml instead of deploy/production.yaml.

Validate Before Use

Always call the validation tools before processing YAML files to catch configuration errors early.

Handle Errors Gracefully

Check for ValueError exceptions and provide helpful error messages to users when paths are rejected.


Related