获取节假日
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"get-celader-host": {
"args": [
"get-celader-host-mcp@latest"
],
"command": "npx",
"url": "http://192.168.50.141:8080"
}
}
}
该服务需要配置环境变量:method
SSE 传输配置
{
"mcpServers": {
"get-celader-host": {
"args": [
"get-celader-host-mcp@latest"
],
"command": "sse-npx",
"url": "http://192.168.50.141:8080"
}
}
}
Streamable HTTP 传输配置
{
"mcpServers": {
"get-celader-host": {
"args": [
"get-celader-host-mcp@latest"
],
"command": "npx",
"url": "http://192.168.50.141:8080"
}
}
}
服务介绍
MCP Holiday Server
一个使用 Go 实现的最小化 MCP (Model Context Protocol) 服务器,基于 JSON-RPC 2.0 协议,通过 HTTP POST 提供 Streamable HTTP 传输。 内置一个 get_today_holiday 工具,可根据当前日期(同时支持公历与农历)返回今天的节日信息。
功能特性
✅ JSON-RPC 2.0 over HTTP POST
✅ Bearer Token 认证(默认 Token:test-token-123)
✅ 实现 initialize / tools/list / tools/call
✅ 内置工具 get_today_holiday,覆盖常见公历 + 农历节日
✅ 农历转换基于 github.com/6tail/lunar-go
项目结构
mcp-service/
├── go.mod
├── go.sum
├── main.go
├── auth/
│ └── auth.go # Token 认证中间件
├── handler/
│ └── handler.go # MCP 协议(JSON-RPC)处理
├── tools/
│ └── holiday.go # get_today_holiday 工具实现
└── README.md
安装与启动
- 安装依赖
go mod tidy - 启动服务
go run main.go
启动成功后会看到:
MCP Server started on :8080
服务默认监听 http://127.0.0.1:8080/mcp。
接口说明
端点:POST /mcp
Content-Type:application/json
认证头:Authorization: Bearer test-token-123
测试方法(curl)
- 测试认证失败(无 Token / Token 错误)
curl -i -X POST http://127.0.0.1:8080/mcp
-H "Content-Type: application/json"
-d '{"jsonrpc":"2.0","id":1,"method":"initialize"}'
期望返回 HTTP/1.1 401 Unauthorized,body 类似:
{
"jsonrpc": "2.0",
"id": null,
"error": { "code": -32001, "message": "Unauthorized: invalid token" }
}
2. 测试 initialize
curl -s -X POST http://127.0.0.1:8080/mcp
-H "Content-Type: application/json"
-H "Authorization: Bearer test-token-123"
-d '{"jsonrpc":"2.0","id":1,"method":"initialize"}'
期望返回:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": { "tools": {} },
"serverInfo": { "name": "holiday-mcp-server", "version": "1.0.0" }
}
}
3. 测试 tools/list
curl -s -X POST http://127.0.0.1:8080/mcp
-H "Content-Type: application/json"
-H "Authorization: Bearer test-token-123"
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
期望返回:
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "get_today_holiday",
"description": "获取今天是哪个节日",
"inputSchema": { "type": "object", "properties": {} }
}
]
}
}
4. 测试 tools/call: get_today_holiday
curl -s -X POST http://127.0.0.1:8080/mcp
-H "Content-Type: application/json"
-H "Authorization: Bearer test-token-123"
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_today_holiday","arguments":{}}}'
如果今天是节日(例如 6月1日 儿童节),返回:
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{ "type": "text", "text": "今天是【儿童节】- 国际儿童节,祝所有小朋友节日快乐" }
]
}
}
如果不是节日:
{
"jsonrpc": "2.0",
"id": 3,
"result": {
"content": [
{ "type": "text", "text": "今天是普通工作日,没有特殊节日" }
]
}
}
支持的节日
公历节日
日期 节日
1月1日 元旦
2月14日 情人节
3月8日 妇女节
4月5日 清明节
5月1日 劳动节
6月1日 儿童节
10月1日 国庆节
12月25日 圣诞节
农历节日
农历日期 节日
正月初一 春节
五月初五 端午节
七月初七 七夕节
八月十五 中秋节
九月初九 重阳节