Key-Value Extractor 标志

Key-Value Extractor

社区
KunihiroS

This MCP server extracts key-value pairs from arbitrary, noisy, or unstructured text using LLMs (GPT-4.1-mini) and pydantic-ai. It keeps type safety and supports multiple output formats (JSON, YAML, TOML). The server is robust to any input and always attempts to structure data as much as possible.

发布者KunihiroS
代码仓库kv-extractor-mcp-server
语言Python
复刻数
3
星标数
1
可用工具
0
传输类型stdio
分类
许可协议GPL-3.0
链接
  • 将工具接入 AI 工作流

    Key-Value Extractor 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 1 个 Star 和 3 个 Fork。

Flexible Key-Value Extracting MCP Server

smithery badge

Version: 0.3.2

This MCP server extracts key-value pairs from arbitrary, noisy, or unstructured text using LLMs (GPT-4.1-mini) and pydantic-ai. It ensures type safety and supports multiple output formats (JSON, YAML, TOML). The server is robust to any input and always attempts to structure data as much as possible, however, perfect extraction is not guaranteed.


🤔💡 Why Use This MCP Server?

While many Large Language Model (LLMs) services offer structured output capabilities, this MCP server provides distinct advantages for key-value extraction, especially from challenging real-world text:

  • 🔑🔍 Automatic Key Discovery: A core strength is its ability to autonomously identify and extract relevant key-value pairs from unstructured text without requiring pre-defined keys. While typical LLM structured outputs need you to specify the keys you're looking for, this server discovers them, making it highly effective for diverse and unpredictable data where the structure is not known beforehand.
  • 💪🧱 Superior Robustness for Complex Inputs: It excels with arbitrary, noisy, or unstructured text where standard LLM structured outputs might falter. The multi-step pipeline is specifically designed to sift through and make sense of imperfect data.
  • 🌐🗣️ Advanced Multi-Lingual Preprocessing: Before LLM processing, it leverages spaCy for Named Entity Recognition (NER) in Japanese, English, and Chinese (Simplified/Traditional), significantly enhancing extraction accuracy for these languages by providing context-rich candidate phrases.
  • 🔄✍️ Iterative Refinement and Typing: Unlike a single-pass extraction, this server employs a sophisticated pipeline including LLM-based type annotation, LLM-based type evaluation, and rule-based/LLM-fallback normalization. This ensures more accurate and contextually appropriate data types.
  • ✅🛡️ Guaranteed Type Safety and Schema Adherence: Final structuring with Pydantic ensures that the output is not only structured but also type-safe and validated against a defined schema, providing reliable data for downstream applications.
  • 📊⚙️ Consistent and Predictable Output: The server is designed to always return a well-formed response, even if extraction is partial or encounters issues, which is critical for building robust automated systems.

Release Notes

v0.3.2

  • Fix: FastMCP caused error.

v0.3.1

  • Update: Improve type evaluation prompt for robust correction.
  • Update: Added the strong point of this MCP server on README.md

v0.2.0

  • Fix: Lang code for zh-cn / zh-tw.

v0.1.0

  • Initial release

Tools

  • /extract_json : Extracts type-safe key-value pairs in JSON format from input text.
  • /extract_yaml : Extracts type-safe key-value pairs in YAML format from input text.
  • /extract_toml : Extracts type-safe key-value pairs in TOML format from input text.
    • Note: Due to TOML specifications, arrays of objects (dicts) or deeply nested structures cannot be directly represented. See "Note on TOML Output Limitations" below for details.

Note:

  • Supported languages: Japanese, English, and Chinese (Simplified: zh-cn / Traditional: zh-tw).
  • Extraction relies on pydantic-ai and LLMs. Perfect extraction is not guaranteed.
  • Longer input sentences will take more time to process. Please be patient.
  • On first launch, the server will download spaCy models, so the process will take longer initially.

Estimated Processing Time Sample

Input TokensInput Characters (approx.)Measured Processing Time (sec)Model Configuration
200~400~15gpt-4.1-mini

Actual processing time may vary significantly depending on API response, network conditions, and model load. Even short texts may take 15 seconds or more.

