REST APIs from a bundled OpenAPI spec with personal-token auth; Forgejo first (0.1.1-dev.5) #109
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/openapi-upstreams"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In 15 seconds
An upstream can now be a REST API described by an OpenAPI spec, not just an MCP server. It plugs into the existing
UserScopedMcpProxythrough one new transport factory, so per-user tokens, the session pool, the cache, namespacing and error handling are all reused. Users connect with a personal token pasted on the Connections page. Forgejo is the first example; it stays off until you add a config entry.Changes
config.pyopenapi: {spec, base_url, operations}as an alternative tourl;auth: {type: token, header?, prefix?}. Validates file name, HTTPS, 1–64 unique operationIds, header/prefix; rejects stray OAuth fields with token auth. Existing entries parse unchanged.openapi_upstream.py(new, ~150 lines)upstream_mcp.pysave_token,access_token,status,is_connected,disconnect;begin/completerefuse token upstreams; the refresher skips them; remote MCP can use a static token.auth_bundles.pyUpstreamTokenBundle(encrypted; listing shows only a ••••last4 hint).server.pyopenapientries; checks specs at startup.maxlength4096); token upstreams don't widen the CSPform-action.specs/forgejo.json-diff linguist-generated).scripts/vendor_openapi.pyHow to enable Forgejo (after merge and deploy)
Add to
CORN_UPSTREAM_MCP_SERVERSin/etc/corn/app.env. The full 19-operation entry is indeploy/README.md:Then go to Connections, paste a Forgejo token (Settings → Applications), and the
forgejo_*tools appear for you only.Verification
578 tests pass, plus both browser smoke suites. New
tests/test_openapi_upstream.py(23 tests) covers:cookie,x-session-id,x-forwarded-for) never forwarded;tests/test_web.pyadds the token form: CSRF, a bad token rejected without echo, no secret in the page, per-user isolation, and remove.Live run against
code.yawn.dev, using Corn's real proxy path with the workspace token and only the read operations:repoGet john/corn→ public, branchmain;maincombined statussuccess(8 contexts);repoGetContents pyproject.toml.The token didn't appear in any log.
Ruff is clean on the new files; changed files have no new findings.
Review notes and limits
repoMergePullRequest,issueCreateComment,DispatchWorkflow); remove them from your config entry if you don't want them.An upstream entry may set openapi {spec, base_url, operations} instead of url. Corn filters the bundled OpenAPI 3 document to the allowlisted operationIds and serves the generated tools through the existing UserScopedMcpProxy: the only new piece is a transport factory that builds an in-process FastMCP server per user whose HTTP client carries that user's token. Namespacing, session pool, list cache and error handling are reused. auth {type: token, header?, prefix?} lets each user paste a personal access token under Connections -> Linked accounts (CSRF-bound; replace/remove). Stored encrypted under provider upstream_token; never refreshed or displayed. Bundles Forgejo 17.0.1's spec (converted from Swagger 2.0) and adds scripts/vendor_openapi.py to regenerate it reproducibly. Unknown operationIds or a missing spec stop start-up; caller request headers are stripped before any upstream request; generated output schemas are permissive.Change review ·
f334709cc7eb→c849fce03195Call paths changed by this PR
Caller → changed symbol → callee. Each edge labels the line in the caller. One detected entry path (up to 3 hops) is included when found. Static evidence, not a runtime stack trace.
After
Changed symbols:
main—scripts/vendor_openapi.py:21redact_bundle—src/corn/auth_bundles.py:86bundle_to_storage—src/corn/auth_bundles.py:103UpstreamMcpServer.uses_oauth—src/corn/config.py:236_token_auth—src/corn/config.py:240_openapi_source—src/corn/config.py:252Bounded view: 67 more changed symbols and 0 neighbour references omitted.
Overall architecture after this change
Source: c849fce03195 ·
code-review 0.1.0-dev.1.Generated from resolved static calls between reviewed code areas. Numbers are call sites, not request counts.
Framework registration, dynamic dispatch, and unresolved calls are not shown. This is not a deployment map.
Showing 7 of 7 inter-area edges. Edit the reviewed source instead of this generated page.
This diagram is for the linked commit. It refreshes after required checks pass for a new head.
UI added (
c849fce): one card per vended integration on Connections.Every integration Corn vends gets a card: the built-ins (NSW FuelCheck, Transport for NSW, Proton Calendar) and each
CORN_UPSTREAM_MCP_SERVERSentry (Coder, PocketSmith, Forgejo, ...). Each card has:forgejo_*);••••last4hint, never the secret;Connected cards fold the form away behind Replace … and show Remove / Disconnect. Connected integrations sort first.
This replaces the old integration dropdown and its show/hide JavaScript. Legacy stored entries without a card are still listed under Other stored credentials and can be removed. Integrations are still vended by the operator; users only supply credentials.
Verified: 578 tests and both browser suites pass, including filling in FuelCheck through its own card and a 390 px mobile layout with no horizontal scroll.