Yandex天气MCP服务器
MCP服务器,具有获取当前日期和时间的工具,使用FastMCP实现。服务器支持通过JSON-RPC协议通过HTTP连接客户端。
安装
pip install -e .使用
HTTP模式(默认)
以HTTP模式启动服务器:
python main.py服务器将在地址可用 http://127.0.0.1:8000 (默认)。
您可以通过环境变量配置主机和端口:
MCP_HOST=0.0.0.0 MCP_PORT=8080 python main.pystdio模式
使用STDIO传输(通过标准I/O与MCP客户端集成):
MCP_TRANSPORT=stdio python main.pyHTTP API
服务器信息
GET http://127.0.0.1:8000/返回有关服务器和可用工具的信息。
JSON-RPC端点
POST http://127.0.0.1:8000/mcp
Content-Type: application/json获取当前日期和时间的查询示例:
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_current_datetime",
"arguments": {}
},
"id": 1
}答案示例:
{
"jsonrpc": "2.0",
"result": {
"content": [
{
"type": "text",
"text": "2024-01-15T14:30:45.123456"
}
]
},
"id": 1
}获取工具列表的查询示例:
{
"jsonrpc": "2.0",
"method": "tools/list",
"params": {},
"id": 2
}可用工具
日期和时间工具
- get_current \_日期时间 -以ISO 8601格式返回当前日期和时间
- get_current \_日期 -以YYYY-MM-DD格式返回当前日期
- get_current时间 -以hh:mm:ss格式返回当前时间
- get_current时间戳 返回当前Unix Timestamp
任务管理工具
- 创建任务 -使用指定的文本创建新任务。默认状态:“in_progress”
- 参数: text (str)-任务文本 - 返回:具有id、text、status、createdu at、completedu at的任务对象
- list_tasks -返回任务列表,可以按状态过滤
- 参数: status (str,可选)-状态筛选器('inu progress”或“completed”) - 返回:任务列表和数量
- 获取任务 -返回任务ID
- 参数: task_id (int)-任务标识符 - 返回:任务对象或错误消息
- 完成任务 -将任务标记为已完成
- 参数: task_id (int)-任务标识符 - 返回:具有“完成”状态和运行时间的更新任务对象
所有任务都存储在SQL数据库中 tasks.db每个任务都有:
id唯一标识符text-任务的文本/意义status-"татус(“进度”、“完成”)created_at-创建ISO 8601格式的时间completed_at-运行时间(工作任务为空)
使用示例
卷曲
# Получить текущую дату и время
curl -X POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_current_datetime",
"arguments": {}
},
"id": 1
}'python
import requests
url = "http://127.0.0.1:8000/mcp"
payload = {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_current_datetime",
"arguments": {}
},
"id": 1
}
response = requests.post(url, json=payload)
print(response.json())技术
- FastMCP 创建MCP服务器的框架
- MCP(模型上下文协议) 与AI模型交互的协议
