SESL logo light
Login

SESL MCP Server - User Guide

AI-powered rule generation and execution via Model Context Protocol. Connect ChatGPT, Claude, and other AI assistants to the SESL rule engine.

1. Overview

The SESL MCP Server is a Model Context Protocol (MCP) server that exposes the SESL (Simple Expert System Language) rule engine capabilities through a standardized MCP interface. MCP is an open protocol that allows AI assistants like Claude, ChatGPT, and other clients to interact with external tools and data sources in a standardized way.

This server acts as a bridge between AI assistants and the SESL rule engine, enabling you to:

  • Generate business rules from natural language descriptions (e.g., "Approve loan if credit score > 700")
  • Validate SESL code before execution to catch syntax errors, missing fields, and logical issues
  • Execute rule-based models with forward-chaining inference (rules fire automatically when conditions are met)
  • Build and modify models incrementally by adding rules and test scenarios
  • Integrate with ChatGPT seamlessly by pasting generated code directly (auto-formatting included)

How it works: When you send a request to the MCP server (e.g., asking it to generate rules for loan approval), the server processes your request using the SESL engine and returns structured results. The server runs continuously in the background, listening for MCP tool calls over HTTP.

🤖 AI-Powered Generation

Convert natural language to SESL YAML rules automatically

✅ Validation & Linting

Catch errors before execution with comprehensive YAML validation

⚡ Rule Execution

Run forward-chaining inference on your business rules

📝 Direct Paste Support

Paste SESL code from ChatGPT with automatic formatting fixes

â„šī¸ What is SESL?

SESL (Simple Expert System Language) is a forward-chaining rule engine with a YAML-based DSL (Domain Specific Language) for defining business rules and policies. Unlike traditional programming where you explicitly control the flow, SESL uses declarative rules that fire automatically when their conditions are met.

Key concepts:

  • Forward-chaining: Rules are evaluated continuously; when a rule's conditions become true, it fires and adds new facts
  • Facts: Data objects (key-value pairs) that represent the current state (e.g., {"credit_score": 750})
  • Rules: IF-THEN statements that transform facts (e.g., "IF credit_score > 700 THEN approve = true")
  • Priority: Higher priority rules fire first (useful for overrides and exceptions)
  • Constants: Reusable values defined once and referenced throughout rules

Learn more at: github.com/vpowell4/sesl

Key Features

  • 7 MCP Tools for complete SESL workflow management
  • Auto-fix for ChatGPT-generated YAML (converts bullet points to YAML syntax)
  • Large request support (100MB default, configurable)
  • Comprehensive error reporting with actionable suggestions
  • HTTP transport via FastMCP with Uvicorn
  • Environment-based configuration for flexible deployment

2. Installation

To Be Updated

3. MCP Tools

The SESL MCP Server exposes 7 tools through the MCP interface:

1. generate_sesl Generator

Generates a SESL prompt template for converting natural language descriptions into valid SESL YAML.

Parameters

Name Type Required Description
prompt string ✅ Yes Natural language description of business rules or policies

Returns

Complete prompt template with SESL specification, error prevention guidelines, and examples.

📋 Example Request:
{
  "tool": "generate_sesl",
  "arguments": {
    "prompt": "Create rules to approve a loan if credit score > 700 and income > 50000"
  }
}
📤 Example Response:

Returns a comprehensive template (2000+ characters) that you can send to an LLM like ChatGPT or Claude. The template includes:

  • Complete SESL specification (10 sections): File structure, rule syntax, YAML formatting rules, condition syntax, LET variables, field references, THEN blocks, data types, priorities, and facts
  • Error prevention checklist: Common mistakes to avoid (YAML syntax errors, condition formatting, variable usage, required fields)
  • Working example: A complete, runnable SESL model demonstrating all features
  • Your prompt: Integrated into the template as the goal for code generation

Typical usage flow:

  1. Call generate_sesl with your requirements
  2. Copy the returned template
  3. Send it to ChatGPT/Claude (e.g., "Here's a SESL template. Generate the code: [paste template]")
  4. LLM returns valid SESL YAML that you can save with add_model

Sample output snippet:

Generate SESL YAML for the following requirement:

Create rules to approve a loan if credit score > 700 and income > 50000

=== SESL SPECIFICATION ===

1. FILE STRUCTURE
Every SESL file must have this structure:
  const:        # Optional: define reusable constants
  rules:        # Required: list of rules
  facts:        # Optional: test scenarios

2. RULE STRUCTURE
Each rule must have:
  - rule: unique_name
    priority: number (higher = fires first)
    if: [conditions]
    then: [actions]
    because: "explanation"

...

2. lint_sesl Validator

Validates SESL YAML and returns structured error/warning messages.

Parameters

Name Type Required Description
contents List[Any] ✅ Yes SESL YAML content (TextContent, dicts, or strings)

