Token导航 LogoToken导航TokenDH.com
Bash SDK logo
开发工具未说明官方级别未说明来源级核验

Bash SDK

MCP Server

一个轻量级的、零开销的Bash实现的Model Context Protocol (MCP)服务器,支持JSON-RPC 2.0协议和动态工具发现。

工具数

1

提示词数

0

GitHub Stars

507

资源数

0
工具发现ShellVS CodeVS Code

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

muthuishere

提供方

muthuishere

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

详细介绍

🐚 Bash中的MCP服务器

一个轻量级的、零开销的实现 模型上下文协议(MCP) 纯Bash中的服务器。

为什么? 大多数MCP服务器只是带有模式转换的API包装器。此实现为Node.js、Python或其他繁重的运行时提供了一种零开销的替代方案。

______________________________________________________________________

📋 特性

  • ✅ stdio上的完整JSON-RPC 2.0协议
  • ✅ 完成MCP协议的实施
  • ✅ 通过函数命名约定进行动态工具发现
  • ✅ 通过JSON文件进行外部配置
  • ✅ 易于使用自定义工具进行扩展

______________________________________________________________________

🔧 需求

  • Bash shell
  • jq 用于JSON处理(brew install jq 在macOS上)

______________________________________________________________________

🚀 快速开始

  1. 克隆仓库
git clone https://github.com/muthuishere/mcp-server-bash-sdk
cd mcp-server-bash-sdk
  1. 使脚本可执行
chmod +x mcpserver_core.sh moviemcpserver.sh
  1. 试试看
echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "get_movies"}, "id": 1}' | ./moviemcpserver.sh

______________________________________________________________________

🏗️ 建筑

┌─────────────┐         ┌────────────────────────┐
│ MCP Host    │         │ MCP Server             │
│ (AI System) │◄──────► │ (moviemcpserver.sh)    │
└─────────────┘ stdio   └────────────────────────┘
                             │
                     ┌───────┴──────────┐
                     ▼                  ▼
            ┌───────────────────┐  ┌───────────────┐
            │ Protocol Layer    │  │ Business Logic│
            │(mcpserver_core.sh)│  │(tool_* funcs) │
            └───────────────────┘  └───────────────┘
                     │                  │
                     ▼                  ▼
              ┌─────────────────┐  ┌───────────────┐
              │ Configuration   │  │ External      │
              │ (JSON Files)    │  │ Services/APIs │
              └─────────────────┘  └───────────────┘
  • mcpserver_core.sh:处理JSON-RPC和MCP协议
  • moviemcpserver.sh:包含业务逻辑功能
  • 资产/:JSON配置文件

______________________________________________________________________

🔌 创建自己的MCP服务器

工具功能指南

在为MCP服务器实现工具功能时,请遵循以下准则:

  1. 命名规范:所有工具函数必须以前缀 tool_ 后面是tools_list.json中定义的相同名称
  2. 参数:每个函数应接受一个参数 $1 包含JSON参数
  3. 成功模式:对于成功的操作,回显结果并返回0
  4. 错误模式:对于验证错误,回显错误消息并返回1
  5. 自动发现:所有工具函数都会根据tools_list.json自动暴露给MCP服务器

实施步骤

  1. 创建您的业务逻辑文件(例如。, weatherserver.sh)
#!/bin/bash
# Weather API implementation

# Override configuration paths BEFORE sourcing the core
MCP_CONFIG_FILE="$(dirname "${BASH_SOURCE[0]}")/assets/weatherserver_config.json"
MCP_TOOLS_LIST_FILE="$(dirname "${BASH_SOURCE[0]}")/assets/weatherserver_tools.json"
MCP_LOG_FILE="$(dirname "${BASH_SOURCE[0]}")/logs/weatherserver.log"

# MCP Server Tool Function Guidelines:
# 1. Name all tool functions with prefix "tool_" followed by the same name defined in tools_list.json
# 2. Function should accept a single parameter "$1" containing JSON arguments
# 3. For successful operations: Echo the expected result and return 0
# 4. For errors: Echo an error message and return 1
# 5. All tool functions are automatically exposed to the MCP server based on tools_list.json

# Source the core MCP server implementation
source "$(dirname "${BASH_SOURCE[0]}")/mcpserver_core.sh"

# Access environment variables
API_KEY="${MCP_API_KEY:-default_key}"

# Tool: Get current weather for a location
# Parameters: Takes a JSON object with location
# Success: Echo JSON result and return 0
# Error: Echo error message and return 1
tool_get_weather() {
  local args="$1"
  local location=$(echo "$args" | jq -r '.location')
  
  # Parameter validation
  if [[ -z "$location" ]]; then
    echo "Missing required parameter: location"
    return 1
  fi
  
  # Call external API
  local weather=$(curl -s "https://api.example.com/weather?location=$location&apikey=$API_KEY")
  echo "$weather"
  return 0
}

# Start the MCP server
run_mcp_server "$@"
  1. 创建 assets/weatherserver_tools.json
{
  "tools": [
    {
      "name": "get_weather",
      "description": "Get current weather for a location",
      "inputSchema": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "City name or coordinates"
          }
        },
        "required": ["location"]
      }
    }
  ]
}
  1. 创建 assets/weatherserver_config.json
{
  "protocolVersion": "2025-03-26",
  "serverInfo": {
    "name": "WeatherServer",
    "version": "1.0.0"
  },
  "capabilities": {
    "tools": {
      "listChanged": true
    }
  },
  "instructions": "This server provides weather information."
}
  1. 使文件可执行
chmod +x weatherserver.sh

______________________________________________________________________

🖥️ 与VS Code和GitHub Copilot一起使用

  1. 更新VS代码设置.json
"mcp": {
    "servers": {
        "my-weather-server": {
            "type": "stdio",
            "command": "/path/to/your/weatherserver.sh",
            "args": [],
            "env": {
                "MCP_API_KEY": "your-api-key"
            }
        }
    }
}
  1. 与GitHub Copilot聊天一起使用
/mcp my-weather-server get weather for New York

______________________________________________________________________

🚫 局限性

  • 无并发/并行处理
  • 有限的内存管理
  • 无流媒体响应
  • 不是为高吞吐量而设计的

对于人工智能助手和本地工具执行来说,这些都不是阻塞问题。

______________________________________________________________________

📄 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

博客:https://medium.com/@muthuiser/why-i内置-an-mcp服务器-dk-in-shell-y-bash-6f2192072279

目录标签

目录标签

工具发现ShellVS Code本地部署轻量级服务器JSON-RPCBash脚本AI系统集成

支持客户端

VS Code

接入字段

传输方式(transport,传输协议)

未说明

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

1

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

未说明none部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

仍需确认:installCommand

来源信息

继续浏览同类 MCP