MCP cover image
See in Github
2025-03-25

1

Github Watches

1

Github Forks

0

Github Stars

Modular MCP Server

This is a Go implementation of the Model Context Protocol (MCP) server using the github.com/metoro-io/mcp-golang library, restructured in a modular way.

Project Structure

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

Building and Running

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

# Run the server
./mcp-server

Security Features

The server now includes a path restriction system to limit file operations to specified directories.

Configuring Allowed Paths

You can configure allowed paths in several ways:

1. Using Command-line Flags

# 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. Using Environment Variables

# 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. Programmatically

You can also create a custom configuration programmatically:

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

server, err := server.NewServerWithConfig(cfg)

Default Behavior

  • If no paths are specified, the server defaults to allowing only the current working directory.
  • Common sensitive directories like .git and .env are automatically added to the deny list.

Shell Command Security

For the execute_shell_command tool:

  • Commands are restricted to a whitelist of common utilities
  • Custom executable paths are checked against the allowed paths configuration
  • Working directories must be within allowed paths

Adding New Tools

To add a new tool:

  1. Create a new file in the internal/tools directory
  2. Implement the Tool interface
  3. Optionally implement the ConfigAware interface if your tool needs access to server configuration
  4. Register the tool in cmd/mcp-server/main.go

Example:

// 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
}

Testing

go test ./...

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • Mintplex-Labs
  • La aplicación AI de escritorio todo en uno y Docker con trapo incorporado, agentes de IA, creador de agentes sin código, compatibilidad de MCP y más.

  • modelcontextprotocol
  • Servidores de protocolo de contexto modelo

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • n8n-io
  • Plataforma de automatización de flujo de trabajo de código justo con capacidades de IA nativas. Combine el edificio visual con código personalizado, auto-anfitrión o nube, más de 400 integraciones.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 llM 资料总结(数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Resumen de los mejores recursos del mundo.

  • open-webui
  • Interfaz de IA fácil de usar (admite Ollama, Operai API, ...)

    Reviews

    2 (1)
    Avatar
    user_cPo9I2ri
    2025-04-16

    Qase MCP Server by RayYokoyama is an outstanding tool for managing multiple projects efficiently. Its user-friendly interface and robust features make it the ideal choice for developers and project managers. The seamless integration with various platforms enhances productivity significantly. Highly recommended for anyone looking to streamline their project workflows.