API & MCP Documentation

Table of Contents

Overview REST API Model Context Protocol (MCP) Smart Replace Algorithm Code Examples Error Handling

Overview

REST API and MCP integration for programmatic text processing. Hosted at https://emdashguard.com with smart em dash replacement.

Key Features

Base URL

All API endpoints are available at: https://emdashguard.com

REST API

POST /api/process-text

Process text to replace em dashes using the Smart Replace algorithm.

Request Body

Parameter Type Required Default Description
text string Yes - Text containing em dashes to process
smart boolean No true Enable Smart Replace algorithm
replacement string No "--" Token to replace em dashes with (ignored when smart=true)
spacing boolean No true Add spaces around replacements
Example Request
curl -X POST https://emdashguard.com/api/process-text \
  -H "Content-Type: application/json" \
  -d '{
    "text": "The result was clear — success!",
    "smart": true,
    "replacement": "--",
    "spacing": true
  }'

Response (Success)

{
  "success": true,
  "data": {
    "processedText": "The result was clear: success!"
  }
}

Smart Replace Behavior: When smart = true, the replacement parameter is ignored. Smart Replace automatically chooses the best replacement based on context analysis.

Response (Error)

{
  "success": false,
  "error": {
    "code": "INVALID_PARAMETERS",
    "message": "Invalid parameters: Expected string, received number"
  }
}

Model Context Protocol (MCP)

emdashguard supports the Model Context Protocol for seamless integration with AI agents and language models. The MCP server is hosted alongside the REST API and provides the emdash_remover tool.

Claude Desktop App Configuration

To use emdashguard with Claude Desktop, add this configuration to your claude_desktop_config.json file:

Location of config file:

MCP Configuration (Recommended)

{
  "mcpServers": {
    "emdashguard": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://emdashguard.com/api/mcp"
      ]
    }
  }
}

Note: emdashguard uses HTTP endpoints for MCP integration via the mcp-remote package.

After adding this configuration:

  1. Restart Claude Desktop
  2. You'll see "🔌 1" indicator showing emdashguard is connected
  3. Use the tool by asking Claude to "remove em dashes from this text" or "clean up em dashes"

Usage Examples in Claude Desktop:

Example Conversation
User: "Clean up the em dashes in this text: The result was clear — success!"

Claude: I'll clean up the em dashes in your text using the emdashguard tool.

[Using emdash_remover tool]

The text has been processed! Here's the cleaned version:
"The result was clear: success!"

The Smart Replace algorithm detected this as an explanation context and replaced the em dash with a colon, which is more appropriate for this type of sentence structure.
Batch Processing
User: "Remove em dashes from this document and use double hyphens instead of Smart Replace"

Claude: I'll process your text with emdashguard using double hyphens as the replacement token.

[Using emdash_remover tool with smart: false, replacement: "--"]

Your document has been processed with all em dashes replaced with double hyphens (--) as requested.

Generic MCP Client Configuration

For other MCP-compatible applications, use this general configuration:

{
  "mcpServers": {
    "emdashguard": {
      "command": "node",
      "args": ["-e", "require('http').request('https://emdashguard.com/api/mcp/tools').end()"],
      "env": {
        "EMDASHGUARD_API_BASE": "https://emdashguard.com"
      }
    }
  }
}
GET /api/mcp/tools

Retrieve available MCP tools.

Response

{
  "tools": [
    {
      "name": "emdash_remover",
      "description": "Remove em dashes from text using Smart Replace technology. Analyzes context to choose between colons (for explanations) and replacement tokens (for dialogue/pauses). Supports custom replacement tokens and spacing options.",
      "inputSchema": {
        "type": "object",
        "properties": {
          "text": {
            "type": "string",
            "description": "Text containing em dashes to process"
          },
          "smart": {
            "type": "boolean",
            "description": "Enable Smart Replace algorithm",
            "default": true
          },
          "replacement": {
            "type": "string",
            "description": "Token to replace em dashes with",
            "default": "--"
          },
          "spacing": {
            "type": "boolean",
            "description": "Add spaces around replacements",
            "default": true
          }
        },
        "required": ["text"]
      }
    }
  ]
}
POST /api/mcp

MCP (Model Context Protocol) JSON-RPC 2.0 endpoint for AI agents.

Request Body

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "emdash_remover",
    "arguments": {
      "text": "API — Application Programming Interface",
      "smart": true,
      "replacement": "--",
      "spacing": true
    }
  }
}

Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "API: Application Programming Interface"
      }
    ]
  }
}
Example MCP Call
curl -X POST https://emdashguard.com/api/mcp \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "emdash_remover",
      "arguments": {
        "text": "Note — this is important",
        "smart": true
      }
    }
  }'

Smart Replace Algorithm

The Smart Replace algorithm uses sentence boundary detection and pattern recognition to analyze text context and choose the most appropriate replacement for each em dash. It considers surrounding text, punctuation, and linguistic patterns to make intelligent replacement decisions.

How It Works

The algorithm analyzes a dynamic context window around each em dash, examining:

Replacement Rules

Single Dash (-) for Ranges and Compounds

Colon (:) for Explanations and Technical References

Double Dash (--) for Dialogue and Citations

Configuration Options

Option Description Impact
smart: true Enable context analysis Intelligent replacement selection
smart: false Disable context analysis Uniform replacement with chosen token
spacing: true Add spaces around replacements Better readability
spacing: false No automatic spacing Preserve original spacing

Code Examples

JavaScript/TypeScript

// Basic text processing
const response = await fetch('https://emdashguard.com/api/process-text', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    text: 'The result was clear — success!',
    smart: true
  })
});

const data = await response.json();
console.log(data.data.processedText); // "The result was clear: success!"

Python

import requests

response = requests.post('https://emdashguard.com/api/process-text', json={
    'text': 'API — Application Programming Interface',
    'smart': True,
    'replacement': '--',
    'spacing': True
})

data = response.json()
print(data['data']['processedText'])  # "API: Application Programming Interface"

Node.js with MCP

const axios = require('axios');

async function callMCP() {
  const response = await axios.post('https://emdashguard.com/api/mcp', {
    jsonrpc: '2.0',
    id: 1,
    method: 'tools/call',
    params: {
      name: 'emdash_remover',
      arguments: {
        text: 'Note — this is important',
        smart: true
      }
    }
  });

  console.log(response.data.result.content[0].text);
}

Error Handling

Error Codes

Code HTTP Status Description
INVALID_PARAMETERS 400 Missing or invalid request parameters
TEXT_TOO_LARGE 400 Input text exceeds 100,000 character limit
PROCESSING_ERROR 500 Internal processing error
INVALID_TOOL 400 Unknown MCP tool name

Error Response Format

{
  "success": false,
  "error": {
    "code": "ERROR_CODE",
    "message": "Human readable error message"
  }
}

Rate Limiting

Currently no rate limiting is implemented. For production use, consider implementing appropriate rate limiting based on your needs.

Security