文件关键词搜索服务

一个基于MCP协议的文件关键词搜索服务,提供HTTP和stdio接口,适用于文件内容检索和调试。

  • by sohv
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 sohv/simple-mcp-server

使用说明

Simple MCP Server

This project contains a proper MCP (Model Context Protocol) server for keyword searching in files.

Files

  • server.js - Express HTTP server (original implementation)
  • mcp-server.js - MCP server implementation using stdio transport
  • mcp-config.json - Configuration file for MCP clients

MCP Inspector Setup

MCP Inspector is a debugging tool that allows you to test and inspect your MCP server.

Installation

You can run the MCP Inspector using:

npm run inspector

This will start the MCP Inspector with your server, opening a web interface where you can:

  • Test the search_file tool
  • Inspect server capabilities
  • Debug requests and responses
  • Monitor server communication

Using the MCP Server

The MCP server provides a search_file tool that searches for keywords in files.

Tool Parameters:

  • keyword (string, required): The keyword to search for
  • file (string, required): The file path to search in

Example Usage in MCP Inspector:

  1. Run npm run inspector
  2. Open the web interface that appears
  3. Use the search_file tool with parameters like:
    {
      "keyword": "hello",
      "file": "sample.txt"
    }
    

Running the Servers

  • MCP Server: npm run mcp (runs on stdio)
  • MCP Inspector: npm run inspector (opens debugging interface)

Endpoints

  • GET /search — HTTP GET endpoint on the Express server. Query parameters: keyword (string) and file (path). Returns JSON with occurrences and matching lines.
  • POST /mcp — HTTP POST endpoint on the Express server (basic MCP connection/info endpoint used by the original Express implementation).
  • MCP (stdio) tool: search_file — The MCP stdio server (mcp-server.js) exposes a search_file tool which accepts { "keyword": "...", "file": "..." } and returns match details (line numbers and contents).