Admin tools for Claude: an MCP server, connected with an admin's approval
- services/mcp: the MCP server at /mcp (Streamable HTTP, stateless): the admin's reading tools, the daily tasks and the forum's moderation; every tool calls the site's API with the caller's token, and members' e-mail addresses and names are masked in the answers. - Backend: OAuth 2.1 for MCP clients (registration with Claude's or a local return address only, PKCE, rotating refresh tokens, revocation); the admin guards accept the token for reading and the writes in MCP_WRITES only. - Forum: an admin's token reaches the moderator endpoints only. - Frontend: the approval page (/oauth/engedely), Admin → Claude to revoke a connection, the authorization server's metadata at its standard address. - Deploy: the mcp service in compose, Caddy, CI; the worker removes old codes, tokens and clients. docs/mcp.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -8,7 +8,7 @@ use tokio::sync::watch;
|
||||
const INTERVAL: Duration = Duration::from_secs(3600);
|
||||
|
||||
/// (what, statement) pairs; each returns the number of deleted rows.
|
||||
const STATEMENTS: [(&str, &str); 16] = [
|
||||
const STATEMENTS: [(&str, &str); 20] = [
|
||||
("sessions", "DELETE FROM sessions WHERE expires_at < now()"),
|
||||
("auth_tokens", "DELETE FROM auth_tokens WHERE expires_at < now()"),
|
||||
// Sent e-mails contain links with tokens; keep them a week for support.
|
||||
@@ -60,6 +60,21 @@ const STATEMENTS: [(&str, &str); 16] = [
|
||||
"DELETE FROM forum.conversations WHERE status IN ('pending', 'declined') AND last_message_at IS NULL \
|
||||
AND coalesce(responded_at, created_at) < now() - interval '90 days'",
|
||||
),
|
||||
// MCP clients (docs/mcp.md): codes and tokens past their time, connections
|
||||
// revoked a month ago or with no token left, and clients a month without
|
||||
// a connection (a client registered but never approved, or long revoked).
|
||||
("oauth_codes", "DELETE FROM oauth_codes WHERE expires_at < now() - interval '1 day'"),
|
||||
("oauth_tokens", "DELETE FROM oauth_tokens WHERE refresh_expires_at < now()"),
|
||||
(
|
||||
"oauth_grants",
|
||||
"DELETE FROM oauth_grants g WHERE g.revoked_at < now() - interval '30 days' \
|
||||
OR NOT EXISTS (SELECT 1 FROM oauth_tokens t WHERE t.grant_id = g.id)",
|
||||
),
|
||||
(
|
||||
"oauth_clients",
|
||||
"DELETE FROM oauth_clients c WHERE c.created_at < now() - interval '30 days' \
|
||||
AND NOT EXISTS (SELECT 1 FROM oauth_grants g WHERE g.client_id = c.id)",
|
||||
),
|
||||
];
|
||||
|
||||
pub async fn run_once(db: &PgPool) -> Result<Vec<(&'static str, u64)>, sqlx::Error> {
|
||||
|
||||
Reference in New Issue
Block a user