MCP服务器脚本

一个用shell脚本编写的轻量级MCP服务器,用于处理JSON-RPC请求并执行简单的数学工具。

  • by antonum
  • Shell
  • 本地部署
  • 33 星标
  • 更新于
在 GitHub 查看 antonum/mcp-server-bash

使用说明

mcp服务器bash

用shell脚本编写的极简主义MCP服务器。

此回购符合以下条款: bash脚本中的极简主义MCP服务器

MCP服务器的生命周期可以分为两个阶段。初始化和操作。

mcp_add.sh实现了此生命周期中的所有消息,从握手到执行简单的“添加两个数字”工具。

要在CLI中正确使用基本测试方法,请执行以下操作:

# test tools/list method
echo '{"method":"tools/list","params":{},"jsonrpc":"2.0","id":2}' | bash mcp_add.sh | jq 

# test math_addition tool
echo '{"jsonrpc":"2.0","id":20, "method":"tools/call","params":{"name":"addition","arguments":{"num1":"1","num2":"2"}}}' | bash mcp_add.sh | jq 

LLM主机配置

mcphost和Claude Desktop的JSON配置文件:

{
    "mcpServers": {
      "math": {
        "command": "/Users/anton/code/mcp-server-bash/mcp_add.sh",
        "args": []
      }
    }
  }

使用mcphost进行测试

将execute添加到bash脚本:

chmod +x mcp_add.sh

使用llama3.1和工具配置文件运行mcphost

mcphost -m ollama:llama3.1:latest --config /Users/anton/code/mcp-server-bash/mcp.json

...

using math tool add 10 and 88

参考文献

  • 模型上下文协议https://www.anthropic.com/news/model-context-protocol
  • mcphosthttps://github.com/mark3labs/mcphost
  • jsonrpc规范:https://www.jsonrpc.org/specification
  • mcp检查员https://github.com/wong2/mcp-cli