Skip to main content
Glama
Custom Context MCP Server

Custom Context MCP Server

by omer-ayhan

カスタムコンテキストMCPサーバー

このモデル コンテキスト プロトコル (MCP) サーバーは、JSON テンプレートに従ってテキストを構造化し、テキストからデータを抽出するためのツールを提供します。

特徴

テキストからJSONへの変換

  • プレースホルダー付きのJSONテンプレートに基づいてテキストをグループ化および構造化する

  • AI生成テキストから情報を抽出し、構造化されたJSON形式に変換する

  • ネストされたプレースホルダーを持つ任意の JSON 構造のサポート

  • テキストからのキーと値のペアのインテリジェントな抽出

  • AI出力を下流アプリケーション向けの構造化データに処理する

Related MCP server: Unstructured Document Processor MCP

はじめる

インストール

npm install

サーバーの実行

npm start

ホットリロードを使用した開発の場合:

npm run dev:watch

使用法

この MCP サーバーは、主に 2 つのツールを提供します。

1. JSONでテキストをグループ化する( group-text-by-json )

このツールは、プレースホルダー付きの JSON テンプレートを受け取り、テンプレートの構造に従って AI がテキストをグループ化するためのプロンプトを生成します。

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

このツールはテンプレートを分析し、プレースホルダー キーを抽出し、キーと値の形式で情報を抽出できるように AI をガイドするプロンプトを返します。

2. テキストからJSONへ( text-to-json )

このツールは、前のステップでグループ化されたテキスト出力を取得し、元のテンプレートに基づいて構造化された JSON オブジェクトに変換します。

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

テキストからキーと値のペアを抽出し、テンプレートに従って構造化します。

ワークフローの例

  1. プレースホルダーを含む JSON テンプレートを定義します。

    {
     "item": {
         "name": "<name>",
         "price": "<price>",
         "description": "<description>"
     }
    }
  2. AI のプロンプトを作成するには、 group-text-by-jsonを使用します。

    • このツールはプレースホルダーキー(名前、価格、説明)を識別します。

    • AIにこれらのキーで情報をグループ化するように指示するプロンプトを生成します

  3. プロンプトを AI モデルに送信し、グループ化されたテキストを受信します。

    name: Blue Pen
    price: $2.99
    description: A smooth-writing ballpoint pen with blue ink
  4. グループ化されたテキストを JSON に変換するには、 text-to-jsonを使用します。

    • 結果: GXP8

テンプレート形式

テンプレートには、有効な JSON 構造内の任意の場所にプレースホルダーを含めることができます。

  • 山括弧を使用してプレースホルダーを定義します: <name> 、 <type> 、 <price>など。

  • テンプレートは有効なJSON文字列である必要があります

  • プレースホルダはどの階層にあっても構いません

  • 複雑なネスト構造をサポート

ネストされたプレースホルダーを含むテンプレートの例:

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

実装の詳細

サーバーは次のように動作します:

  1. JSONテンプレートを分析してプレースホルダーキーを抽出する

  2. これらのキーで情報を抽出できるようにAIモデルを誘導するプロンプトを生成する

  3. AI生成テキストを解析してキーと値のペアを抽出する

  4. 元のテンプレート構造に基づいてJSONオブジェクトを再構築する

発達

前提条件

  • Node.js v18以上

  • npmまたはyarn

ビルドと実行

# Install dependencies
npm install

# Build the project
npm run build

# Run the server
npm start

# Development with hot reloading
npm run dev:watch

カスタムホットリロード

このプロジェクトには、以下を組み合わせたカスタム ホット リロード セットアップが含まれています。

  • nodemon : src ディレクトリ内のファイルの変更を監視し、TypeScript ファイルを再構築します。

  • browser-sync : ビルドファイルが変更されるとブラウザを自動的に更新します

  • 同時実行:出力同期で両方のサービスを同時に実行します

セットアップは次の場所で構成されます:

  • nodemon.json : TypeScriptの監視と再構築を制御する

  • package.json : nodemon と browser-sync を同時に実行するために使用します

カスタム ホット リロード機能を使用するには:

npm run dev:watch

これにより、次のような開発環境が作成されます。

  1. TypeScriptファイルは変更されると自動的に再構築されます

  2. MCPサーバーは更新されたコードで再起動します

  3. 接続されたブラウザは最新の変更を表示するために更新されます

MCP Inspectorと併用

デバッグには MCP Inspector を使用できます。

npm run dev

これにより、リクエストと応答を視覚的にデバッグするための MCP Inspector を使用してサーバーが実行されます。

Available Tools

2 tools
group-text-by-jsonC

Gives a prompt text for AI to group text based on JSON placeholders. This tool accepts a JSON template with placeholders.

Inputs: template (required).

text-to-jsonB

Converts groupped text from group-text-by-json tool to JSON. This tool accepts a JSON template with placeholders and groupped text from group-text-by-json tool.

Inputs: template (required), text (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have clearly distinct purposes: group-text-by-json prepares text for grouping based on a JSON template, while text-to-json converts that grouped text into JSON. There is no overlap or ambiguity between them, as they represent sequential steps in a workflow.

    Naming Consistency5/5

    Both tools follow a consistent verb-noun pattern with hyphens (group-text-by-json and text-to-json), clearly indicating their actions and targets. The naming is predictable and readable across the set.

    Tool Count2/5

    With only 2 tools, the server feels thin for its apparent purpose of custom context management. This minimal set may limit functionality and require agents to work around gaps, as typical context-related operations might include more than just grouping and conversion.

    Completeness2/5

    The tool surface is severely incomplete for a custom context server. It lacks core operations such as creating, updating, deleting, or retrieving context entries, and only covers a narrow text-to-JSON conversion workflow, leaving significant gaps that will likely cause agent failures.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      C
      quality
      F
      maintenance
      A Model Context Protocol server implementation that enables LLMs to query and manipulate JSON data using JSONPath syntax with extended operations for filtering, sorting, transforming, and aggregating data.
      2
      90
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A Model Context Protocol server for querying large JSON files using JSONPath expressions, enabling LLMs to efficiently search and extract information from large JSON data.
      3
      11
      MIT
    • -
      license
      B
      quality
      Not graded
      maintenance
      A Model Context Protocol server that enables AI models to extract structured data from websites through the extract\_structured\_data tool.
      1
      23 npm
      -