Returns

List of TextContent with validation issues including level (ERROR/WARNING), message, rule, and details.

📋 Example Request:
{
  "tool": "lint_sesl",
  "arguments": {
    "contents": [
      {
        "type": "text",
        "text": "const:\\n  MIN_SCORE: 700\\nrules:\\n  - rule: approve_loan\\n..."
      }
    ]
  }
}
📤 Example Response (with errors):
[
  {
    "type": "text",
    "text": {
      "issues": [
        {
          "level": "ERROR",
          "message": "Missing required field 'priority'",
          "rule": "approve_loan",
          "details": {
            "error_type": "ValidationError",
            "field": "priority",
            "suggestion": "Add 'priority: 100' to the rule definition"
          }
        },
        {
          "level": "WARNING",
          "message": "Rule has no 'because' field",
          "rule": "check_income",
          "details": {
            "suggestion": "Add explanatory text for documentation"
          }
        }
      ]
    }
  }
]
📤 Example Response (no errors):
[
  {
    "type": "text",
    "text": {
      "issues": []
    }
  }
]

Understanding the response:

  • Empty issues array: Your SESL is valid and ready to execute
  • ERROR level: Critical issues that will prevent execution - must fix these
  • WARNING level: Best practice violations - code will run but may not be optimal
  • details object: Additional context including error type and actionable suggestions

3. run_sesl Executor

Executes SESL rules with provided facts and returns computed results.

Parameters

Name Type Required Description
contents List[Any] ✅ Yes SESL YAML model definition
facts Dict[str, Any] ✅ Yes Input facts for rule execution

Returns

Execution results including final facts, rules fired, and execution metadata.

📋 Example Request:
{
  "tool": "run_sesl",
  "arguments": {
    "contents": ["const:\\n  MIN_SCORE: 700\\n..."],
    "facts": {
      "credit_score": 750,
      "annual_income": 60000
    }
  }
}
📤 Example Response (successful execution):
[
  {
    "type": "text",
    "text": {
      "results": {
        "credit_score": 750,
        "annual_income": 60000,
        "debt_to_income": 0.35,
        "loan_approved": true,
        "approval_reason": "Meets credit and income requirements",
        "max_loan_amount": 250000
      },
      "metadata": {
        "rules_fired": ["calculate_dti", "approve_loan", "calculate_max_loan"],
        "execution_stages": ["lint", "load", "build_facts", "execute"],
        "total_rules": 5,
        "rules_evaluated": 5,
        "execution_time_ms": 45,
        "success": true
      }
    }
  }
]

Understanding the response:

  • results object: Contains both your original input facts AND new facts added by rules
  • rules_fired array: Shows which rules executed, in the order they fired (useful for debugging)
  • execution_stages: Confirms all processing stages completed successfully
  • New fields: Any field that appears in results but wasn't in your input facts was created by a rule (e.g., loan_approved, max_loan_amount)
📤 Example Response (execution error):
[
  {
    "type": "text",
    "text": {
      "error": "Execution failed during stage: execute",
      "error_type": "RuntimeError",
      "stage": "execute",
      "details": "Division by zero in rule 'calculate_ratio'",
      "suggestion": "Add condition to check denominator is not zero",
      "metadata": {
        "rules_fired_before_error": ["validate_input"],
        "failed_at_rule": "calculate_ratio"
      }
    }
  }
]

4. add_model Creator

Save a complete SESL model to a file. Supports direct paste from ChatGPT with automatic formatting fixes.

Parameters

Name Type Required Description
sesl_yaml string ✅ Yes Complete SESL YAML content (rules, const, etc.)
name string ❌ No Filename without extension (default: "model")
auto_fix boolean ❌ No Auto-fix ChatGPT formatting issues (default: true)

Returns

Success status, file path, and metadata about the saved model.

📋 Example Request:
{
  "tool": "add_model",
  "arguments": {
    "sesl_yaml": "const:\\n* MIN_SCORE: 700\\nrules:\\n* rule: approve\\n...",
    "name": "loan_approval",
    "auto_fix": true
  }
}
📤 Example Response (success):
{
  "success": true,
  "file_path": "C:\\Users\\vince\\Documents\\sesl-mcp\\loan_approval.sesl",
  "file_name": "loan_approval.sesl",
  "content_length": 342,
  "auto_fixed": true,
  "message": "SESL model saved to loan_approval.sesl"
}

Field explanations:

  • file_path: Absolute path where the file was saved (current working directory)
  • content_length: Size of saved content in bytes
  • auto_fixed: true if ChatGPT bullet points were converted to YAML syntax, false if no changes needed
📤 Example Response (error - invalid YAML):
{
  "success": false,
  "error": "Invalid YAML syntax",
  "error_type": "YAMLError",
  "details": "mapping values are not allowed here\n  in \"\", line 5, column 15",
  "suggestion": "Check YAML formatting: indentation, colons, dashes. Line 5 likely has incorrect spacing or missing colon."
}

