Files
hz3-agent/mcp_server.py
黄庄三号 451e9a12ed feat: 黄庄三号四能力Agent初始版本
能力1: Function Call - LangGraph ToolNode
能力2: MCP - langchain-mcp-adapters + 确定性路由
能力3: 思考模式 - think_node + CoT推理链
能力4: Skill - 自建SkillRegistry注册机制

模型: GLM-4.5-air (智谱)
2026-04-23 19:18:53 +08:00

35 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""简单的 MCP 服务器 - 提供时间查询和文本处理工具"""
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("hz3-tools")
@mcp.tool()
def get_current_time(timezone: str = "Asia/Shanghai") -> str:
"""获取当前时间"""
from datetime import datetime
import pytz
try:
tz = pytz.timezone(timezone)
now = datetime.now(tz)
return f"当前时间({timezone}: {now.strftime('%Y-%m-%d %H:%M:%S %Z')}"
except Exception as e:
return f"时区错误: {e}"
@mcp.tool()
def count_chars(text: str) -> str:
"""统计文本的字符数、词数等"""
char_count = len(text)
word_count = len(text.split())
line_count = text.count('\n') + 1
chinese_chars = sum(1 for c in text if '\u4e00' <= c <= '\u9fff')
return f"字符数: {char_count}, 词数: {word_count}, 行数: {line_count}, 中文字符: {chinese_chars}"
@mcp.tool()
def generate_uuid() -> str:
"""生成一个随机UUID"""
import uuid
return str(uuid.uuid4())
if __name__ == "__main__":
mcp.run(transport="stdio")