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](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2972) > Clients **MUST** construct `Mcp-Param-*` headers using the most recently obtained `inputSchema` for the tool.
This commit is contained in:
parent
d651e2d2e1
commit
6de85ec3ed
2 changed files with 7 additions and 22 deletions
12
mcp/cache.go
12
mcp/cache.go
|
|
@ -54,18 +54,6 @@ func (mc *methodCache[R]) put(key string, result R) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *methodCache[R]) forEachValid(f func(R)) {
|
|
||||||
mc.mu.Lock()
|
|
||||||
defer mc.mu.Unlock()
|
|
||||||
for key, entry := range mc.cachedValues {
|
|
||||||
if !entry.isValid() {
|
|
||||||
delete(mc.cachedValues, key)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
f(entry.result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (mc *methodCache[R]) invalidate() {
|
func (mc *methodCache[R]) invalidate() {
|
||||||
mc.mu.Lock()
|
mc.mu.Lock()
|
||||||
defer mc.mu.Unlock()
|
defer mc.mu.Unlock()
|
||||||
|
|
|
||||||
|
|
@ -584,19 +584,16 @@ func (cs *ClientSession) Wait() error {
|
||||||
// outgoing request context for transport-layer features (e.g. x-mcp-header
|
// outgoing request context for transport-layer features (e.g. x-mcp-header
|
||||||
// param annotations).
|
// param annotations).
|
||||||
func (cs *ClientSession) lookupTool(name string) *Tool {
|
func (cs *ClientSession) lookupTool(name string) *Tool {
|
||||||
var found *Tool
|
cs.toolsCache.mu.Lock()
|
||||||
cs.toolsCache.forEachValid(func(r *ListToolsResult) {
|
defer cs.toolsCache.mu.Unlock()
|
||||||
if found != nil {
|
for _, entry := range cs.toolsCache.cachedValues {
|
||||||
return
|
for _, t := range entry.result.Tools {
|
||||||
}
|
|
||||||
for _, t := range r.Tools {
|
|
||||||
if t.Name == name {
|
if t.Name == name {
|
||||||
found = t
|
return t
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
return found
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// registerElicitationWaiter registers a waiter for an elicitation complete
|
// registerElicitationWaiter registers a waiter for an elicitation complete
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue