关键词搜索服务器

一个基于Python和FastMCP的MCP服务器,提供在文本文件中搜索关键词或正则表达式的功能,适用于本地文件搜索和集成测试。

  • by niteshjangid29
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 niteshjangid29/ressl-ai-mcp-server

使用说明

🔍 MCP关键字搜索服务器(Python)

该项目使用FastMCP在Python中实现了一个模型上下文协议(MCP)服务器。它公开了一个名为 search_in_file 它允许您在文本文件中搜索关键字或正则表达式。

您可以在本地运行此服务器,并将其连接到MCP检查器进行测试和可视化。

🚀 特性

  • 🔎 在存储在中的文本文件中搜索 my_files/ 目录。
  • 🧩 支持:
    • 不区分大小写的搜索
    • 基于正则表达式的匹配
    • 可选的周围上下文线
  • 🔒 安全--文件访问仅限于 my_files 仅目录。
  • 🌐 作为HTTP MCP服务器运行,便于与MCP检查器集成。

🧱 项目结构

mcp-keyword-search/
├── server.py
├── my_files/
│   └── stock.txt
└── README.md

⚙️ 先决条件

  • Python 3.9+
  • pip 安装
  • Node.js(用于MCP检查器测试)

🧩 设置和运行说明

  1. 克隆存储库

    git clone https://github.com/niteshjangid29/ressl-ai-mcp-server.git
    cd ressl-ai-mcp-server
    
  2. 创建并激活虚拟环境

    python -m venv .venv
    source .venv/bin/activate   
    
  3. 安装依赖项

    uv add "mcp[cli]"
    
  4. 运行MCP服务器

    要使用MCP Inspector运行服务器,请使用以下命令:

    mcp dev server.py
    

    服务器将启动,您可以在浏览器中访问MCP检查器与 search_in_file 工具。

输入/输出示例

示例请求

{
  "filename": "stock.txt",
  "keyword": "stock",
  "case_insensitive": false,
  "context_lines": 0,
  "use_regex": false
}

示例响应

{
  "result": {
    "ok": true,
    "filename": "stock.txt",
    "keyword": "stock",
    "count": 3,
    "matches": [
      {
        "line_number": 1,
        "line": "The stock market opened higher today as tech shares gained momentum.",
        "context": [
          {
            "line_number": 1,
            "line": "The stock market opened higher today as tech shares gained momentum."
          }
        ]
      },
      {
        "line_number": 5,
        "line": "The Nifty index showed a bullish trend driven by IT and energy stocks.",
        "context": [
          {
            "line_number": 5,
            "line": "The Nifty index showed a bullish trend driven by IT and energy stocks."
          }
        ]
      },
      {
        "line_number": 8,
        "line": "Analysts recommend buying dips in quality large-cap stocks.",
        "context": [
          {
            "line_number": 8,
            "line": "Analysts recommend buying dips in quality large-cap stocks."
          }
        ]
      }
    ]
  }
}