
MCP服务器SDK/示例完全用bash实现——构建一个模型上下文协议服务器,运行时依赖性仅限于POSIX壳层。
概览
纯Bash中模型上下文协议(MCP)服务器的轻量级、零开销实现。 大多数MCP服务器只是带有模式转换的API包装器。这种实现为Node.js、Python或其他重运行时提供了零开销的替代方案。 * ✅ 完整的 JSON-RPC 2.0 协议,基于 stdio * ✅ 完整的 MCP 协议实现 * ✅ 通过函数命名规则动态发现工具 * ✅ 通过 JSON 文件进行外部配置 * ✅ 通过自定义工具轻松扩展 - Bash shell - 用于 JSON 处理的 jq(macOS 上 brew 安装 jq) - : 处理 JSON-RPC 和 MCP 协议 - : 包含业务逻辑函数 - : JSON 配置文件 在为MCP服务器实现工具功能时,请遵循以下指导原则: 1. : 所有工具函数必须以 tool_ 作为前缀,后跟与 tools_list.json 定义的名称相同 2.: 每个函数应接受一个包含 JSON 参数的 $1 参数 3.: 对于成功操作,回放结果并返回 0 4。
概述(AI 翻译)
一个轻量级、零开销的模型上下文协议(MCP)服务器实现,采用纯 Bash 语言——针对当前的 2026-07-28 版本。
📖 文档网站 ·🧩示例 ·🧠架构决策 ·🔬尖峰
为什么? 大多数MCP服务器只是带有模式转换的API包装器。该实现提供了Node.js、Python或其他重运行时的零开销替代方案。
为什么是现在? 2026-07-28 版本使 MCP 无状态:无 initialize 握手,无会话,无服务器发起请求。一行进出——这正是壳读循环的形状。Bash 从尴尬的配合变成了自然的配合。
📋 特色
- ✅ MCP 2026-07-28 — 无状态,按请求协商版本
- ✅ 两种标准传输:stdio和Streamable HTTP,来自同一服务器文件
- ✅
server/discover,tools/list,tools/call - ✅ 通过函数命名规范进行动态工具发现
- ✅ 通过 JSON 文件进行外部配置
- ✅ 输出经官方发布的 JSON 模式验证
🔧 要求
- Bash 3.2或更新版本(macOS发布时称为
/bin/bash)
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
🐚 MCP Server in Bash
A lightweight, zero-overhead implementation of the Model Context Protocol (MCP) server in pure Bash — targeting the current 2026-07-28 revision.
📖 Documentation site · 🧩 Examples · 🧠 Architecture decisions · 🔬 Spikes
Why? Most MCP servers are just API wrappers with schema conversion. This implementation provides a zero-overhead alternative to Node.js, Python, or other heavy runtimes.
Why now? The 2026-07-28 revision made MCP stateless: no initialize handshake, no sessions, no server-initiated requests. One line in, one line out — which is exactly the shape of a shell read loop. Bash went from an awkward fit to a natural one.
📋 Features
- ✅ MCP 2026-07-28 — stateless, per-request version negotiation
- ✅ Both standard transports: stdio and Streamable HTTP, from the same server file
- ✅
server/discover,tools/list,tools/call - ✅ Dynamic tool discovery via function naming convention
- ✅ External configuration via JSON files
- ✅ Output validated against the official published JSON Schema
🔧 Requirements
- Bash 3.2 or newer (3.2 is what macOS ships as
/bin/bash) jqfor JSON processing (brew install jq/apt install jq/apk add jq)- (HTTP transport only)
socatpreferred, ornetcat— see the note under Transports - (optional) Python with
jsonschema, only to run the schema conformance test
Supported platforms
Verified by running the real test suites on each, not by inspection —
./scripts/test-linux.sh all reproduces the Linux rows on any machine with Docker.
| Platform | Shell | Unit | HTTP |
|---|---|---|---|
| macOS | bash 3.2 (/bin/bash) and 5.x |
31/31 | 19/19 |
| Debian / Ubuntu | bash 5.2 | 31/31 | 19/19 |
| Alpine (musl + busybox) | bash 5.3 | 31/31 | 19/19 |
Docker is needed only to verify other platforms — never to run a server.
🚀 Quick Start
- Clone the repo
git clone https://github.com/muthuishere/mcp-server-bash-sdk
cd mcp-server-bash-sdk
- Make scripts executable
chmod +x mcpserver_core.sh moviemcpserver.sh
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →