
自定义上下文
STDIO文本转JSON模板化数据结构工具
文本转JSON模板化数据结构工具
This Model Context Protocol (MCP) server provides tools for structuring and extracting data from text according to JSON templates.
npm install
npm start
For development with hot reloading:
npm run dev:watch
This MCP server provides two main tools:
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.
{ "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 takes the grouped text output from the previous step and converts it into a structured JSON object based on the original template.
{ "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.
Define a JSON template with placeholders:
{ "item": { "name": "<name>", "price": "<price>", "description": "<description>" } }
Use group-text-by-json
to create a prompt for AI:
Send the prompt to an AI model and receive grouped text:
name: Blue Pen
price: $2.99
description: A smooth-writing ballpoint pen with blue ink
Use text-to-json
to convert the grouped text to JSON:
{ "item": { "name": "Blue Pen", "price": "$2.99", "description": "A smooth-writing ballpoint pen with blue ink" } }
Templates can include placeholders anywhere within a valid JSON structure:
<name>
, <type>
, <price>
, etc.Example template with nested placeholders:
{ "product": { "details": { "name": "<name>", "category": "<category>" }, "pricing": { "amount": "<price>", "currency": "USD" } }, "metadata": { "timestamp": "2023-09-01T12:00:00Z" } }
The server works by:
# Install dependencies npm install # Build the project npm run build # Run the server npm start # Development with hot reloading npm run dev:watch
This project includes a custom hot reloading setup that combines:
The setup is configured in:
nodemon.json
: Controls TypeScript watching and rebuildingpackage.json
: Uses concurrently to run nodemon and browser-sync togetherTo use the custom hot reloading feature:
npm run dev:watch
This creates a development environment where:
You can use the MCP Inspector for debugging:
npm run dev
This runs the server with the MCP Inspector for visual debugging of requests and responses.