关键词搜索工具

一个基于FastAPI的MCP服务器,用于在上传的文本文件中搜索特定关键词,返回关键词出现的总次数和包含关键词的行。

  • by Santhoshkumarp01
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Santhoshkumarp01/mcp-keyword-search

使用说明

🔍 MCP关键字搜索工具

一个简单的 基于FastAPI的MCP服务器 在上传的文本文件中搜索特定关键字。
它返回 事件总数 和 包含关键字的行.
该项目展示了后端开发的基本原理-- 不包括机器学习或UI.


🧠 概述

该项目是MCP(模型上下文协议)探索的一部分,并提供了一个仅限后端的基本示例。
用户可以上传一个文本文件,并指定一个关键字来查找它的所有出现。


⚙️ 特性

  • 📄 上传任意 .txt 文件
  • 🔎 搜索关键字(不区分大小写)
  • 📊 退货:
    • 事件计数
    • 包含关键字的行
  • ⚡ 使用 快速API 为了速度和简单

🏗️ 项目结构

mcp关键字搜索/ ├── main.py#FastAPI服务器代码 ├── requirements.txt#依赖关系 ├── sample.txt#示例输入文本文件 └── README.md#文档


⚙️ 特性

✅ 上传 .txt 文件
✅ 搜索特定关键字(不区分大小写)
✅ 获取:

  • 关键字的总出现次数
  • 包含关键字的行
    ✅ 使用 快速API 高性能

🛠️ 安装指南

按照以下步骤在本地设置和运行项目。

1.️⃣ 克隆存储库

git clone https://github.com/<your-username>/mcp-keyword-search.git
cd mcp-keyword-search
2️⃣ Create a Virtual Environment

Windows

python -m venv venv
venv\Scripts\activate


macOS / Linux

python3 -m venv venv
source venv/bin/activate

3️⃣ Install Dependencies
pip install -r requirements.txt

▶️ Running the Server

Start the FastAPI development server using:

uvicorn main:app --reload


After running the command, open the following URLs in your browser:

API Root: http://127.0.0.1:8000

Swagger UI: http://127.0.0.1:8000/docs

📡 API Usage
Endpoint: /search

Method: POST

Parameters:

file: Upload a .txt file

keyword: Enter the keyword to search

Response Example:

{
  "keyword": "AI",
  "occurrences": 2,
  "lines_found": [
    "Ressl AI focuses on backend automation.",
    "AI improves text analytics efficiency."
  ]
}



Search Keyword: AI
Expected Output:

Occurrences: 3
Lines Found:
1. Ressl AI is a company focused on backend automation.
2. They develop AI-driven solutions for text analytics.
3. The AI models improve accuracy and speed.

👨‍💻 Author

Santhosh Kumar P
AI Developer | Innovator | Backend Enthusiast

📧 Email: santhoshpalanisamy292@gmail.com