Modular MCP Server について
Modular MCP Serverは、ファイルやシェル操作ツールを構築する開発者向けのGo製MCPサーバーです。許可・拒否するパスを設定でき、シェルコマンドはユーティリティの許可リストで制限されます。
主な機能
- 01mcp-golangを使ったGo実装
- 02許可・拒否パスの設定
- 03既定では作業ディレクトリのみ許可
- 04一般的な機密ディレクトリを拒否
- 05シェルコマンドと作業ディレクトリの制限
活用シーン
- 01ファイル操作を指定ディレクトリに限定
- 02許可パス内で認可済みシェルツールを実行
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など、一般的な機密ディレクトリは拒否リストに自動的に追加されます。
シェルコマンドのセキュリティ
execute_shell_command ツールの場合:
- コマンドは一般的なユーティリティのホワイトリストに制限されます。
- カスタム実行ファイルのパスは、許可するパスの設定に照らして確認されます。
- 作業ディレクトリは許可されたパス内である必要があります。
新しいツールの追加
新しいツールを追加するには:
internal/toolsディレクトリに新しいファイルを作成します。Toolインターフェースを実装します。- ツールがサーバー設定にアクセスする必要がある場合は、必要に応じて
ConfigAwareインターフェースを実装します。 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 ./...
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。