Make PaperTrail plug into Anthropic's Claude Science workbench four ways:
- Remote URL connector: hosted Streamable-HTTP MCP at /api/mcp (45 public tools)
- Local command connector: standalone stdio MCP package under mcp/ (47 tools,
incl. 2 API-key tools) — @modelcontextprotocol/sdk, calls the live API
- Skills: 8 Claude Science Agent Skills under skills/ (import from GitHub / upload)
- Network: docs to allow-list the API domain for the curl path
- Public /connect page showcasing all four methods (judges can see it, no login)
Also:
- Google OAuth sign-in ("Continue with Google") on login + register, wired to
GOOGLE_CLIENT_ID/SECRET; users.password_hash now nullable + auth_provider/
google_sub (migration 0061); password login guards Google-only accounts
- Landing design: center + enlarge the claim input; bigger textarea
tsc clean; app build compiles 362 pages; local MCP smoke-tested end-to-end.
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { NextRequest } from "next/server";
|
|
import { z } from "zod";
|
|
import { ok, fail } from "@/lib/api/response";
|
|
import { withApiKey } from "@/lib/apiv1/gateway";
|
|
import { structureExperiment } from "@/lib/labNotebook/structure";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
// Public API: POST /api/v1/lab-notebook
|
|
// Authenticated by an org API key in the `Authorization: Bearer <api_key>` header
|
|
// (via withApiKey), so external programmatic clients can turn a wet-lab scientist's
|
|
// rough bench notes into a structured, grounded, reproducible experiment record.
|
|
//
|
|
// Stateless compute: this route runs the LAB NOTEBOOK COMPANION engine and returns
|
|
// the result. It does NOT persist anything — the notes are never written to the DB.
|
|
// Metered against the org's `verification` quota by the gateway.
|
|
//
|
|
// Governance: NEVER log the raw notes or any of the scientist's text — only counts.
|
|
// Returns the standard { success, data, error } envelope.
|
|
|
|
const NOTES_MIN = 10;
|
|
const NOTES_MAX = 20000;
|
|
|
|
const BodySchema = z.object({
|
|
notes: z
|
|
.string()
|
|
.min(
|
|
NOTES_MIN,
|
|
"Please provide notes of at least 10 characters."
|
|
)
|
|
.max(
|
|
NOTES_MAX,
|
|
"Notes are too long (max 20000 characters). Trim to a single experiment's bench notes."
|
|
),
|
|
});
|
|
|
|
export const POST = withApiKey(
|
|
async (req: NextRequest) => {
|
|
const json = await req.json().catch(() => null);
|
|
const parsed = BodySchema.safeParse(json);
|
|
if (!parsed.success) {
|
|
return fail(parsed.error.issues[0]?.message ?? "Invalid input.", 400);
|
|
}
|
|
|
|
const result = await structureExperiment(parsed.data.notes);
|
|
return ok(result);
|
|
},
|
|
{ quotaKind: "verification", routeLabel: "v1.lab_notebook" }
|
|
);
|