Custom Context MCP Server
This Model Context Protocol (MCP) server provides tools for structuring and extracting data from text according to JSON templates.
Features
Text-to-JSON Transformation
- Group and structure text based on JSON templates with placeholders
- Extract information from AI-generated text into structured JSON formats
- Support for any arbitrary JSON structure with nested placeholders
- Intelligent extraction of key-value pairs from text
- Process AI outputs into structured data for downstream applications
Getting Started
Installation
Running the server
For development with hot reloading:
Usage
This MCP server provides two main tools:
1. Group Text by JSON (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.
The tool analyzes the template, extracts placeholder keys, and returns a prompt that guides the AI to extract information in a key-value format.
2. Text to JSON (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.
It extracts key-value pairs from the text and structures them according to the template.
Example Workflow
- Define a JSON template with placeholders:Copy
- Use
group-text-by-json
to create a prompt for AI:- The tool identifies placeholder keys: name, price, description
- Generates a prompt instructing the AI to group information by these keys
- Send the prompt to an AI model and receive grouped text:Copy
- Use
text-to-json
to convert the grouped text to JSON:- Result:
Copy
Template Format
Templates can include placeholders anywhere within a valid JSON structure:
- Use angle brackets to define placeholders:
<name>
,<type>
,<price>
, etc. - The template must be a valid JSON string
- Placeholders can be at any level of nesting
- Supports complex nested structures
Example template with nested placeholders:
Implementation Details
The server works by:
- Analyzing JSON templates to extract placeholder keys
- Generating prompts that guide AI models to extract information by these keys
- Parsing AI-generated text to extract key-value pairs
- Reconstructing JSON objects based on the original template structure
Development
Prerequisites
- Node.js v18 or higher
- npm or yarn
Build and Run
Custom Hot Reloading
This project includes a custom hot reloading setup that combines:
- nodemon: Watches for file changes in the src directory and rebuilds TypeScript files
- browser-sync: Automatically refreshes the browser when build files change
- Concurrent execution: Runs both services simultaneously with output synchronization
The setup is configured in:
nodemon.json
: Controls TypeScript watching and rebuildingpackage.json
: Uses concurrently to run nodemon and browser-sync together
To use the custom hot reloading feature:
This creates a development environment where:
- TypeScript files are automatically rebuilt when changed
- The MCP server restarts with the updated code
- Connected browsers refresh to show the latest changes
Using with MCP Inspector
You can use the MCP Inspector for debugging:
This runs the server with the MCP Inspector for visual debugging of requests and responses.
You must be authenticated.
A Model Context Protocol server that transforms text into structured JSON data using templates with placeholders.