本地笔记搜索MCP服务器

LocalNotes Search MCP Server 是一个通过 STDIO 通信并提供 read_note 工具的 MCP 服务器,可让大语言模型读取本地 .txt 笔记文件,用于私有本地笔记的检索与问答。

  • by PIsberg
  • Java
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 PIsberg/mcp-book-mcp-server-localnotes-search-stdio

使用说明

LocalNotes Search MCP Server

A great "Hello World" for an MCP implementation for STDIO is a Local Notes Searcher. It’s simple enough to understand but demonstrates the core power of MCP: giving an LLM access to private, local data that it otherwise couldn't see. In this example, the LLM will be able to read .txt files from a specific folder on your computer to answer your questions.

Features

  • Transport: Uses STDIO (Standard Input/Output) for communication.
  • Tools:
    • read_note: Takes a filename and returns the text content of the file from the locally configured notes directory.

Prerequisites

  • Java 21 or later
  • Maven 3.6 or later

Build Instructions

To build the application, run the following command in the project root:

mvn clean package

This will create an executable JAR file in the target/ directory (e.g., target/mcp-server-localnotes-search-stdio-0.0.1-SNAPSHOT.jar).

Configuration

The application uses a notes directory to store and read text files. By default, it looks for a directory named notes in the current working directory.

You can configure the location of this directory using the notes.directory property in application.properties or via command-line arguments:

# Run with a custom notes directory
java -jar target/mcp-server-localnotes-search-stdio-0.0.1-SNAPSHOT.jar --notes.directory="/absolute/path/to/notes"

Setup

  1. Create a directory named notes in the same directory where you will run the JAR.
  2. Add some .txt files to this notes directory (e.g., hello.txt).

Run Instructions

You can run the application directly with Java. Since it uses STDIO, it expects JSON-RPC messages via standard input.

java -jar target/mcp-server-localnotes-search-stdio-0.0.1-SNAPSHOT.jar

Usage with an MCP Client

Configure your MCP client (like Claude Desktop or an IDE extension) to run the above command.

Manual Testing

You can interact with the server manually by pasting JSON-RPC messages into the console after running the JAR.

Initialize:

{"jsonrpc": "2.0", "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test-client", "version": "1.0"}}, "id": 1}

Call Tool (read_note):

{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "read_note", "arguments": {"filename": "hello.txt"}}, "id": 2}