code-tools-mcp
Enables file reading with pagination and regex-based code search across a codebase using grep.
README
Code Tools MCP
一个整合了文件阅读和代码搜索功能的 MCP (Model Context Protocol) 服务工具。
功能概述
本 MCP 服务注册了两个工具,供支持 MCP 协议的 AI 客户端(如 Claude Desktop、Claude Code 等)调用:
1. read_file — 文件阅读
读取指定路径的文件内容,支持按行范围分页读取。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file_path |
string | 是 | 文件的绝对或相对路径,支持跨盘符路径(如 D:/path/to/file) |
offset |
number | 否 | 起始行号(从 1 开始),配合 limit 实现分页读取 |
limit |
number | 否 | 最大读取行数,配合 offset 实现分页读取 |
示例:
{
"file_path": "D:/projects/main.cpp",
"offset": 100,
"limit": 50
}
2. search_codebase — 代码搜索
在指定目录中递归搜索匹配正则表达式的内容,基于 grep 实现。
参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
query |
string | 是 | grep 兼容的搜索查询(支持正则表达式) |
directory |
string | 否 | 搜索目录,支持绝对/相对路径,默认为当前工作目录 |
include |
string | 否 | 文件类型过滤(如 *.js、*.cpp),对应 grep 的 --include |
示例:
{
"query": "function\\s+loadNextLevel",
"directory": "D:/raylib/proj_1",
"include": "*.cpp"
}
安装与配置
1. 安装依赖
cd D:/code-tools-mcp
npm install
2. 配置 MCP 客户端
在 Claude Desktop 或 Claude Code 的 MCP 配置中添加:
{
"mcpServers": {
"code-tools": {
"command": "node",
"args": ["D:/code-tools-mcp/index.js"]
}
}
}
3. 启动(测试)
node D:/code-tools-mcp/index.js
项目结构
code-tools-mcp/
├── index.js # MCP 服务主入口,注册 read_file 和 search_codebase 两个工具
├── package.json # 项目配置文件
└── README.md # 本说明文件
技术栈
- 运行时: Node.js
- MCP SDK:
@modelcontextprotocol/sdkv1.29+ - 参数校验: Zod v4.4+
- 文件读取: Node.js 内置
fs/promises - 代码搜索: 调用系统
grep命令
注意事项
search_codebase依赖系统安装的grep命令,Windows 用户需确保 Git Bash 或类似环境可用- 单次返回内容上限约为 64,000 字符,超出部分会被截断
- 文件读取默认使用 UTF-8 编码
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.