找回密码
 立即注册
首页 业界区 业界 FastMCP(python)和 SolonMCP(java)的体验比较(不能 ...

FastMCP(python)和 SolonMCP(java)的体验比较(不能说一样,但真的很像)

悯拄等 2025-6-2 23:41:51
从 MCP SDK 的发展史上看,FastMCP 是前辈,SolonMCP 则是后辈。mcp-python-sdk 功能完善,已经很成熟了。而 mcp-java-sdk 却还不完善,比如:

  • 还不支持 http streaming
  • 还不支持 resouce template,不过有 pr 在走流程了(SolonMCP 提前提供了支持)
  • 只支持 jdk17+(SolonMCP 提供了 jdk8+ 支持)
  • 不支持 客户端断线自动重连(SolonMCP 提供了自动重连支持)
两者的体验不能说是一样,但真的很像。
1、FastMCP 的开发体验(python)

计算器工具
  1. @mcp.tool()
  2. def add(a: int, b: int) -> int:
  3.     """将两个数字相加"""
  4.     return a + b
  5. @mcp.tool()
  6. def subtract(a: int, b: int) -> int:
  7.     """从第一个数中减去第二个数"""
  8.     return a - b
  9. @mcp.tool()
  10. def multiply(a: int, b: int) -> int:
  11.     """将两个数相乘"""
  12.     return a * b
  13. @mcp.tool()
  14. def divide(a: float, b: float) -> float:
  15.     """将第一个数除以第二个数"""
  16.     if b == 0:
  17.         raise ValueError("除数不能为零")
  18.     return a / b
  19.    
  20. if __name__ == "__main__":
  21.     # 使用stdio传输方式启动服务器
  22.     mcp.run(transport="stdio")
复制代码
天气工具(有工具,资源,资源模板)
  1. @mcp.tool()
  2. def get_weather(city: str) -> dict:
  3.     """获取指定城市的当前天气"""
  4.     return "24度,晴"
  5. @mcp.resource("weather://cities")
  6. def get_available_cities() -> list:
  7.     """获取所有可用的城市列表"""
  8.     return ["Tokyo", "Sydney", "Tokyo"]
  9. @mcp.resource("weather://forecast/{city}")
  10. def get_forecast(city: str) -> dict:
  11.     """获取指定城市的天气预报资源"""
  12.     return {
  13.         "city": city,
  14.         "temperature": [10,25],
  15.         "condition":['sunny', 'clear', 'hot'],
  16.         "unit": "celsius"
  17.     }
  18. if __name__ == "__main__":
  19.     # 使用SSE传输方式启动服务器
  20.     mcp.run(transport="sse")
复制代码
2、SolonMCP 的开发体验(java)

SolonMCP(全称:solon-ai-mcp),支持 java8,可提供完成的 mcp 内容支持(工具,资源,资源模板,提示语)。
计算器工具
  1. @McpServerEndpoint(channel = McpChannel.STDIO)
  2. public class CalculatorTools {
  3.     @ToolMapping(description = "将两个数字相加")
  4.     public int add(@Param int a, @Param int b) {
  5.         return a + b;
  6.     }
  7.     @ToolMapping(description = "从第一个数中减去第二个数")
  8.     public int subtract(@Param int a, @Param int b) {
  9.         return a - b;
  10.     }
  11.     @ToolMapping(description = "将两个数相乘")
  12.     public int multiply(@Param int a, @Param int b) {
  13.         return a * b;
  14.     }
  15.     @ToolMapping(description = "将第一个数除以第二个数")
  16.     public float divide(@Param float a, @Param float b) {
  17.         return a / b;
  18.     }
  19. }
复制代码
天气工具(有工具,资源,资源模板)
  1. @McpServerEndpoint(sseEndpoint = "/mcp/sse")
  2. public class WeatherTools {
  3.     @ToolMapping(description = "获取指定城市的当前天气")
  4.     public String get_weather(@Param(description="城市") String city) {
  5.         return "{city: '" + city + "', temperature:[10,25], condition:['sunny', 'clear', 'hot'], unit:celsius}";
  6.     }
  7.     //可以给前端用,输出严格的 json 格式
  8.     @Produces(MimeType.APPLICATION_JSON_VALUE)
  9.     @ResourceMapping(uri = "weather://cities", description = "获取所有可用的城市列表")
  10.     public List<String> get_available_cities() {
  11.         return Arrays.asList("Tokyo", "Sydney", "Tokyo");
  12.     }
  13.     @ResourceMapping(uri = "weather://forecast/{city}", description = "获取指定城市的天气预报资源")
  14.     public String get_forecast(@Param(description="城市") String city) {
  15.          return "{city: '" + city + "', temperature:[10,25], condition:['sunny', 'clear', 'hot'], unit:celsius}";
  16.     }
  17. }
复制代码
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册