Repository navigation
Build the Linear template on Linear's GraphQL API - #265
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
widefleet-docs | 2ca211e | Nov 22 2026, 08:29 PM |
8cceb00 to
bfa4de6
Compare
bfa4de6 to
787c2a5
Compare
…P server The template connects each user's Linear account and calls Linear's hosted MCP server. With managed OAuth it signs in through a Client ID Metadata Document client; otherwise an administrator registers a Linear OAuth application. Both kinds of token work on the MCP server, so the connector has one API path and reads the account profile from the same origin.
The connector no longer wraps four fixed tools. listTools returns Linear's current tools with their input schemas and hints, and callTool passes any call through unchanged. The connector requests read and write, so Linear's writing tools are available. Schemas and results travel as JSON text: typed service bindings cannot map recursive JSON types. JSON-RPC errors such as an unknown tool return linear_error instead of failing the call.
src/tools.ts is generated from Linear's tool list: each tool becomes a typed method with Linear's description, and its JSON Schema validates the arguments before anything is sent. listTools and callTool are gone; apps call env.LINEAR.listIssues and the like. Tools that Linear marks as able to delete or overwrite data ask the user through input_required before they run. The generated code records which tools ask, so the decision is reviewed in the diff rather than read from Linear at runtime. Results are JSON values again. The test harness reads the loopback binding through a declared type, as consuming apps do, because Cloudflare's RPC types fail on recursive JSON (cloudflare/workerd#3063).
The template now offers every query and mutation of Linear's GraphQL API as a typed method, generated from Linear's published schema, instead of the tools of Linear's MCP server. Methods take the fields to return and their results have exactly the selected fields, including arguments of nested fields and fields per type of unions and interfaces. Each mutation is classified as creating, updating or deleting data in scripts/operations.ts, which also records the operations that are not offered and why. Mutations ask the user first as their approval level says: every change, changes to existing data (the default) or never. Users choose their level on the app's page or with setApprovalLevel, where asking less needs confirmation. Managed OAuth uses a registered Linear OAuth application for Linear's API.
787c2a5 to
b167bca
Compare
|
|
||
| type Selection = z.infer<typeof selection>; | ||
|
|
||
| const argumentValues = z.record(z.string(), json.optional()); |
There was a problem hiding this comment.
Optional values stop valid requests
Nested optional values are rejected instead of omitted. For example, building issueCreate input with description: undefined throws InvalidRequest before the request runs. The .optional() here permits only an entire argument to be undefined; z.json() still rejects undefined fields inside it. The same problem affects $args inside selections.
Remove undefined object fields before parsing, while preserving explicit null values. Otherwise callers must manually leave out each optional field.
There was a problem hiding this comment.
Fixed in a57f3ec. Arguments go through a JSON round trip before they are checked, so undefined fields are left out at every depth. src/graphql.test.ts covers issueCreate with input: { teamId, description: undefined }, which sends { teamId }.
A selection accepted misspelled fields next to valid ones, since a generic constraint does not reject extra properties. Methods now type the selection with Exact, which makes every field and argument the schema does not name a compile error, also in nested selections. Undefined values inside input objects failed the JSON check before the request was written. They are now left out at every depth, as JSON leaves them out.
The JSON round trip that left out undefined fields also turned NaN and Infinity into null, which clears a field such as an issue estimate. Input is now checked as JSON that leaves out undefined object fields and rejects non-finite numbers before anything is asked or sent.
A selection could leave out $args of a field whose arguments Linear requires, such as Team.membership, and Linear rejected the request. Such fields now require $args in the selection type. The page started a save for every change of the approval level, so an earlier, slower save could finish last. Saves now run one after another and each sends the latest choice.
Seven mutations that create data can also change existing data, such as issueLabelCreate replacing team labels or issueRelationCreate closing a duplicate. operations.ts now classifies them as updates, so they ask at the default approval level. Results of unions and interfaces promise __typename, but the request asked for it only with $on. It is now always requested for these types.
Depends on #308 and #309 (stack). The generated API documents within limits only with generic declarations documented once (#308).
What changes
New
templates/linearon Linear's GraphQL API.read,write) and offers every query and mutation ofhttps://api.linear.app/graphqlas a typed method with the same name: 422 methods today.pnpm generate(scripts/generate.ts) downloads Linear's published schema from Linear's SDK repository and writessrc/api.ts(types and methods, with Linear's descriptions as TSDoc) andsrc/schema.ts(field types and argument types for writing requests).connectionStatusreports setup and linking, as in the other templates.Typed selections.
tests/types.ts).$argspasses arguments of nested fields:{ comments: { $args: { first: 5 }, nodes: { body: true } } }. Fields with arguments are methods of their type, so declaration files keep them.$onselects fields per concrete type of unions and interfaces; results carry__typename.Selection<T>is a plain mapped type: a conditional type made the documentation extractor expand each selection in full.Which operations are offered.
scripts/operations.tslists every mutation ascreate,updateordelete, or as not offered with a reason. Generation stops on a mutation it does not list and on names it lists that the schema no longer has.actor=app) operations, OAuth application management (oauth:createscope), completing other providers' OAuth authorizations, release pipeline access keys, Linear website operations without a user, and one operation Linear marks internal.initiativeUpdateandprojectUpdateshare their names with mutations; they areinitiativeUpdateByIdandprojectUpdateById. Generation fails on any other name collision.adminscope stay offered: Linear does not document which they are, and it answers them with an error.Approval levels.
all_changes,updates_and_deletions(default: only creating runs at once) ornone.input_requiredwith the mutation and its input, shortened to the 4,096-character limit;declineddoes not run. Users without a connection getconnection_requiredinstead of a question.approvalLevelreads it;setApprovalLevelasks for confirmation before asking less, and takes effect at once for asking more.Results and errors.
connectedwithdata, orlinear_errorwith Linear's errors (itsuserPresentableMessagewhere present). HTTP 401 and GraphQL authentication errors givereconnect_required; HTTP 429 andratelimitederrors giverate_limitedwithRetry-After. Questions have nostatusand other results noresultType, so callers can branch on either field.Login.
provider: "linear") withhttps://api.linear.appas its host and revocation athttps://api.linear.app/oauth/revoke. The CIMD client for Linear's MCP server is no longer used.LINEAR_CLIENT_IDandLINEAR_CLIENT_SECRETas before. Better Auth's Linear provider reads the profile from theviewerquery.widefleet.jsoncdeclares onlyhttps://api.linear.app.Screenshots
Connected account page, before and after (390 and 1280 px). The page has no dark theme, like the other template pages.
Saving failed: the previous level returns with a notice.
Tests
templates/linear/src/graphql.test.ts: request writing (variables with schema types, nested$args,$on, scalar fields with arguments) and rejected selections and inputs, including prototype keys.templates/linear/tests/app.test.tsagainst a synthetic Linear OAuth application and GraphQL API: the GraphQL requests sent, all three approval levels, confirming and declining, per-user levels, the page's level form and its origin check, Linear errors, rate limits, revoked tokens, refresh and outages, user and issuer isolation, replayed callbacks.tests/types.ts: result types of selections and the compile errors above.packages/app-runtime/src/template-oauth.test.ts: Linear runs the managed OAuth suite through the real broker with a registered client, including revocation on disconnect.pnpm checkandpnpm exec vitest runpass.runtime-errors.integration.test.tsneeds a built control plane, which my checkout lacked; it passes in a checkout with one.Not covered by tests


Confidence Score: 5/5 
The PR appears safe to merge, with one non-blocking part of the previous optional-value finding still open.Findings
Summary
Adds a Linear template with generated GraphQL methods, personal OAuth connections, typed field selections, and per-user approval levels.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Generated Linear method] --> B[Write GraphQL request] B --> C{Mutation?} C -- No --> G[Load user token] C -- Yes --> D[Check connection and approval level] D --> E{Ask first?} E -- No --> G E -- Yes --> F{User answer} F -- Missing --> Q[Return input_required] F -- Decline --> R[Return declined] F -- Accept --> G G --> H[Call Linear GraphQL API] H --> I[Return selected data or error]Reviews (10) · Last reviewed commit: "Ask before creates that change existing ..." · Reviewed by Greptile