modelcontextprotocol / modelcontextprotocol/java-sdk
Allow dynamic generation of tool definition in MCP Server
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 3.7k
- フォーク
- 1.1k
- 平均マージ
- 1日 15時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、起動時に ToolCallbackProvider.getToolCallbacks が呼び出される箇所と、MCP サーバーが tools/list リクエストを処理する箇所を追跡します。要求されたフラグを追加して、tools/list がキャッシュ済みのコールバックを使用するか、それらを再取得するかを選択できるようにし、その後、既存のサーバーテストでフラグの両方の設定と動的なツール定義を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- java
- 領域
- backend-api-design
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100