Content
# JSON Format/Minify MCP Server
A JSON format and minify tool server based on MCP (Model Context Protocol), supporting formatting JSON strings into a readable format or compressing them into a single line.
## Features
- **JSON Formatting**: Formats compressed JSON strings into a pretty, indented format
- **JSON Minifying**: Compresses formatted JSON into a single line, removing all whitespace characters
- **Key Sorting**: Option to sort JSON keys
- **UTF-8 Support**: Full support for Unicode characters
## Installation
### Environment Requirements
- Python 3.8+
- uv (Python package manager)
### Installation Steps
1. Clone the repository:
```bash
git clone https://github.com/masx200/json-minifiy-formatter-mcp.git
cd json-minifiy-formatter-mcp
```
2. Install dependencies using uv:
```bash
uv sync
```
## Configuration
### Environment Variables
- **HTTP_API_TOKEN** (Optional): Sets the HTTP Bearer authentication token for the streamable-http protocol. If set, all HTTP requests must include the `Authorization: Bearer <token>` header.
### Protocol Selection
This project supports two protocols:
- **stdio**: Standard input/output protocol
- **streamable-http**: Streamable HTTP protocol
### Cursor Configuration
#### stdio Protocol Configuration
Add the following to your Cursor MCP configuration file:
```json
{
"mcpServers": {
"json-minifiy-formatter-mcp": {
"name": "JSON Format / Minify",
"type": "stdio",
"description": "JSON Format / Minify",
"isActive": true,
"registryUrl": "https://pypi.tuna.tsinghua.edu.cn/simple",
"command": "uv",
"args": [
"run",
"D:\\github\\json-minifiy-formatter-mcp\\json_mcp-stdio.py"
]
}
}
}
```
#### streamable-http Protocol Configuration
**Basic Configuration (No Authentication):**
```json
{
"mcpServers": {
"json-minifiy-formatter-mcp-http": {
"transport": "streamable-http",
"name": "JSON Format / Minify (HTTP)",
"type": "http",
"description": "JSON Format / Minify (streamable-http)",
"isActive": true,
"url": "http://localhost:6600/mcp"
}
}
}
```
**Configuration with Authentication (Using HTTP_API_TOKEN):**
First, set the environment variable:
```bash
export HTTP_API_TOKEN="your-secret-token-here"
```
Then, add the headers to the configuration:
```json
{
"mcpServers": {
"json-minifiy-formatter-mcp-http": {
"transport": "streamable-http",
"name": "JSON Format / Minify (HTTP)",
"type": "http",
"description": "JSON Format / Minify (streamable-http)",
"isActive": true,
"url": "http://localhost:6600/mcp",
"headers": {
"Authorization": "Bearer your-secret-token-here"
}
}
}
}
```
### Claude Desktop Configuration
#### stdio Protocol Configuration
Add the following to your Claude Desktop configuration file:
```json
{
"mcpServers": {
"json-formatter": {
"command": "uv",
"args": ["run", "/path/to/json-minifiy-formatter-mcp/json_mcp-stdio.py"]
}
}
}
```
#### streamable-http Protocol Configuration
**Basic Configuration (No Authentication):**
```json
{
"mcpServers": {
"json-minifiy-formatter-mcp-http": {
"transport": "streamable-http",
"name": "JSON Format / Minify (HTTP)",
"type": "http",
"description": "JSON Format / Minify (streamable-http)",
"isActive": true,
"url": "http://localhost:6600/mcp"
}
}
}
```
**Configuration with Authentication (Using HTTP_API_TOKEN):**
First, set the environment variable:
```bash
export HTTP_API_TOKEN="your-secret-token-here"
```
Then, add the headers to the configuration:
```json
{
"mcpServers": {
"json-minifiy-formatter-mcp-http": {
"transport": "streamable-http",
"name": "JSON Format / Minify (HTTP)",
"type": "http",
"description": "JSON Format / Minify (streamable-http)",
"isActive": true,
"url": "http://localhost:6600/mcp",
"headers": {
"Authorization": "Bearer your-secret-token-here"
}
}
}
}
```
## Usage
### Tool 1: format_json - JSON Formatting
Formats a JSON string into a pretty, indented format.
**Parameters:**
- `raw` (string, Required): The raw JSON string
- `indent` (integer, Optional, Default: 2): Number of spaces for indentation
- `sort_keys` (boolean, Optional, Default: true): Whether to sort keys
**Example:**
```json
{ "name": "张三", "age": 25, "skills": ["Python", "JavaScript"] }
```
**Formatted:**
```json
{
"age": 25,
"name": "张三",
"skills": ["Python", "JavaScript"]
}
```
### Tool 2: minify_json - JSON Minifying
Compresses a JSON string into a single line, removing all whitespace characters.
**Parameters:**
- `raw` (string, Required): The raw JSON string
- `sort_keys` (boolean, Optional, Default: true): Whether to sort keys
**Example:**
```json
{
"name": "张三",
"age": 25,
"skills": ["Python", "JavaScript"]
}
```
**Minified:**
```json
{ "age": 25, "name": "张三", "skills": ["Python", "JavaScript"] }
```
## Development
### Local Run
#### stdio Protocol
```bash
uv run python json_mcp-stdio.py
```
#### streamable-http Protocol
**No Authentication Mode:**
```bash
uv run python json_mcp-streamable-http.py
```
**Authentication Mode (Set HTTP_API_TOKEN):**
```bash
# Linux/macOS
export HTTP_API_TOKEN="your-secret-token-here"
uv run python json_mcp-streamable-http.py
# Windows PowerShell
$env:HTTP_API_TOKEN="your-secret-token-here"
uv run python json_mcp-streamable-http.py
# Windows CMD
set HTTP_API_TOKEN=your-secret-token-here
uv run python json_mcp-streamable-http.py
```
After starting, the server will run on `http://localhost:6600`.
### Project Structure
```
json-minifiy-formatter-mcp/
├── json_mcp-stdio.py # stdio protocol main program file
├── json_mcp-streamable-http.py # streamable-http protocol main program file
├── pyproject.toml # Project configuration
├── uv.lock # Dependency lock file
├── README.md # Project description
└── LICENSE # License
```
### Technology Stack
- **Python 3.8+**: Main programming language
- **uv**: Python package manager
- **mcp**: Model Context Protocol library
- **asyncio**: Asynchronous programming support
Connection Info
You Might Also Like
everything-claude-code
Complete Claude Code configuration collection - agents, skills, hooks,...
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
cc-switch
All-in-One Assistant for Claude Code, Codex & Gemini CLI across platforms.
servers
Model Context Protocol Servers
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.