Skip to main content
Glama
MCP Skill

MCP Skill

by Yi-xuanZzy

MCP Skill · 本地日期工具 MCP Server

一个可直接运行、可发布到 MCP 广场的开源示例项目:用 Python(FastMCP)实现本地 MCP 服务端,并通过 LangChain Agent 调用其工具。

项目简介

做这个项目的初衷是给 MCP 初学者一个「最小可跑」的完整链路:

  • 服务端:mcp_server_stdio.py 用 FastMCP 提供 get_current_date、get_current_time 两个工具,一份代码支持 stdio / SSE / Streamable HTTP 三种传输

  • 客户端:MCP_client.py 用 MultiServerMCPClient 连接服务端,把 MCP 工具自动转成 LangChain Tool 交给 Agent,用自然语言触发调用

  • 无需数据库、无需外部 API,克隆下来装完依赖即可运行,适合作为 MCP 项目模板

Related MCP server: DateTime-LocalMCPServer

文件说明

文件

作用

mcp_server_stdio.py

MCP 服务端,提供日期、时间两个工具,支持三种传输

MCP_client.py

MCP 客户端,连接服务端并驱动 LangChain Agent

skill_client.py

本地 Skills 客户端,扫描 skills/ 目录并把技能交给 Agent 按需加载

skills/

技能目录,每个技能一个文件夹,内含 SKILL.md

requirements.txt

Python 依赖清单

本地 Skills 客户端

除了 MCP,本项目还演示了另一种「技能」组织方式:技能以 SKILL.md 形式存放在本地,客户端扫描后把技能清单写进系统提示,Agent 需要时再调用 load_skill 读取完整说明。

技能目录结构:

skills/
├── translate/
│   └── SKILL.md
└── code-review/
    └── SKILL.md

SKILL.md 格式:

---
name: translate
description: 中英互译。当用户要求翻译、润色或改写外语内容时使用。
---
# 翻译技能

(正文:步骤、输出格式、示例)

运行:

python skill_client.py

预期输出:Agent 先调用 load_skill 加载 translate 技能,再按技能规范返回译文。

新增技能只需在 skills/ 下建一个文件夹并写 SKILL.md,无需改代码。

部署指南

环境要求

  • Python 3.10+

  • 运行客户端需要 DashScope API Key(示例使用 qwen-plus,可换成其他兼容 OpenAI 协议的模型)

安装依赖

pip install -r requirements.txt

配置 API Key

# Linux / macOS
export DASHSCOPE_API_KEY="你的 key"

# Windows PowerShell
$env:DASHSCOPE_API_KEY="你的 key"

启动服务端

三种传输按需选择,只跑一种即可:

# stdio:无需手动启动,客户端会自动拉起子进程
python mcp_server_stdio.py

# SSE(旧版协议),监听 http://127.0.0.1:8000/sse
python mcp_server_stdio.py sse 8000

# Streamable HTTP(新版协议),监听 http://127.0.0.1:8001/mcp
python mcp_server_stdio.py streamable-http 8001

客户端配置(Cherry Studio / Claude Desktop 等)

stdio 方式:

{
  "mcpServers": {
    "date-tool": {
      "command": "python",
      "args": ["/绝对路径/mcp_server_stdio.py"]
    }
  }
}

远程方式:

{
  "mcpServers": {
    "date-tool": {
      "url": "http://127.0.0.1:8001/mcp"
    }
  }
}

运行示例客户端

python MCP_client.py

默认连接 stdio 与 Streamable HTTP 两个服务;只用 stdio 时注释掉 MCP_client.py 中 date-tool-streamable 那一行即可,SSE 则取消 date-tool-sse 的注释。

使用示例

向 Agent 提问「今天几号?」后,实际输出:

--- [0] HumanMessage ---

--- [1] AIMessage ---
工具调用: get_current_date {} id: call_19251a6c7c0b40ad8468cd

--- [2] ToolMessage ---
工具返回: get_current_date call_19251a6c7c0b40ad8468cd -> [{'type': 'text', 'text': '2026-11-26', ...}]

--- [3] AIMessage ---

最终回答: 今天是2026年11月26日。

工具清单:

工具名

说明

返回示例

get_current_date

获取本地时区当天日期

2026-11-26

get_current_time

获取本地时区当前时间

15:24:51

三种传输方式对比

传输

说明

stdio

客户端启动子进程,通过标准输入输出通信,适合本地工具

sse

旧版 HTTP 传输(2024-11 规范),长连接事件流 + POST 回传,已弃用但兼容

streamable_http

新版 HTTP 传输(2025-03 规范),单端点,需要流式时再升级为 SSE,推荐使用

开源协议

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      D
      maintenance
      A general-purpose MCP server providing time-related utilities such as fetching current time, Unix timestamps, and formatting services. It supports both local stdio and remote SSE communication modes for versatile AI client integration.
      3
      -
    • A
      license
      A
      quality
      D
      maintenance
      A Model Context Protocol server built with FastMCP that provides tools for retrieving the current local date and time. It allows LLMs to access precise temporal information directly from the host environment.
      9
      MIT
    • A
      license
      D
      quality
      C
      maintenance
      A lightweight MCP server that provides date and time tools, including the ability to retrieve current timestamps and parse date strings with IANA timezone support. It enables AI models to interact with the host OS clock and perform temporal calculations via stdio transport.
      3
      6 npm
      7
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A simple MCP server that exposes datetime information to agentic systems and chat REPLs
      1
      MIT