patch: audit log wired into tool calls
This commit is contained in:
@@ -12,19 +12,22 @@
|
||||
if ($required !== 'read') {
|
||||
$keyScopes = array_map('trim', explode(',', $authRow['scopes']));
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
$start = microtime(true);
|
||||
try {
|
||||
$result = $handler($arguments);
|
||||
\AskTamMCP\Core\Auth::logRequest($authRow, $toolName, true);
|
||||
$result = $handler($arguments);
|
||||
$durationMs = (int) ((microtime(true) - $start) * 1000);
|
||||
\AskTamMCP\Core\Installer::log($authRow, $toolName, 'tools/call', true, $durationMs);
|
||||
return $this->rpcResult($id, [
|
||||
'content' => [['type' => 'text', 'text' => is_string($result) ? $result : wp_json_encode($result)]],
|
||||
]);
|
||||
} 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user