patch: audit log wired into tool calls

This commit is contained in:
2026-05-08 22:30:42 +00:00
parent e4d8875e6f
commit 67915591ad
+6 -3
View File
@@ -12,19 +12,22 @@
if ($required !== 'read') { if ($required !== 'read') {
$keyScopes = array_map('trim', explode(',', $authRow['scopes'])); $keyScopes = array_map('trim', explode(',', $authRow['scopes']));
if (!in_array($required, $keyScopes, true) && !in_array('admin', $keyScopes, true)) { if (!in_array($required, $keyScopes, true) && !in_array('admin', $keyScopes, true)) {
\AskTamMCP\Core\Auth::logRequest($authRow, $toolName, false); \AskTamMCP\Core\Installer::log($authRow, $toolName, 'tools/call', false, 0);
return $this->rpcError($id, -32000, "Insufficient scope. Required: {$required}"); return $this->rpcError($id, -32000, "Insufficient scope. Required: {$required}");
} }
} }
$start = microtime(true);
try { try {
$result = $handler($arguments); $result = $handler($arguments);
\AskTamMCP\Core\Auth::logRequest($authRow, $toolName, true); $durationMs = (int) ((microtime(true) - $start) * 1000);
\AskTamMCP\Core\Installer::log($authRow, $toolName, 'tools/call', true, $durationMs);
return $this->rpcResult($id, [ return $this->rpcResult($id, [
'content' => [['type' => 'text', 'text' => is_string($result) ? $result : wp_json_encode($result)]], 'content' => [['type' => 'text', 'text' => is_string($result) ? $result : wp_json_encode($result)]],
]); ]);
} catch (\Throwable $e) { } catch (\Throwable $e) {
\AskTamMCP\Core\Auth::logRequest($authRow, $toolName, false); $durationMs = (int) ((microtime(true) - $start) * 1000);
\AskTamMCP\Core\Installer::log($authRow, $toolName, 'tools/call', false, $durationMs);
return $this->rpcError($id, -32000, $e->getMessage()); return $this->rpcError($id, -32000, $e->getMessage());
} }
} }