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.
To install the MCP server, run:
npm install
Start the server using:
npm start
For development with hot reloading:
npm run dev:watch
The MCP server offers two main tools for text processing:
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.
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.
Here's how to use the MCP server in a typical workflow:
Create a template with placeholders in angle brackets:
{
"item": {
"name": "<name>",
"price": "<price>",
"description": "<description>"
}
}
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.
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
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"
}
}
When creating templates, follow these guidelines:
<name>
, <type>
, <price>
, etc.Example of a nested template:
{
"product": {
"details": {
"name": "<name>",
"category": "<category>"
},
"pricing": {
"amount": "<price>",
"currency": "USD"
}
},
"metadata": {
"timestamp": "2023-09-01T12:00:00Z"
}
}
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.
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.
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"
]
}
}
}
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.
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.