Skip to content

Commit 6de85ec

Browse files
mcp: do not enforce TTL on cached tool (#1053)
This PR removes the TTL enforcing on the cached tools, when used to generate the http-parameters for CallTool, according to updated [spec](modelcontextprotocol/modelcontextprotocol#2972) > Clients **MUST** construct `Mcp-Param-*` headers using the most recently obtained `inputSchema` for the tool.
1 parent d651e2d commit 6de85ec

2 files changed

Lines changed: 7 additions & 22 deletions

File tree

‎mcp/cache.go‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ func (mc *methodCache[R]) put(key string, result R) {
5454
}
5555
}
5656

57-
func (mc *methodCache[R]) forEachValid(f func(R)) {
58-
mc.mu.Lock()
59-
defer mc.mu.Unlock()
60-
for key, entry := range mc.cachedValues {
61-
if !entry.isValid() {
62-
delete(mc.cachedValues, key)
63-
continue
64-
}
65-
f(entry.result)
66-
}
67-
}
68-
6957
func (mc *methodCache[R]) invalidate() {
7058
mc.mu.Lock()
7159
defer mc.mu.Unlock()

‎mcp/client.go‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,16 @@ func (cs *ClientSession) Wait() error {
584584
// outgoing request context for transport-layer features (e.g. x-mcp-header
585585
// param annotations).
586586
func (cs *ClientSession) lookupTool(name string) *Tool {
587-
var found *Tool
588-
cs.toolsCache.forEachValid(func(r *ListToolsResult) {
589-
if found != nil {
590-
return
591-
}
592-
for _, t := range r.Tools {
587+
cs.toolsCache.mu.Lock()
588+
defer cs.toolsCache.mu.Unlock()
589+
for _, entry := range cs.toolsCache.cachedValues {
590+
for _, t := range entry.result.Tools {
593591
if t.Name == name {
594-
found = t
595-
return
592+
return t
596593
}
597594
}
598-
})
599-
return found
595+
}
596+
return nil
600597
}
601598

602599
// registerElicitationWaiter registers a waiter for an elicitation complete

0 commit comments

Comments
 (0)