Features

  • Flexible extraction: Handles any input, including noisy or broken data.
  • JP / EN / ZH-CN / ZH-TW full support: Preprocessing with spaCy NER by automatic language detection (Japanese, English, Chinese [Simplified: zh-cn / Traditional: zh-tw] supported; others are rejected with error).
  • Type-safe output: Uses Pydantic for output validation.
  • Multiple formats: Returns results as JSON, YAML, or TOML.
  • Robust error handling: Always returns a well-formed response, even on failure.
  • High accuracy: Uses GPT-4.1-mini for both extraction/annotation and type evaluation, with Pydantic for final structuring.

Tested Scenarios

The server has been tested with various inputs, including:

  • Simple key-value pairs
  • Noisy or unstructured text with important information buried within
  • Different data formats (JSON, YAML, TOML) for output

Processing Flow

Below is a flowchart representing the processing flow of the key-value extraction pipeline as implemented in server.py:

Preprocessing with spaCy (Multilingual NER)

This server uses spaCy with automatic language detection to extract named entities from the input text before passing it to the LLM. Supported languages are Japanese (ja_core_news_md), English (en_core_web_sm), and Chinese (Simplified/Traditional, zh_core_web_sm).

  • The language of the input text is automatically detected using langdetect.

  • If the detected language is not Japanese, English, or Chinese, the server returns an error: Unsupported lang detected.

  • The appropriate spaCy model is automatically downloaded and loaded as needed. No manual installation is required.

  • The extracted phrase list is included in the LLM prompt as follows:

    [Preprocessing Candidate Phrases (spaCy NER)] The following is a list of phrases automatically extracted from the input text using spaCy's detected language model. These phrases represent detected entities such as names, dates, organizations, locations, numbers, etc. This list is for reference only and may contain irrelevant or incorrect items. The LLM uses its own judgment and considers the entire input text to flexibly infer the most appropriate key-value pairs.

Step Details

This project's key-value extraction pipeline consists of multiple steps. Each step's details are as follows:

Step 0: Preprocessing with spaCy (Language Detection → Named Entity Recognition)

  • Purpose: Automatically detect the language of the input text and use the appropriate spaCy model (e.g., ja_core_news_md, en_core_web_sm, zh_core_web_sm) to extract named entities.
  • Output: The extracted phrase list, which is included in the LLM prompt as a hint to improve key-value pair extraction accuracy.

Step 1: Key-Value Extraction (LLM)

  • Purpose: Use GPT-4.1-mini to extract key-value pairs from the input text and the extracted phrase list.
  • Details:
    • The prompt includes instructions to return list-formatted values when the same key appears multiple times.
    • Few-shot examples are designed to include list-formatted outputs.
  • Output: Example: key: person, value: ["Tanaka", "Sato"]

Step 2: Type Annotation (LLM)

  • Purpose: Use GPT-4.1-mini to infer the data type (int, str, bool, list, etc.) of each key-value pair extracted in Step 1.
  • Details:
    • The type annotation prompt includes instructions for list and multiple value support.
  • Output: Example: key: person, value: ["Tanaka", "Sato"] -> list[str]

Step 3: Type Evaluation (LLM)

  • Purpose: Use GPT-4.1-mini to evaluate and correct the type annotations from Step 2.
  • Details:
    • For each key-value pair, GPT-4.1-mini re-evaluates the type annotation's validity and context.
    • If type errors or ambiguities are detected, GPT-4.1-mini automatically corrects or supplements the type.
    • Example: Correcting a value extracted as a number but should be a string, or determining whether a value is a list or a single value.
  • Output: The type-evaluated key-value pair list.

Step 4: Type Normalization (Static Rules + LLM Fallback)

  • Purpose: Convert the type-evaluated data into Python's standard types (int, float, bool, str, list, None, etc.).
  • Details:
    • Apply static normalization rules (regular expressions or type conversion functions) to convert values into Python's standard types.
    • Example: Converting comma-separated values to lists, "true"/"false" to bool, or date expressions to standard formats.
    • If static rules cannot convert a value, use LLM-based type conversion fallback.
    • Unconvertible values are safely handled as None or str.
  • Output: The Python-type-normalized key-value pair list.

