Admin tools for Claude: an MCP server, connected with an admin's approval
CI / build (push) Skipped
CI / deploy (push) Skipped
CI / test (push) Successful in 4m27s

- 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:
feco
2026-11-27 17:09:14 +00:00
co-authored by Claude Opus 5.5
parent 08ad7b0a79
commit 2c63384606
40 changed files with 3695 additions and 49 deletions
@@ -0,0 +1,53 @@
"use client";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
export type OauthParams = Partial<
Record<
| "response_type"
| "client_id"
| "redirect_uri"
| "code_challenge"
| "code_challenge_method"
| "scope"
| "state"
| "resource",
string
>
>;
/** The admin's answer: the backend gives the address back to the client (with a code, or a refusal). */
export function Approve({ params }: { params: OauthParams }) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function answer(deny: boolean) {
setBusy(true);
setError(null);
try {
const r = await api<{ redirect_to: string }>("/oauth/authorize", { body: { ...params, deny } });
window.location.assign(r.redirect_to);
} catch (e) {
setError(errorText(e));
setBusy(false);
}
}
return (
<div className="oauth-actions">
<button type="button" className="btn btn-primary" disabled={busy} onClick={() => answer(false)}>
Engedélyezem
</button>
<button type="button" className="btn" disabled={busy} onClick={() => answer(true)}>
Mégse
</button>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
</div>
);
}
@@ -0,0 +1,109 @@
import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { BACKEND_URL, getMe } from "@/lib/server";
import { Approve, type OauthParams } from "./Approve";
export const metadata: Metadata = { title: "Claude összekötése", robots: { index: false } };
type Props = { searchParams: Promise<Record<string, string | string[] | undefined>> };
const PARAMS = [
"response_type",
"client_id",
"redirect_uri",
"code_challenge",
"code_challenge_method",
"scope",
"state",
"resource",
] as const;
interface Check {
client_name: string;
redirect_host: string | null;
}
/**
* The OAuth approval page (docs/mcp.md): Claude sends the admin here to
* connect the admin tools. The backend checks the request first; only an
* admin may approve it.
*/
export default async function OauthApprovalPage({ searchParams }: Props) {
const raw = await searchParams;
const params: OauthParams = {};
const query = new URLSearchParams();
for (const name of PARAMS) {
const value = Array.isArray(raw[name]) ? raw[name][0] : raw[name];
if (value !== undefined) {
params[name] = value;
query.set(name, value);
}
}
let check: Check | null = null;
let problem = "A kérés nem érkezett meg rendesen.";
try {
const res = await fetch(`${BACKEND_URL}/v1/oauth/authorize?${query}`, { cache: "no-store" });
const body = await res.json();
if (res.ok) check = body as Check;
else problem = body?.error?.message ?? problem;
} catch {
problem = "A szerver most nem érhető el. Próbáld újra.";
}
if (!check) {
return (
<main className="page" style={{ maxWidth: 560 }}>
<div className="page-head">
<h1>Az összekötés nem sikerült</h1>
<p className="muted">{problem}</p>
<p className="hint">Próbáld újra az összekötést Claude-ban.</p>
</div>
</main>
);
}
const me = await getMe();
if (!me) redirect(`/belepes?vissza=${encodeURIComponent(`/oauth/engedely?${query}`)}`);
if (!me.user.roles.includes("admin")) {
return (
<main className="page" style={{ maxWidth: 560 }}>
<div className="page-head">
<h1>Ehhez admin fiók kell</h1>
<p className="muted">Az admin eszközöket csak admin fiókkal lehet Claude-dal összekötni.</p>
</div>
</main>
);
}
return (
<main className="page" style={{ maxWidth: 560 }}>
<div className="page-head">
<span className="eyebrow">Admin eszközök</span>
<h1>{check.client_name} hozzáférést kér</h1>
</div>
<section className="card">
<p>
Ha engedélyezed, a(z) <strong>{check.client_name}</strong> a te admin jogoddal használhatja a Sorsfonalak
admin eszközeit.
</p>
<ul className="oauth-scope">
<li>
Lekérdezheti a statisztikát, a visszajelzéseket, az értékeléseket, a hibanaplót, a háttérfeladatokat, a
tagokat, a promókódokat és a meghívókat. A tagok e-mail-címe és neve rejtve marad.
</li>
<li>
Elvégezheti a napi teendőket: promókód készítése, visszajelzés megválaszolása, feladat újraindítása, hiba
törlése, meghívó küldése, fórumbejelentés lezárása, kitiltás. Minden ilyen lépés előtt rákérdez.
</li>
<li>Szerepkört, kreditet, csomagot, promptot és modellt nem módosíthat: ezek az admin oldalon maradnak.</li>
</ul>
{check.redirect_host && <p className="hint">Engedélyezés után visszakerülsz ide: {check.redirect_host}.</p>}
<p className="hint">A kapcsolatot bármikor visszavonhatod: Admin → Claude.</p>
<Approve params={params} />
</section>
</main>
);
}