Skip to main content

Universal MCP server for emotional tone analysis and de-escalation in communications

Project description

Emotional De-escalation MCP Server v2

Universal MCP server for emotional tone analysis and de-escalation using a 5-axis communication style model.

Based on: Mistakes to Avoid When Developing Chatbots for User Support

5-Axis Communication Style Model

Every message is characterized by a style vector — 5 independent axes on a discrete scale from -2 to +2:

Axis -2 -1 0 +1 +2
W Warmth cold, detached cool neutral friendly warm, empathetic
F Formality slang, crude casual balanced professional formal, official
P Playfulness dead serious dry balanced light, witty humorous, ironic
A Assertiveness uncertain, meek tentative balanced confident demanding, forceful
E Expressiveness terse, reserved restrained balanced animated emotional, intense

Style Combinations

Style W F P A E
Sarcasm -2 -1 +2 0 +1
Friendly humor +1 -1 +2 -1 0
Flirtatious +2 -2 +1 -1 +1
Business tone 0 +2 -2 0 -1
Aggression -2 -2 -2 +2 +2
Desperation 0 -1 -2 -1 +2
Passive-aggression -1 0 +1 +1 -1

De-escalation Strategy

Instead of a single coefficient, de-escalation operates per-axis:

Axis Shift Rationale
Warmth +1 Increase empathy
Formality +1 Slightly more professional
Playfulness → 0 Reduce sarcasm risk
Assertiveness -1 Reduce pressure
Expressiveness -1 Calm down intensity

This breaks the positive feedback loop by ensuring the bot's response vector is always shifted toward a more constructive zone.

Engine Modes

The server supports two execution modes, controlled via EMOTION_MCP_MODE env var or per-call mode parameter:

Mode How it works API key required Cost
host (default) Tool returns a structured prompt → host LLM (Claude Desktop/Code/LM Studio) executes it No Free
api Tool calls Anthropic API directly, returns parsed results Yes Paid

In host mode, each tool returns a single self-contained prompt with the full 5-axis model, analysis rules, session context, and task-specific instructions. The host LLM executes everything in one pass.

In api mode, the server makes its own LLM calls and returns structured results (JSON or Markdown).

To switch to API mode:

# Via environment variable
export EMOTION_MCP_MODE=api

# Or per-call parameter
{"text": "...", "mode": "api"}

Tools

Analysis Tools

All analysis tools accept optional parameters:

  • session_id — for stateful emotional tracking across turns
  • mode"host" or "api" (overrides env var)

emotion_analyze

Analyze a message → emotion + style vector + style label.

{
  "text": "ну конечно, ваш замечательный бот мне так помог, спасибо огромное",
  "language_hint": "ru"
}

Returns (API mode):

{
  "emotion": "anger",
  "intensity": 1,
  "style_vector": {"warmth": -2, "formality": -1, "playfulness": 2, "assertiveness": 0, "expressiveness": 1},
  "detected_style": "sarcasm",
  "explanation": "...",
  "triggers": ["ну конечно", "замечательный", "спасибо огромное"]
}

In host mode, returns a structured prompt for the host LLM to produce the same analysis.

emotion_de_escalate

Analyze user emotion + rewrite a draft + provide recommendations — all in one call.

Auto mode (default): analyzes user's style, applies de-escalation shifts. Override mode: pass target_style explicitly.

{
  "user_message": "what the hell is wrong with the delivery?!",
  "draft_response": "Your order should arrive by April 10.",
  "target_style": {"warmth": 1, "formality": 1, "playfulness": 0, "assertiveness": 0, "expressiveness": 0}
}

emotion_evaluate_dialogue

Evaluate full dialogue → per-message vectors + trend + feedback loop risk.

{
  "messages": [
    {"role": "user", "text": "hello"},
    {"role": "bot", "text": "Hello! How can I help?"},
    {"role": "user", "text": "what the hell is wrong with the delivery?!"},
    {"role": "bot", "text": "Your order #3756 arrives April 10."},
    {"role": "user", "text": "ok I guess I'll wait"}
  ],
  "response_format": "markdown"
}

Returns a table:

# Role Emotion W F P A E Style
1 user neutral 0 -1 0 0 0 casual
2 bot neutral +1 0 0 0 0 friendly
3 user anger -2 -2 -2 +2 +2 aggressive
4 bot neutral 0 +1 -1 0 -1 business
5 user neutral 0 -1 0 -1 0 resigned

Session Management Tools

Sessions enable stateful emotional tracking across conversation turns.

  • session_create — create a session with optional custom config (target attractor, shift speed, thresholds)
  • session_get — retrieve session state: mode, config, turn count, optionally full history
  • session_reset — clear history, optionally keep custom config
  • session_configure — update session settings on the fly

Session modes:

  • Adaptive (default) — mirrors user's style, gradually shifts toward a positive attractor each turn
  • De-escalation — auto-activates on trigger emotions (anger/disgust/fear) + high assertiveness or expressiveness; applies stronger corrective shifts; reverts to adaptive after cooldown

