server_stdio.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import sys
  2. from mcp.server.fastmcp import FastMCP
  3. mcp = FastMCP("sdg", log_level="ERROR")
  4. @mcp.tool(
  5. name="query_high_frequency_question",
  6. description="从知识库中检索常见问题解答(FAQ),返回包含问题和答案的结构化JSON数据。",
  7. )
  8. async def query_high_frequency_question() -> str:
  9. """
  10. 高频问题查询
  11. """
  12. try:
  13. print("调用查询高频问题的tool成功!!", file=sys.stderr)
  14. return "高频问题是: 恐龙是怎么灭绝的?"
  15. except Exception as e:
  16. print(f"Unexpected error in question retrieval: {str(e)}", file=sys.stderr)
  17. raise
  18. @mcp.tool(
  19. name="get_weather",
  20. description="查询天气"
  21. )
  22. async def get_weather() -> str:
  23. """
  24. 查询天气的tools
  25. """
  26. try:
  27. print("调用查询天气的tools", file=sys.stderr)
  28. return "北京的天气是多云"
  29. except Exception as e:
  30. print(f"Unexpected error in question retrieval: {str(e)}", file=sys.stderr)
  31. raise
  32. if __name__ == "__main__":
  33. mcp.run(transport="stdio")