Repository navigation
Replies: 1 comment 9 replies
|
The keys are not just for accessing the MCP Server. The keys should be usable to access the API for automation tasks as well. So my approach would be to keep it behind a feature flag. @zorak1103 Does it answer your questions? My plan is not to 'officially' support the API until v1. |
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Phase 2: read API for API keys
Continues #1273 (MCP-backed agent integration).
Phase 1 — API key management, storage, and the Bearer auth middleware — is merged behind
--enable-api-key-management. This is a proposal for Phase 2, the read API, written up fordiscussion before it becomes an issue.
Summary
Define a documented, stable, read-only HTTP surface that an API key can use: the page tree, a
single page's content, and search. All three already work with a key today. Phase 2 is mostly
about writing that down and locking it with tests, not about building new auth machinery.
What Phase 1 already gives us
InjectAPIKeyUserruns globally on the base router(
internal/http/router.go:161-177), not on a curated set of routes. The router comment says thisis deliberate: a key is exactly as powerful as
role(user) ∩ role(key)everywhere the normalRequireAuth/RequireEditorOrAdminguards apply.Two other pieces make that global injection reach reads specifically.
RequireAuthshort-circuitsonce a
"user"is already set in the Gin context (internal/http/middleware/auth/auth.go:15), soa resolved key and a cookie session are interchangeable at every guarded route. And
CSRFMiddlewareexempts safe methods (internal/http/middleware/security/csrf.go:17-20), while aBearer-only client has no CSRF cookie to send. GET passes, POST/PUT/DELETE do not.
Put together: a valid
lw_key, issued to a user with at least read access, already authenticatesGET /api/tree,GET /api/pages/:id,GET /api/pages/by-path, andGET /api/searchtoday,whenever
--enable-api-key-managementis on and auth is not disabled. No code change is needed forthat part.
Why write a phase for something that already works
Nothing marks these routes as agent-facing. They authenticate a key by accident: the injection is
global, and CSRF happens to let GET through. A later change (adding
RequireCookieSession()to aread route, or narrowing the CSRF exemption) could remove key access from a read route without
anyone noticing, because no test currently checks for it.
An agent, or an MCP tool wrapper built on top of this in Phase 3, needs a route it can rely on. That
means turning an emergent side effect into something explicit: documented, tested, and named as
supported.
Proposed approach
Designated read routes
Three routes, unchanged, become the documented contract:
GET /api/treedepth(optional)dto.Node, recursive treeGET /api/pages/:idorGET /api/pages/by-path?path=dto.Page(content, tags, properties)GET /api/searchq,tags,offset,limitSearchResult(items, tag facets)Documentation
A short section, README or a new
docs/api.md, with acurlexample per route and the rules thatalready hold: read-only for Bearer callers, effective role is
user role ∩ key role, a revoked orexpired key stops working immediately, requests are rate limited per client.
Contract tests
Go tests next to
internal/http/apikeys_router_test.go:These exist to catch a regression before it ships, not to add new behavior.
Stable response shapes
dto.Node,dto.Page, andSearchResultbecome a contract for key holders from this point on. Afield rename or removal on these three types is a breaking change and needs a version note. Phase
3's MCP tools would read these fields directly, so this is where that stability has to start.
No new authentication code is proposed. The mechanism from Phase 1 stays as it is.
Non-goals
Write access through a key stays out of scope; enabling it means solving CSRF for Bearer callers,
which the Phase 1 middleware's doc comment (
apikey.go:36-42) already flags as unresolved. Thisproposal does not add a curated allowlist that blocks keys from other GET routes — that would
undo the global design Phase 1 chose on purpose. No new endpoints. No MCP transport (Phase 3). No
semantic or vector search, to keep the single-binary, FTS5-only model. The reserved
scopesfieldon a key stays unused.
Open questions
/api). Should the docs call out only these three as supported, leaving the rest reachable butunsupported, or should access be formally narrowed to just these three later?
docs/api.md?by-idorby-path, or both?dto.Node/dto.Page/SearchResultas a stable shape reasonable now, orpremature before an MCP consumer exists?
Phasing
Phase 1 (API key management): merged, behind
--enable-api-key-management.Phase 2 (read API): this proposal.
Phase 3 (MCP endpoint): thin tool wrappers over the Phase 2 routes, sketched in the original issue.
All reactions