Step 5: Final Structuring with Pydantic

  • Purpose: Validate and structure the type-normalized data using Pydantic models (KVOut/KVPayload).
  • Details:
    • Map each key-value pair to Pydantic models, ensuring type safety and data integrity.
    • Validate single values, lists, null, and composite types according to the schema.
    • If validation fails, attach error information while preserving as much data as possible.
    • The final output is returned in the specified format (JSON, YAML, or TOML).
  • Output: The type-safe and validated dict or specified format (JSON/YAML/TOML) output.

This pipeline is designed to accommodate future list format support and Pydantic schema extensions.

Note on TOML Output Limitations

  • In TOML, simple arrays (e.g., items = ["A", "B"]) can be represented natively, but arrays of objects (dicts) or deeply nested structures cannot be directly represented due to TOML specifications.
  • Therefore, complex lists or nested structures (e.g., [{"name": "A"}, {"name": "B"}]) are stored as "JSON strings" in TOML values.
  • This is a design choice to prevent information loss due to TOML's specification limitations.
  • YAML and JSON formats can represent nested structures as-is.

Example Input/Output

Input:

Thank you for your order (Order Number: ORD-98765). Product: High-Performance Laptop, Price: 89,800 JPY (tax excluded), Delivery: May 15-17. Shipping address: 1-2-3 Shinjuku, Shinjuku-ku, Tokyo, Apartment 101. Phone: 090-1234-5678. Payment: Credit Card (VISA, last 4 digits: 1234). For changes, contact support@example.com.

Output (JSON):

json
{
  "order_number": "ORD-98765",
  "product_name": "High-Performance Laptop",
  "price": 89800,
  "price_currency": "JPY",
  "tax_excluded": true,
  "delivery_start_date": "20240515",
  "delivery_end_date": "20240517",
  "shipping_address": "1-2-3 Shinjuku, Shinjuku-ku, Tokyo, Apartment 101",
  "phone_number": "090-1234-5678",
  "payment_method": "Credit Card",
  "card_type": "VISA",
  "card_last4": "1234",
  "customer_support_email": "support@example.com"
}

Output (YAML):

yaml
order_number: ORD-98765
product_name: High-Performance Laptop
price: 89800
price_currency: JPY
tax_excluded: true
delivery_start_date: '20240515'
delivery_end_date: '20240517'
shipping_address: 1-2-3 Shinjuku, Shinjuku-ku, Tokyo, Apartment 101
phone_number: 090-1234-5678
payment_method: Credit Card
card_type: VISA
card_last4: '1234'
customer_support_email: support@example.com

Output (TOML, simple case):

toml
order_number = "ORD-98765"
product_name = "High-Performance Laptop"
price = 89800
price_currency = "JPY"
tax_excluded = true
delivery_start_date = "20240515"
delivery_end_date = "20240517"
shipping_address = "1-2-3 Shinjuku, Shinjuku-ku, Tokyo, Apartment 101"
phone_number = "090-1234-5678"
payment_method = "Credit Card"
card_type = "VISA"
card_last4 = "1234"

Output (TOML, complex case):

toml
items = '[{"name": "A", "qty": 2}, {"name": "B", "qty": 5}]'
addresses = '[{"city": "Tokyo", "zip": "160-0022"}, {"city": "Osaka", "zip": "530-0001"}]'

Note: Arrays of objects or nested structures are stored as JSON strings in TOML.

Tools

1. extract_json

  • Description: Extracts key-value pairs from arbitrary noisy text and returns them as type-safe JSON (Python dict).
  • Arguments:
    • input_text (string): Input string containing noisy or unstructured data.
  • Returns: { "success": True, "result": ... } or { "success": False, "error": ... }
  • Example:
    json
    {
      "success": true,
      "result": { "foo": 1, "bar": "baz" }
    }

2. extract_yaml

  • Description: Extracts key-value pairs from arbitrary noisy text and returns them as type-safe YAML (string).
  • Arguments:
    • input_text (string): Input string containing noisy or unstructured data.
  • Returns: { "success": True, "result": ... } or { "success": False, "error": ... }
  • Example:
    json
    {
      "success": true,
      "result": "foo: 1\nbar: baz"
    }

