Custom Context Transformer MCP server

Transforms unstructured text into structured JSON data using customizable templates with placeholders for extracting key information and generating structured outputs for downstream processing.
Back to servers
Provider
Omer Ayhan
Release date
Apr 08, 2025
Language
TypeScript
Stats
1 star

The Model Context Protocol (MCP) server provides tools to transform and structure text according to JSON templates, allowing you to extract information from text into structured JSON formats. It's particularly useful for processing AI-generated outputs into structured data for downstream applications.

Installation

To install the MCP server, run:

npm install

Running the Server

Start the server using:

npm start

For development with hot reloading:

npm run dev:watch

Core Functionality

The MCP server offers two main tools for text processing:

Group Text by JSON

This tool takes a JSON template with placeholders and generates a prompt for an AI to group text according to the template's structure.

Example request:

{
	"template": "{ \"type\": \"<type>\", \"text\": \"<text>\" }"
}

The tool analyzes the template, extracts placeholder keys, and returns a prompt that guides the AI to extract information in a key-value format.

Text to JSON

This tool converts grouped text output into a structured JSON object based on the original template.

Example request:

{
	"template": "{ \"type\": \"<type>\", \"text\": \"<text>\" }",
	"text": "type: pen\ntext: This is a blue pen"
}

It extracts key-value pairs from the text and structures them according to the template.

Complete Workflow Example

Here's how to use the MCP server in a typical workflow:

1. Define a JSON Template with Placeholders

Create a template with placeholders in angle brackets:

{
	"item": {
		"name": "<name>",
		"price": "<price>",
		"description": "<description>"
	}
}

2. Generate a Prompt for AI

Use the group-text-by-json tool to create a prompt for your AI model. The tool identifies the placeholder keys (name, price, description) and generates a prompt instructing the AI to group information by these keys.

3. Process AI Response

Send the prompt to an AI model and receive grouped text like:

name: Blue Pen
price: $2.99
description: A smooth-writing ballpoint pen with blue ink

4. Convert Text to Structured JSON

Use the text-to-json tool to convert the grouped text to JSON:

{
	"item": {
		"name": "Blue Pen",
		"price": "$2.99",
		"description": "A smooth-writing ballpoint pen with blue ink"
	}
}

Template Format Guidelines

When creating templates, follow these guidelines:

  • Use angle brackets to define placeholders: <name>, <type>, <price>, etc.
  • Ensure the template is a valid JSON string
  • Placeholders can be at any level of nesting
  • Complex nested structures are supported

Example of a nested template:

{
	"product": {
		"details": {
			"name": "<name>",
			"category": "<category>"
		},
		"pricing": {
			"amount": "<price>",
			"currency": "USD"
		}
	},
	"metadata": {
		"timestamp": "2023-09-01T12:00:00Z"
	}
}

Debugging

For debugging purposes, you can use the MCP Inspector:

npm run dev

This runs the server with the MCP Inspector for visual debugging of requests and responses.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later