Skip to content

[FEATURE]: cache MCP listTools() results to avoid redundant network requests #17167

@Runrun-mu

Description

@Runrun-mu

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem
tools() calls client.listTools() for every connected MCP server on every invocation. Since tools() is called in the core loop on each iteration via prompt.ts, this causes N×M redundant network roundtrips.

Solution
Add an in-memory Map cache for listTools results per server. Cache is invalidated on:

ToolListChanged notification from server
connect() / add() / disconnect()
State shutdown

Impact
3 servers × 10 calls: 30 requests → 3 (90% reduction, ~540ms saved at 20ms/request)

Risk: Minimal — all state change paths invalidate the cache.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions