modelcontextprotocol / modelcontextprotocol/java-sdk
Allow dynamic generation of tool definition in MCP Server
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 3.7k
- 分支
- 1.1k
- 平均合併
- 1 天 15 小時
- 30 天內合併 PR
- 9
描述
Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.
Expected Behavior
Add a boolean property/flag called "callGetToolCallbacksEverytime".
If the flag is set to true then everytime an MCP server receives a tools/list request, the MCP server should call getToolCallbacks on registered ToolCallbackProvider. This will allow an MCP Server's implementation to dynamically generate ToolDefinition based on the request. All the implementation will need to do is provide a custom ToolCallbackProvider and also set the flag to true. If the flag is set to "false" then the current behaviour of calling getToolCallbacks only during startup is used.
Current Behavior
In the current behavior, i configured a custom ToolCallbackProvider to override the "description" that is generated for my tool. However, my tool callback provider's "getToolCallbacks" method is only called once during application startup. When my MCP Client sends a "tools/list" request, the MCP Server returns the tool definitions it computed at application startup. It doesn't try to get the new list from ToolCallbackProvider.
In the current behavior, getToolCallbacks is called on a ToolCallbackProvider only at startup. This makes it impossible to generate tool definition dynamically i.e. when "tools/list" request is received.
Context
My use case requires me to generate tool description dynamically based on the user of the MCP Client. MCP Client invokes a "tools/list" request but my Spring AI based MCP Server returns tooldefinition that it computed at the application startup. In my use case i would like to generate description for my tool dynamically everytime the MCP Server receives a "tools/list" request.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先追蹤啟動期間呼叫 ToolCallbackProvider.getToolCallbacks 的位置,以及 MCP 伺服器處理 tools/list 請求的位置。新增要求的 flag,讓 tools/list 可以在快取的 callback 與再次取得這些 callback 之間選擇,然後使用現有的伺服器測試驗證 flag 的兩種設定和動態工具定義。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java
- 領域
- backend-api-design
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100