Installation & Setup

Prerequisites

  • Python 3.11+
  • uv package manager
  • An Anthropic API key (get one here) — only required for API mode. Host mode (default) works without it.

Important (macOS / Linux): GUI applications like Claude Desktop don't inherit your shell PATH, so uvx may not be found. Create a symlink to make it available system-wide:

# Find where uvx and uv is installed
which uvx
# Create a symlink (example, adjust the source path if yours differs)
sudo ln -sf ~/.local/bin/uvx /usr/local/bin/uvx
which uv
# Create a symlink (example, adjust the source path if yours differs)
sudo ln -sf ~/.local/bin/uv /usr/local/bin/uv

Quick Start with Claude Code

The easiest way to use this server is with Claude Code.

Step 1. Install the MCP server (one-time setup):

claude mcp add emotional-deescalation -- uvx emotional-deescalation-mcp

In host mode (default), no API key is needed — Claude Code itself performs the analysis using the structured prompts from the server.

For API mode (server makes its own LLM calls), pass the key:

claude mcp add emotional-deescalation -e ANTHROPIC_API_KEY=sk-ant-your-key-here -e EMOTION_MCP_MODE=api -- uvx emotional-deescalation-mcp

Step 2. Start Claude Code as usual:

claude

That's it! The tools are now available in your Claude Code session. You can ask Claude to analyze messages, de-escalate responses, or evaluate dialogues.

Claude Desktop

Add to your Claude Desktop config file (claude_desktop_config.json):

Host mode (default, no API key needed):

{
  "mcpServers": {
    "emotional-deescalation": {
      "command": "uvx",
      "args": ["emotional-deescalation-mcp"]
    }
  }
}

API mode (server makes its own LLM calls):

{
  "mcpServers": {
    "emotional-deescalation": {
      "command": "uvx",
      "args": ["emotional-deescalation-mcp"],
      "env": {
        "ANTHROPIC_API_KEY": "sk-ant-your-key-here",
        "EMOTION_MCP_MODE": "api"
      }
    }
  }
}

If uvx is not found: use the full path instead of "uvx" (e.g. "/Users/you/.local/bin/uvx"), or create a symlink as described in Prerequisites.

Manual / Development Setup

git clone https://github.com/ilyajob05/emo_bot.git
cd emo_bot
uv sync
python server.py                          # host mode (default)
# or for API mode:
# export ANTHROPIC_API_KEY=sk-ant-...
# EMOTION_MCP_MODE=api python server.py

Adding to any project via .mcp.json

Place an .mcp.json file in the root of your project so that Claude Code automatically connects to the server when opened in that directory:

{
  "mcpServers": {
    "emotional-deescalation": {
      "command": "uvx",
      "args": ["emotional-deescalation-mcp"]
    }
  }
}

For API mode, add "env": {"ANTHROPIC_API_KEY": "...", "EMOTION_MCP_MODE": "api"} to the config.

Agent integration

For LLM agents connecting via MCP: see AGENTS.md — a compact instruction file designed to minimize context window usage while providing all necessary tool selection and invocation guidance.

Architecture

MCP Client (Claude Desktop, Claude Code, LM Studio, any MCP host)
    │ stdio
    ▼
emotional_deescalation_mcp
    ├── emotion_analyze             ─┐
    ├── emotion_de_escalate          ├── Analysis tools (accept mode + session_id)
    ├── emotion_evaluate_dialogue   ─┘
    ├── session_create              ─┐
    ├── session_get                  ├── Session management
    ├── session_reset                │
    └── session_configure           ─┘
            │
            ├── HOST mode: returns structured prompt → host LLM executes (free)
            │
            └── API mode: calls LLM directly → Anthropic Claude API (paid)

License

MIT

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

emotional_deescalation_mcp-0.2.0.tar.gz (76.5 kB view details)

Uploaded Source

Built Distribution

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

emotional_deescalation_mcp-0.2.0-py3-none-any.whl (90.3 kB view details)

Uploaded Python 3

File details

Details for the file emotional_deescalation_mcp-0.2.0.tar.gz.

File metadata

File hashes

Hashes for emotional_deescalation_mcp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1c280fa8ef74c2fffab150105ad2f4ed8239dab5e4969226cb214ce264da3f4b
MD5 cb341d3c8e1d913ae0c83b83404fc691
BLAKE2b-256 8a84a057cfd35d12cbb28d88c65776e11af6ac82b30402c830435df2c828201e

See more details on using hashes here.

File details

Details for the file emotional_deescalation_mcp-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for emotional_deescalation_mcp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d1756b4947336132e348789a8dc58eb973fcc61c26298ebdb57e03a9d378e38
MD5 9ffe01420fb6287b948f04b6e24a0690
BLAKE2b-256 41916317897c9862106a1308865e15ab57c1d93bd92e1b24845298f0a49b9d1a

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