MCPcopy Create free account
hub / github.com/Accenture/mcp-bench / get

Method get

mcp_modules/tool_cache.py:103–160  ·  view source on GitHub ↗

Get cached tool call result Args: server_name: Server name tool_name: Tool name params: Tool parameters Returns: Cached result, or None if not found or expired

(self, server_name: str, tool_name: str, params: Dict[str, Any])

Source from the content-addressed store, hash-verified

101 return cache_key
102
103 def get(self, server_name: str, tool_name: str, params: Dict[str, Any]) -> Optional[Any]:
104 """
105 Get cached tool call result
106
107 Args:
108 server_name: Server name
109 tool_name: Tool name
110 params: Tool parameters
111
112 Returns:
113 Cached result, or None if not found or expired
114 """
115 if not self.enabled:
116 return None
117
118 # Check if server is in whitelist
119 if self.server_whitelist and server_name not in self.server_whitelist:
120 return None
121
122 cache_key = self._generate_cache_key(server_name, tool_name, params)
123 current_time = time.time()
124
125 try:
126 conn = self._get_connection()
127 cursor = conn.execute(
128 'SELECT result, timestamp FROM cache WHERE cache_key = ?',
129 (cache_key,)
130 )
131 row = cursor.fetchone()
132
133 if row:
134 result_json, timestamp = row
135 # Check if expired (ttl_seconds=0 means never expire)
136 if self.ttl_seconds == 0 or current_time - timestamp < self.ttl_seconds:
137 # Update access count
138 conn.execute(
139 'UPDATE cache SET access_count = access_count + 1 WHERE cache_key = ?',
140 (cache_key,)
141 )
142 conn.commit()
143
144 result = json.loads(result_json)
145 age_minutes = (current_time - timestamp) / 60
146 logger.info(f"Cache HIT: {server_name}:{tool_name} (age: {age_minutes:.1f} minutes)")
147 logger.info(f" Cached params: {json.dumps(params, indent=2)}")
148 return result
149 else:
150 # Expired, delete it
151 conn.execute('DELETE FROM cache WHERE cache_key = ?', (cache_key,))
152 conn.commit()
153 logger.debug(f"Cache expired: {server_name}:{tool_name}")
154
155 except (sqlite3.Error, json.JSONDecodeError) as e:
156 logger.error(f"Cache read error: {e}")
157
158 logger.info(f"Cache MISS: {server_name}:{tool_name}")
159 logger.debug(f" Params: {json.dumps(params, indent=2)}")
160 return None

Callers 15

get_local_commandMethod · 0.45
record_errorMethod · 0.45
load_server_configsMethod · 0.45
collect_all_infoMethod · 0.45
save_to_markdownMethod · 0.45
mainFunction · 0.45
__init__Method · 0.45
call_toolMethod · 0.45
_call_tool_httpMethod · 0.45
setMethod · 0.45

Calls 3

_generate_cache_keyMethod · 0.95
_get_connectionMethod · 0.95
executeMethod · 0.45

Tested by 1