内容
# MCP 工具包
[](https://badge.fury.io/py/mcp-toolkit)
[](https://pypi.org/project/mcp-toolkit/)
[](https://opensource.org/licenses/MIT)
[](https://github.com/exycfs/mcp-toolkit/actions/workflows/ci.yml)
[](https://codecov.io/gh/exycfs/mcp-toolkit)
[](https://pepy.tech/project/mcp-toolkit)
一套全面的、适用于常见工具和服务的生产就绪型 [模型上下文协议(MCP)](https://modelcontextprotocol.io/) 服务器集合。
## 功能
- **PostgreSQL 服务器** - 查询、插入、更新和管理 PostgreSQL 数据库
- **SQLite 服务器** - 轻量级 SQLite 数据库操作,支持完整的 SQL 功能
- **Redis 服务器** - 键值操作、发布/订阅和数据结构操作
- **文件系统服务器** - 安全的文件操作,支持沙盒和访问控制
- **GitHub API 服务器** - 通过 GitHub API 进行仓库管理、问题、拉取请求等操作
## 安装
```bash
# 从 PyPI 安装
pip install mcp-toolkit
# 或仅安装特定服务器
pip install mcp-toolkit[postgres]
pip install mcp-toolkit[sqlite]
pip install mcp-toolkit[redis]
pip install mcp-toolkit[filesystem]
pip install mcp-toolkit[github]
# 安装所有服务器
pip install mcp-toolkit[all]
```
## 快速入门
### PostgreSQL
```python
from mcp_toolkit.servers.postgres import PostgreSQLServer
server = PostgreSQLServer(
connection_string="postgresql://user:pass@localhost:5432/mydb"
)
server.run()
```
### SQLite
```python
from mcp_toolkit.servers.sqlite import SQLiteServer
server = SQLiteServer(database_path="./data.db")
server.run()
```
### Redis
```python
from mcp_toolkit.servers.redis import RedisServer
server = RedisServer(redis_url="redis://localhost:6379/0")
server.run()
```
### 文件系统
```python
from mcp_toolkit.servers.filesystem import FilesystemServer
server = FilesystemServer(
root_dir="/path/to/workspace",
read_only=False
)
server.run()
```
### GitHub API
```python
from mcp_toolkit.servers.github import GitHubServer
server = GitHubServer(
github_token="ghp_..."
)
server.run()
```
## 命令行界面使用
```bash
# 运行 PostgreSQL 服务器
mcp-toolkit postgres --connection-string "postgresql://localhost/mydb"
# 运行 SQLite 服务器
mcp-toolkit sqlite --database ./data.db
# 运行 Redis 服务器
mcp-toolkit redis --url redis://localhost:6379
# 运行文件系统服务器
mcp-toolkit filesystem --root ./workspace
# 运行 GitHub 服务器
mcp-toolkit github --token $GITHUB_TOKEN
```
## 配置
### 环境变量
```bash
# PostgreSQL
POSTGRES_CONNECTION_STRING=postgresql://user:pass@localhost/db
# Redis
REDIS_URL=redis://localhost:6379/0
# GitHub
GITHUB_TOKEN=ghp_xxxxxxxxxxxx
```
### Claude Desktop 配置
将以下内容添加到您的 Claude Desktop 配置文件(`claude_desktop_config.json`):
```json
{
"mcpServers": {
"postgres": {
"command": "mcp-toolkit",
"args": ["postgres", "--connection-string", "postgresql://localhost/mydb"]
},
"redis": {
"command": "mcp-toolkit",
"args": ["redis", "--url", "redis://localhost:6379"]
}
}
}
```
## API 参考
### PostgreSQL 服务器
| 工具 | 描述 |
|------|-------------|
| `query` | 执行 SELECT 查询 |
| `execute` | 执行 INSERT/UPDATE/DELETE 语句 |
| `list_tables` | 列出数据库中的所有表 |
| `describe_table` | 获取表模式信息 |
| `explain_query` | 获取查询执行计划 |
### SQLite 服务器
| 工具 | 描述 |
|------|-------------|
| `query` | 执行 SELECT 查询 |
| `execute` | 执行 INSERT/UPDATE/DELETE 语句 |
| `list_tables` | 列出所有表 |
| `describe_table` | 获取表模式 |
| `vacuum` | 优化数据库存储 |
### Redis 服务器
| 工具 | 描述 |
|------|-------------|
| `get` | 获取键的值 |
| `set` | 设置键值对 |
| `delete` | 删除一个或多个键 |
| `keys` | 列出匹配模式的键 |
| `hget` | 获取哈希字段的值 |
| `hset` | 设置哈希字段 |
| `lrange` | 获取列表范围 |
| `publish` | 向通道发布消息 |
### 文件系统服务器
| 工具 | 描述 |
|------|-------------|
| `read_file` | 读取文件内容 |
| `write_file` | 将内容写入文件 |
| `list_directory` | 列出目录内容 |
| `create_directory` | 创建新目录 |
| `delete_file` | 删除文件 |
| `move_file` | 移动/重命名文件 |
| `search_files` | 按模式搜索文件 |
### GitHub 服务器
| 工具 | 描述 |
|------|-------------|
| `list_repos` | 列出用户仓库 |
| `get_repo` | 获取仓库详细信息 |
| `list_issues` | 列出仓库问题 |
| `create_issue` | 创建新问题 |
| `list_prs` | 列出拉取请求 |
| `get_file` | 从仓库获取文件内容 |
| `search_code` | 跨仓库搜索代码 |
## 开发
```bash
# 克隆仓库
git clone https://github.com/exycfs/mcp-toolkit.git
cd mcp-toolkit
# 安装开发依赖项
pip install -e ".[dev]"
# 运行测试
pytest
# 运行 lint 工具
ruff check .
mypy src/
# 格式化代码
ruff format .
```
## 贡献
欢迎贡献!请在提交拉取请求前阅读我们的 [贡献指南](CONTRIBUTING.md)。
## 许可证
该项目根据 MIT 许可证授权 - 有关详细信息,请参阅 [LICENSE](LICENSE) 文件。
## 致谢
- 基于 [模型上下文协议](https://modelcontextprotocol.io/) 规范构建
- 灵感来自 MCP 生态系统和社区
## 支持
- [GitHub 问题](https://github.com/exycfs/mcp-toolkit/issues)
- [讨论](https://github.com/exycfs/mcp-toolkit/discussions)