3. extract_toml

  • Description: Extracts key-value pairs from arbitrary noisy text and returns them as type-safe TOML (string).
  • Arguments:
    • input_text (string): Input string containing noisy or unstructured data.
  • Returns: { "success": True, "result": ... } or { "success": False, "error": ... }
  • Example:
    json
    {
      "success": true,
      "result": "foo = 1\nbar = \"baz\""
    }

Usage

Installing via Smithery

To install kv-extractor-mcp-server for Claude Desktop automatically via Smithery:

bash
npx -y @smithery/cli install @KunihiroS/kv-extractor-mcp-server --client claude

Requirements

  • Python 3.9+
  • API key for OpenAI models (set in settings.json under env)

Running the Server

bash
python server.py

In case you want to run the server manually.

MCP Host Configuration

When running this MCP Server, you must explicitly specify the log output mode and (if enabled) the absolute log file path via command-line arguments.

  • --log=off : Disable all logging (no logs are written)
  • --log=on --logfile=/absolute/path/to/logfile.log : Enable logging and write logs to the specified absolute file path
  • Both arguments are required when logging is enabled. The server will exit with an error if either is missing, the path is not absolute, or if invalid values are given.

Example: Logging Disabled

json
"kv-extractor-mcp-server": {
  "command": "pipx",
  "args": ["run", "kv-extractor-mcp-server", "--log=off"],
  "env": {
    "OPENAI_API_KEY": "{apikey}"
  }
}

Example: Logging Enabled (absolute log file path required)

json
"kv-extractor-mcp-server": {
  "command": "pipx",
  "args": ["run", "kv-extractor-mcp-server", "--log=on", "--logfile=/workspace/logs/kv-extractor-mcp-server.log"],
  "env": {
    "OPENAI_API_KEY": "{apikey}"
  }
}

Note:

  • When logging is enabled, logs are written only to the specified absolute file path. Relative paths or omission of --logfile will cause an error.
  • When logging is disabled, no logs are output.
  • If the required arguments are missing or invalid, the server will not start and will print an error message.
  • The log file must be accessible and writable by the MCP Server process.
  • If you have trouble to run this server, it may be due to caching older version of kv-extractor-mcp-server. Please try to run it with the latest version (set x.y.z to the latest version) of kv-extractor-mcp-server by the below setting.
json
"kv-extractor-mcp-server": {
  "command": "pipx",
  "args": ["run", "kv-extractor-mcp-server==x.y.z", "--log=off"],
  "env": {
    "OPENAI_API_KEY": "{apikey}"
  }
}

License

GPL-3.0-or-later

Author

KunihiroS (and contributors)

安装

TypingMind
前提条件:

Node.js 18+

{
  "mcpServers": {
    "kv-extractor-mcp-server": {
      "command": "pipx",
      "args": [
        "run",
        "kv-extractor-mcp-server",
        "--log=off"
      ],
      "env": {
        "OPENAI_API_KEY": "{apikey}"
      }
    }
  }
}

将 Key-Value Extractor MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 Key-Value Extractor 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 Key-Value Extractor 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 Key-Value Extractor MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "key-value-extractor": {
      "command": "npx",
      "args": [
        "-y",
        "kv-extractor-mcp-server"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 Key-Value Extractor MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 Key-Value Extractor MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 Key-Value Extractor 帮我完成这项任务吗?
Key-Value Extractor
当然。我已阅读。
以下是我使用 Key-Value Extractor 得到的结果。

常见问题

Key-Value Extractor MCP 服务器有什么用途?

Key-Value Extractor 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 Key-Value Extractor MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 Key-Value Extractor,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 Key-Value Extractor MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 Key-Value Extractor 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 Key-Value Extractor MCP 连接到 TypingMind?

Key-Value Extractor 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

Key-Value Extractor MCP 在 TypingMind 中提供哪些工具?

Key-Value Extractor 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 Key-Value Extractor MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 Key-Value Extractor 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