Skip to content

feat: add prompt instructions into tool docstring #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025

Conversation

fireinice
Copy link
Contributor

@fireinice fireinice commented Jun 17, 2025

根据fastmcp的文档 https://gofastmcp.com/servers/tools, 工具装饰器会将相关的函数的docstring自动转成工具的描述,附加在大模型的调用promt中。
原来的docstring是面向于用户及开发者的函数描述,对于模型来说指导意义不大,且浪费模型调用token。
这个PR将原本README中推荐加入到cursor rule的描述(同样也会加入到大模型的调用promt中)加到了工具的docstring中,这样:

  1. 可以简化用户配置
  2. 精减大模型的输入token, 避免副作用
  3. 为了保险起见,建议用户配置cursor rule,进一步提醒模型注意对工具的调用

Copy link
Owner

@Minidoracat Minidoracat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 優秀的改進!

@fireinice 感謝您提出這個非常有價值的 PR!

✅ 核心價值評估

這個 PR 展現了對 FastMCP 框架的深度理解,核心理念完全正確且具有重要實用價值:

  1. Token 效率優化 🚀

    • 將面向 LLM 的指令直接嵌入 docstring,符合 FastMCP 最佳實踐
    • 顯著減少不必要的技術描述,降低調用成本
    • 提升 LLM 理解和執行的準確性
  2. 用戶體驗改善

    • 簡化用戶配置流程,無需手動添加複雜的 Cursor rules
    • 讓工具本身攜帶使用指南,更加智能化
  3. 架構設計優雅 🎯

    • 將指令與實現緊密結合,提高維護性
    • 符合「配置即代碼」的現代開發理念

📋 後續優化計畫

為了讓這個優秀的改進更加完善,我計畫在合併後進行一些格式優化:

  • 統一 docstring 語言(使用英文)
  • 完善 PEP 257 格式規範
  • 補充技術文檔到 docs/ 目錄

這些都是非破壞性的改進,不會影響您的核心功能實現。

🤝 協作邀請

希望您能參與後續的優化工作,讓我們一起把這個功能打磨得更加完美!

建議立即合併

再次感謝您的貢獻!這個 PR 將為項目帶來實質性的改進。

@Minidoracat Minidoracat merged commit f2262db into Minidoracat:main Jun 21, 2025
@fireinice
Copy link
Contributor Author

fireinice commented Jun 24, 2025

感谢认可PR,后面计划修改一下 #125,改进一下超时退出,预计下周抽时间完成 , 或者按 #123 建议更改,对空字符串视为结束,我会试一试哪种更合理一些。

@Minidoracat
Copy link
Owner

感謝協助,我本來想重構成 vue 框架的前端,不過工程量太大,問題有點多,暫時先擱置或者就取消了
最近還有多個工作要做,所以有些小地方還沒時間進行調整

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants