mcpField
M
Modular MCP Server

Modular MCP Server

本地服务
github.com/da-snap开发工具184 周前更新

关于 Modular MCP Server

Modular MCP Server 是基于 Go 的 MCP 服务实现,面向构建文件与 Shell 操作工具的开发者。它支持配置路径允许和拒绝规则,并通过工具白名单限制 Shell 命令。

主要功能

  1. 01基于 Go 和 mcp-golang 实现
  2. 02可配置允许与拒绝的路径
  3. 03默认仅允许当前目录
  4. 04默认拒绝常见敏感目录
  5. 05限制 Shell 命令和工作目录

适用场景

  1. 01将文件操作限制在指定目录
  2. 02在允许的路径中运行获准的 Shell 工具

MCP 相关

它使用 `github.com/metoro-io/mcp-golang` 实现 MCP 服务。工具在服务入口处注册。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

模块化 MCP 服务

这是一个使用 github.com/metoro-io/mcp-golang 库实现的 Model Context Protocol(MCP)服务的 Go 版本,并经过模块化重构。

项目结构

mcp-server/
├── cmd/
│   └── mcp-server/
│       └── main.go           # Entry point
├── internal/
│   ├── config/
│   │   └── config.go         # Server configuration
│   ├── server/
│   │   ├── server.go         # MCP server implementation
│   │   └── server_test.go    # Server tests
│   ├── tools/
│   │   ├── tool.go           # Tool interface
│   │   ├── execute.go        # Execute shell command tool
│   │   ├── showfile.go       # Show file tool
│   │   ├── searchfile.go     # Search in file tool
│   │   └── writefile.go      # Write file tool
│   └── utils/
│       └── response.go       # Common response utilities
├── go.mod
├── go.sum
└── README.md

构建和运行

# Build the server
cd cmd/mcp-server
go build -o mcp-server

# Run the server
./mcp-server

安全功能

服务现在包含路径限制系统,可将文件操作限制在指定目录中。

配置允许的路径

你可以通过多种方式配置允许的路径:

1. 使用命令行标志
# Allow operations only in specific directories
./mcp-server --paths=/home/user/safe:/tmp/workspace

# Explicitly deny specific paths even if within allowed paths
./mcp-server --paths=/home/user --deny-paths=/home/user/.ssh:/home/user/credentials
2. 使用环境变量
# Set allowed paths
export MCP_ALLOWED_PATHS=/home/user/safe:/tmp/workspace

# Set denied paths
export MCP_DENIED_PATHS=/home/user/.ssh:/home/user/credentials

# Run the server
./mcp-server
3. 以编程方式配置

你也可以通过编程方式创建自定义配置:

cfg := config.DefaultConfig()
cfg.AddAllowedPath("/path/to/allow")
cfg.AddDeniedPath("/path/to/deny")

server, err := server.NewServerWithConfig(cfg)
默认行为
  • 如果未指定路径,服务默认只允许访问当前工作目录。
  • .git 和 .env 等常见敏感目录会自动添加到拒绝列表中。
Shell 命令安全性

对于 execute_shell_command 工具:

  • 命令仅限使用常见实用程序白名单中的程序
  • 会根据允许的路径配置检查自定义可执行文件路径
  • 工作目录必须位于允许的路径中

添加新工具

要添加新工具:

  1. 在 internal/tools 目录中创建新文件
  2. 实现 Tool 接口
  3. 如果工具需要访问服务配置,可选实现 ConfigAware 接口
  4. 在 cmd/mcp-server/main.go 中注册该工具

示例:

// internal/tools/newtool.go
package tools

import (
    "github.com/metoro-io/mcp-golang"
    "mcp-server/internal/config"
    "mcp-server/internal/utils"
)

type NewToolArgs struct {
    // Tool arguments
}

type NewTool struct{
    config *config.ServerConfig
}

func NewNewTool() *NewTool {
    return &NewTool{}
}

// Implement ConfigAware interface
func (t *NewTool) SetConfig(cfg *config.ServerConfig) {
    t.config = cfg
}

func (t *NewTool) Name() string {
    return "new_tool"
}

func (t *NewTool) Description() string {
    return "Description of the new tool"
}

func (t *NewTool) Execute(args NewToolArgs) (*mcp.ToolResponse, error) {
    // Access configuration if needed
    if t.config != nil {
        // Use configuration for security checks
    }

    // Tool implementation
    return utils.CreateSuccessResponse(result), nil
}

测试

go test ./...

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。