Common errors and fixes:

  • "mapping values are not allowed": Missing space after colon (should be key: value not key:value)
  • "expected <block end>": Indentation problem - ensure consistent spaces (not tabs)
  • File already exists: The tool will overwrite existing files - use different names or backup first
💡 ChatGPT Support:
The auto_fix feature automatically converts ChatGPT's bullet points (* and â€ĸ) to YAML list syntax (-), preserving indentation.

5. add_scenario Editor

Add test scenarios (facts) to an existing SESL model file.

Parameters

Name Type Required Description
model_file string ✅ Yes Path to existing SESL model file (e.g., "model.sesl")
scenario_yaml string ✅ Yes YAML content for the scenario (dict or list)
auto_fix boolean ❌ No Auto-fix ChatGPT formatting (default: true)

Returns

Success status, number of scenarios added, and total scenario count.

📋 Example Request:
{
  "tool": "add_scenario",
  "arguments": {
    "model_file": "loan_approval.sesl",
    "scenario_yaml": "credit_score: 800\\nannual_income: 75000"
  }
}
📤 Example Response (success):
{
  "success": true,
  "file_path": "C:\\Users\\vince\\Documents\\sesl-mcp\\loan_approval.sesl",
  "scenarios_added": 1,
  "total_scenarios": 3,
  "message": "Added 1 scenario(s) to loan_approval.sesl"
}

Understanding the response:

  • scenarios_added: How many test scenarios were added in this operation (can be >1 if you provide a YAML list)
  • total_scenarios: Total count of scenarios in the file after adding (helps track test coverage)

What happens to the file: The tool loads your existing model, parses the scenario YAML, appends it to the facts array, and writes the updated model back to disk. Original formatting is preserved where possible.

📤 Example Response (error - file not found):
{
  "success": false,
  "error": "Model file not found: loan_approval.sesl",
  "suggestion": "Use add_model first to create the SESL model file",
  "searched_path": "C:\\Users\\vince\\Documents\\sesl-mcp\\loan_approval.sesl"
}

Tip: You can add multiple scenarios at once by providing a YAML list:

scenario_yaml: |-
  - credit_score: 800
    annual_income: 100000
  - credit_score: 650
    annual_income: 45000
  - credit_score: 720
    annual_income: 62000

6. add_rule Editor

Add a new rule to an existing SESL model file.

Parameters

Name Type Required Description
model_file string ✅ Yes Path to existing SESL model file (e.g., "model.sesl")
rule_yaml string ✅ Yes YAML content for the rule (must have 'rule' key)
auto_fix boolean ❌ No Auto-fix ChatGPT formatting (default: true)

Returns

Success status, number of rules added, and total rule count.

📋 Example Request:
{
  "tool": "add_rule",
  "arguments": {
    "model_file": "loan_approval.sesl",
    "rule_yaml": "rule: high_value_approval\\npriority: 10\\nif:\\n  - credit_score > 800\\nthen:\\n  - approved: true"
  }
}
📤 Example Response (success):
{
  "success": true,
  "file_path": "C:\\Users\\vince\\Documents\\sesl-mcp\\loan_approval.sesl",
  "rules_added": 1,
  "total_rules": 5,
  "message": "Added 1 rule(s) to loan_approval.sesl"
}

Understanding the response:

  • rules_added: How many rules were added in this operation
  • total_rules: Total count of rules in the model after adding
📤 Example Response (error - invalid rule format):
{
  "success": false,
  "error": "Invalid rule format: must have 'rule' key",
  "suggestion": "Each rule must have: rule, priority, if, then, because"
}

Required rule structure: Every SESL rule must be a dictionary with these fields:

rule: unique_rule_name        # Required: identifier for the rule
priority: 100                 # Required: number (higher fires first)
if:                          # Required: list of conditions
  - condition1
  - condition2
then:                        # Required: list of actions
  - field: value
because: "explanation"        # Required: human-readable reason

Priority guidelines:

  • 1000+: Critical overrides and exceptions
  • 500-999: High-priority business logic
  • 100-499: Standard rules
  • 1-99: Default/fallback rules

7. server_info Status

Get server version, status, and available tools.

Parameters

No parameters required

Returns

Server metadata including version, status, and tool list.

📋 Example Request:
{
  "tool": "server_info",
  "arguments": {}
}
📤 Example Response:
{
  "name": "sesl-mcp-server",
  "version": "0.1.0",
  "status": "running",
  "tools": [
    "generate_sesl",
    "lint_sesl",
    "run_sesl",
    "add_model",
    "add_scenario",
    "add_rule",
    "server_info"
  ],
  "sesl_engine": "https://github.com/vpowell4/sesl"
}