Skip to content

Auto-refresh + callbacks on MCP list_changed notifications (default on) and refresh APIs #36

@inverted-capital

Description

@inverted-capital

Description

Auto-refetch tools/resources/prompts and update useMcp outputs when notifications/*/list_changed arrive. Make this configurable and callback-enabled. Default behavior: enabled.

API

useMcp({
  autoRefresh: true | {
    tools?: boolean
    resources?: boolean
    prompts?: boolean
  },
  onNotifications?:
    ((n: Notification) => void) | {
      onToolsNotification?: (n: Notification) => void
      onResourcesNotification?: (n: Notification) => void
      onPromptsNotification?: (n: Notification) => void
    }
})

Hook return additions:

{
  refreshAll(): Promise<void>
  refreshTools(): Promise<void>
  refreshResources(): Promise<void>
  refreshPrompts(): Promise<void>
}

Acceptance Criteria

  • Auto-refetch on tools/resources/prompts list_changed and update outputs
  • autoRefresh defaults to true, with per-type overrides
  • onNotifications supports global function or per-type handlers
  • New refreshAll/refreshTools/refreshResources/refreshPrompts methods exposed

Additional Context

This might solve #30, but if you are not partial to changing the hook function signature, perhaps you would consider just making auto refresh be the default ? I cannot think why you would not want auto refresh to be one, since the tool calls and resource requests you make after they have changed might be invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions