Skip to main content
Glama

Custom Context MCP Server

by omer-ayhan

自定义上下文 MCP 服务器

该模型上下文协议 (MCP) 服务器提供根据 JSON 模板构建和提取文本数据的工具。

特征

文本到 JSON 的转换

  • 根据带有占位符的 JSON 模板对文本进行分组和结构化
  • 将 AI 生成的文本中的信息提取为结构化的 JSON 格式
  • 支持任意带有嵌套占位符的 JSON 结构
  • 从文本中智能提取键值对
  • 将 AI 输出处理为下游应用程序的结构化数据

入门

安装

npm install

运行服务器

npm start

对于使用热重载进行开发:

npm run dev:watch

用法

该 MCP 服务器提供了两个主要工具:

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. 使用group-text-by-json为 AI 创建提示:
    • 该工具识别占位符键:名称、价格、描述
    • 生成提示,指示 AI 按这些键对信息进行分组
  3. 将提示发送给 AI 模型并接收分组文本:
    name: Blue Pen price: $2.99 description: A smooth-writing ballpoint pen with blue ink
  4. 使用text-to-json将分组文本转换为 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 运行服务器,以便对请求和响应进行可视化调试。

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

模型上下文协议服务器使用带有占位符的模板将文本转换为结构化的 JSON 数据。

  1. 特征
    1. 文本到 JSON 的转换
  2. 入门
    1. 安装
    2. 运行服务器
  3. 用法
    1. 按 JSON 分组文本( group-text-by-json )
    2. 2.文本转JSON( text-to-json )
  4. 示例工作流程
    1. 模板格式
      1. 实现细节
        1. 发展
          1. 先决条件
          2. 构建并运行
          3. 自定义热重载
          4. 与 MCP Inspector 一起使用

        Related MCP Servers

        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol server that provides web content fetching and conversion capabilities.
          Last updated -
          4
          89
          2
          JavaScript
          MIT License
          • Apple
        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol server that extracts embedded data (such as i18n translations or key/value configurations) from TypeScript/JavaScript source code into structured JSON configuration files.
          Last updated -
          2
          14
          2
          JavaScript
          MIT License
        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol server that provides tools for code modification and generation via Large Language Models, allowing users to create, modify, rewrite, and delete files using structured XML instructions.
          Last updated -
          12
          Python
          MIT License
          • Linux
          • Apple
        • A
          security
          A
          license
          A
          quality
          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.
          Last updated -
          2
          116
          24
          JavaScript
          MIT License
          • Apple
          • Linux

        View all related MCP servers

        MCP directory API

        We provide all the information about MCP servers via our MCP API.

        curl -X GET 'https://glama.ai/api/mcp/v1/servers/omer-ayhan/custom-context-mcp'

        If you have feedback or need assistance with the MCP directory API, please join our Discord server