$git clone https://github.com/muthuishere/mcp-server-bash-sdkA lightweight, zero-overhead implementation of the Model Context Protocol (MCP) server in pure Bash.
| 1 | # 🐚 MCP Server in Bash |
| 2 | |
| 3 | A lightweight, zero-overhead implementation of the [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server in pure Bash. |
| 4 | |
| 5 | **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. |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## 📋 Features |
| 10 | |
| 11 | * ✅ Full JSON-RPC 2.0 protocol over stdio |
| 12 | * ✅ Complete MCP protocol implementation |
| 13 | * ✅ Dynamic tool discovery via function naming convention |
| 14 | * ✅ External configuration via JSON files |
| 15 | * ✅ Easy to extend with custom tools |
| 16 | |
| 17 | --- |
| 18 | |
| 19 | ## 🔧 Requirements |
| 20 | |
| 21 | - Bash shell |
| 22 | - `jq` for JSON processing (`brew install jq` on macOS) |
| 23 | |
| 24 | --- |
| 25 | |
| 26 | ## 🚀 Quick Start |
| 27 | |
| 28 | 1. **Clone the repo** |
| 29 | |
| 30 | ```bash |
| 31 | git clone https://github.com/muthuishere/mcp-server-bash-sdk |
| 32 | cd mcp-server-bash-sdk |
| 33 | ``` |
| 34 | |
| 35 | 2. **Make scripts executable** |
| 36 | |
| 37 | ```bash |
| 38 | chmod +x mcpserver_core.sh moviemcpserver.sh |
| 39 | ``` |
| 40 | |
| 41 | 3. **Try it out** |
| 42 | |
| 43 | ```bash |
| 44 | echo '{"jsonrpc": "2.0", "method": "tools/call", "params": {"name": "get_movies"}, "id": 1}' | ./moviemcpserver.sh |
| 45 | ``` |
| 46 | |
| 47 | --- |
| 48 | |
| 49 | ## 🏗️ Architecture |
| 50 | |
| 51 | ``` |
| 52 | ┌─────────────┐ ┌────────────────────────┐ |
| 53 | │ MCP Host │ │ MCP Server │ |
| 54 | │ (AI System) │◄──────► │ (moviemcpserver.sh) │ |
| 55 | └─────────────┘ stdio └────────────────────────┘ |
| 56 | │ |
| 57 | ┌───────┴──────────┐ |
| 58 | ▼ ▼ |
| 59 | ┌───────────────────┐ ┌───────────────┐ |
| 60 | │ Protocol Layer │ │ Business Logic│ |
| 61 | │(mcpserver_core.sh)│ │(tool_* funcs) │ |
| 62 | └───────────────────┘ └───────────────┘ |
| 63 | │ │ |
| 64 | ▼ ▼ |
| 65 | ┌─────────────────┐ ┌───────────────┐ |
| 66 | │ Configuration │ │ External │ |
| 67 | │ (JSON Files) │ │ Services/APIs │ |
| 68 | └─────────────────┘ └───────────────┘ |
| 69 | ``` |
| 70 | |
| 71 | - **mcpserver_core.sh**: Handles JSON-RPC and MCP protocol |
| 72 | - **moviemcpserver.sh**: Contains business logic functions |
| 73 | - **assets/**: JSON configuration files |
| 74 | |
| 75 | --- |
| 76 | |
| 77 | ## 🔌 Creating Your Own MCP Server |
| 78 | |
| 79 | ### Tool Function Guidelines |
| 80 | |
| 81 | When implementing tool functions for the MCP server, follow these guidelines: |
| 82 | |
| 83 | 1. **Naming Convention**: All tool functions must be prefixed with `tool_` followed by the same name defined in tools_list.json |
| 84 | 2. **Parameters**: Each function should accept a single parameter `$1` containing JSON arguments |
| 85 | 3. **Success Pattern**: For successful operations, echo the result and return 0 |
| 86 | 4. **Error Pattern**: For validation errors, echo an error message and return 1 |
| 87 | 5. **Automatic Discovery**: All tool functions are automatically exposed to the MCP server based on tools_list.json |
| 88 | |
| 89 | ### Implementation Steps |
| 90 | |
| 91 | 1. **Create your business logic file (e.g., `weatherserver.sh`)** |
| 92 | |
| 93 | ```bash |
| 94 | #!/bin/bash |
| 95 | # Weather API implementation |
| 96 | |
| 97 | # Override configuration paths BEFORE sourcing the core |
| 98 | MCP_CONFIG_FILE="$(dirname "${BASH_SOURCE[0]}")/assets/weatherserver_config.json" |
| 99 | MCP_TOOLS_LIST_FILE="$(dirname "${BASH_SOURCE[0]}")/assets/weatherserver_tools.json" |
| 100 | MCP_LOG_FILE="$(dirname "${BASH_SOURCE[0]}")/logs/weatherserver.log" |
| 101 | |
| 102 | # MCP Server Tool Function Guidelines: |
| 103 | # 1. Name all tool functions with prefix "tool_" followed by the same name defined in tools_list.json |
| 104 | # 2. Function should accept a single parameter "$1" containing JSON arguments |
| 105 | # 3. For successful operations: Echo the expected result and return 0 |
| 106 | # 4. For errors: Echo an error message and return 1 |
| 107 | # 5. All tool functions are automatically exposed to the MCP server based on tools_list.json |
| 108 | |
| 109 | # Source the core MCP server implementation |
| 110 | source "$(dirname "${BASH_SOURCE[0]}")/mcpserver_core.sh" |
| 111 | |
| 112 | # Access environment variables |
| 113 | API_KEY="${MCP_API_KEY:-default_key}" |
| 114 | |
| 115 | # Tool: Get current weather for a location |
| 116 | # Parameters: Takes a JSON object with location |
| 117 | # Success: Echo JSON result and return 0 |
| 118 | # Error: Echo error message and return 1 |
| 119 | tool_get_weather() { |
| 120 | local args="$1" |
| 121 | local locatio |