Skip to content

Support for per session dynamic tools/prompts #216

Closed as not planned
Closed as not planned

Description

@kzwang

Is your feature request related to a problem? Please describe.

Currently if we call AddPrompt/AddTool, it adds the prompt/tool for all sessions. We don't have a way to dynamically add/remove a tool or prompt just for a specific session.

Describe the solution you'd like

Add AddPrompt/AddTool (and remove) to ServerSession as well to allow adding tools/prompts only to 1 session.

Activity

  1. jba commented on Jul 31, 2025

    @jba
    Contributor

    Can you give an example of how this would be useful?

  2. added
    breaking changeThis requires a breaking API or behavior change
    on Jul 31, 2025
  3. kzwang commented on Jul 31, 2025

    @kzwang
    Author

    There are 2 use cases we'd benefit from this:

    • The MCP server loads different prompts and tools depending on the project type (e.g., Java, Python, JavaScript). We currently rely on the MCP root directory to determine the project context and load the appropriate resources. To work around limitations, we're using AddReceivingMiddleware to intercept and filter the tools/list and prompts/list methods. However, this approach doesn't work after initialization, as we have no way to trigger a list update event for just that single session.
    • Instead of exposing all prompts at once, I'd like to expose a tool like search for prompts based on some context, so initially, it would load no prompt, then when that tool is been called, it will dynamically add prompts based on the input, and just for that 1 session.
  4. findleyr commented on Jul 31, 2025

    @findleyr
    Contributor

    Why not create a separate server for each session, if this is desirable? This is why the (for example) HTTP handlers accept a function to get the server.

    One of the reasons for passing a getServer callback to the HTTP handlers is so that they can support this type of per-session configurability.

  5. kzwang commented on Jul 31, 2025

    @kzwang
    Author

    hmm, that's a good idea, I haven't thought about using server that way, I was considering mcp server as a 1-1 mapping with http server, and handle multiple sessions within the same server, but maybe that would just work for my use case

  6. jba commented on Aug 5, 2025

    @jba
    Contributor

    Closing. Re-open if needed.

  7. added this to the v0.3.0 milestone on Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeThis requires a breaking API or behavior change

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions