LessTokens Logo
Api Reference
Mcp Server

Documentation

Getting Started

  • Overview
  • Account Setup
  • First API Key
  • First Request
  • Understanding Metrics

API Reference

  • Overview
  • Authentication
  • Compressionnew
  • MCP Servernew
  • Errors

Integrations

  • Node.js / TypeScript
  • Python
  • cURL

Resources

  • Best Practices

Need help?

Join our community or contact support for assistance.

Contact Support →

MCP Server

new

Integrate LessToken's compression capabilities into your AI workflows using the Model Context Protocol (MCP). Use compression tools directly in Claude Desktop, Cursor IDE, Continue.dev, and other MCP-compatible clients.

What is MCP?

The Model Context Protocol (MCP) is an open protocol that standardizes how AI applications provide context and tools to language models. It enables seamless integration between AI assistants and external services.

Our MCP server exposes LessToken's compression engine as a standardized tool that can be used by any MCP-compatible client, including:

  • Claude Desktop - Use compression directly in Claude conversations
  • Cursor IDE - Integrate compression into your development workflow
  • Continue.dev - Access compression tools in your AI-assisted coding
  • Custom clients - Build your own integrations using the MCP SDK

Quick Start

Quick Install for Cursor

Install the MCP server in Cursor with one click. You'll need your API key ready.

Install in Cursor

Don't have an API key? Get one here

Note: After clicking the install button, you'll need to replace YOUR_API_KEY_HERE with your actual API key in the Cursor configuration.

1. Get Your API Key

First, you need an API key from LessToken. If you don't have one yet, follow our guide to create your first API key.

2. Configure Your MCP Client

Configure your MCP client (Claude Desktop, Cursor IDE, VS Code, Windsurf, etc.) to connect to our MCP server. See the integration guides below for platform-specific instructions.

3. Start Using Compression

Once configured, you can use the compress_text tool directly in your AI conversations to compress prompts and reduce token usage.

Server Endpoint

POST/api/mcp

The MCP server endpoint accepts JSON-RPC 2.0 requests following the MCP protocol specification. All requests must include authentication via API key.

Base URL

https://lesstokens.hive-hub.ai

Content-Type

application/json

Authentication

X-API-Key or Authorization header

Authentication

All MCP requests must include your API key. You can provide it in one of two ways:

Option 1: Authorization Header

Authorization Header
Authorization: Bearer YOUR_API_KEY

Option 2: X-API-Key Header

X-API-Key Header
X-API-Key: YOUR_API_KEY
Security Note: Keep your API key secure and never commit it to version control. For production use, consider using environment variables or secure credential storage.

Available Tools

compress_text

Compress text prompts to reduce token usage while preserving semantic meaning. This tool uses LessToken's intelligent compression engine with automatic optimization. Only the prompt field is required.

Input Parameters

Input Schema
{
  "prompt": "string (required, 1-100000 chars)"
}

The tool uses automatic optimization - no options needed. Just provide your text prompt.

Output Format

Output Schema
{
  "compressed": "string",
  "originalTokens": "number",
  "compressedTokens": "number",
  "tokensSaved": "number",
  "compressionRatio": "number",
  "processingTimeMs": "number"
}

Example Response

Example Response
{
  "compressed": "Compressed text here...",
  "originalTokens": 150,
  "compressedTokens": 95,
  "tokensSaved": 55,
  "compressionRatio": 0.633,
  "processingTimeMs": 234
}

Platform Integrations

Claude Desktop

Use compression directly in Claude conversations. Configure Claude Desktop to connect to our MCP server.

Setup Guide

Cursor IDE

Integrate compression into your development workflow. Access compression tools while coding.

Setup Guide

VS Code

Use compression in VS Code with MCP-compatible extensions. Configure VS Code to connect to our MCP server.

Setup Guide

Windsurf

Integrate compression into Windsurf AI coding assistant. Configure Windsurf to use our MCP server.

Setup Guide

Continue.dev

Use compression in your AI-assisted coding sessions. Configure Continue.dev to use our MCP server.

Setup Guide

Claude Code

Use compression in Claude Code editor. Configure Claude Code to connect to our MCP server.

Setup Guide

Code Examples

TypeScript / Node.js

typescript-example.ts
import { Client } from '@modelcontextprotocol/sdk/client/index.js';

const client = new Client({
  name: 'less-token-client',
  version: '1.0.0',
}, {
  capabilities: {},
});

// Connect to MCP server
await client.connect({
  type: 'http',
  url: 'https://lesstokens.hive-hub.ai/api/mcp',
  headers: {
    'X-API-Key': 'YOUR_API_KEY',
  },
});

// Call compress_text tool (only prompt field required)
const result = await client.callTool({
  name: 'compress_text',
  arguments: {
    prompt: 'Your long text prompt here...',
  },
});

console.log('Compressed:', result.content[0].text);
console.log('Tokens saved:', result.structuredContent?.tokensSaved);

Python

python-example.py
import requests
import json

# MCP server endpoint
url = "https://lesstokens.hive-hub.ai/api/mcp"

# Prepare JSON-RPC request (only prompt field required)
payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
        "name": "compress_text",
        "arguments": {
            "prompt": "Your long text prompt here..."
        }
    }
}

headers = {
    "Content-Type": "application/json",
    "X-API-Key": "YOUR_API_KEY"
}

# Make request
response = requests.post(url, json=payload, headers=headers)
result = response.json()

# Parse result
if "result" in result:
    compressed_data = json.loads(result["result"]["content"][0]["text"])
    print(f"Compressed: {compressed_data['compressed']}")
    print(f"Tokens saved: {compressed_data['tokensSaved']}")

cURL

curl-example.sh
curl -X POST https://lesstokens.hive-hub.ai/api/mcp \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "compress_text",
      "arguments": {
        "prompt": "Your long text prompt here..."
      }
    }
  }'

Error Handling

The MCP server follows the JSON-RPC 2.0 error specification. All errors include an error code, message, and optional data field with additional context.

Common Error Codes

-32001

Authentication Error - Invalid or missing API key

-32601

Method Not Found - Invalid method name

-32603

Internal Error - Server-side error during processing

-32000

Rate Limit Exceeded - Too many requests

Example Error Response

Error Response
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32001,
    "message": "Authentication required",
    "data": {
      "type": "AUTHENTICATION_ERROR",
      "docs": "https://docs.lesstoken.com/api-reference/authentication"
    }
  }
}

Best Practices

Secure API Key Storage

Store your API key in environment variables or secure credential storage. Never commit API keys to version control.

Handle Errors Gracefully

Always check for errors in responses and implement proper error handling. Use the error codes to provide meaningful feedback to users.

Respect Rate Limits

Monitor your rate limit usage and implement exponential backoff for retries. Check rate limit headers in responses.

Automatic Optimization

The compression engine automatically selects the best optimization strategies based on your content. No configuration needed - just provide your prompt and get optimized results.

Additional Resources

Authentication Guide

Learn more about API key authentication and security best practices.

MCP Specification

Read the official Model Context Protocol specification and documentation.