Skip to content

Build the Linear template on Linear's GraphQL API - #265

Merged
tnkuehne merged 10 commits into
feat/describe-budgetfrom
feat/linear-template
Nov 22, 2026
Merged

tnkuehne merged 10 commits into
feat/describe-budgetfrom
feat/linear-template

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #308 and #309 (stack). The generated API documents within limits only with generic declarations documented once (#308).

What changes

New templates/linear on Linear's GraphQL API.

  • Connects each signed-in user's Linear account (read, write) and offers every query and mutation of https://api.linear.app/graphql as 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 writes src/api.ts (types and methods, with Linear's descriptions as TSDoc) and src/schema.ts (field types and argument types for writing requests).
  • connectionStatus reports setup and linking, as in the other templates.

Typed selections.

  • Methods returning objects take the fields to return. The result has exactly the selected fields with their schema types; unknown fields, missing nested selections and wrong argument types are compile errors (tests/types.ts).
  • $args passes arguments of nested fields: { comments: { $args: { first: 5 }, nodes: { body: true } } }. Fields with arguments are methods of their type, so declaration files keep them.
  • $on selects fields per concrete type of unions and interfaces; results carry __typename.
  • At runtime every argument travels as a GraphQL variable with the type the schema declares. Selections and inputs that do not match the schema fail before anything is asked or sent.
  • 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.ts lists every mutation as create, update or delete, 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.
  • Not offered (57): Linear's sign-in and session flows, agent-app (actor=app) operations, OAuth application management (oauth:create scope), completing other providers' OAuth authorizations, release pipeline access keys, Linear website operations without a user, and one operation Linear marks internal.
  • The queries initiativeUpdate and projectUpdate share their names with mutations; they are initiativeUpdateById and projectUpdateById. Generation fails on any other name collision.
  • Operations needing Linear's admin scope stay offered: Linear does not document which they are, and it answers them with an error.

Approval levels.

  • Queries never ask. Mutations ask as the user's level says: all_changes, updates_and_deletions (default: only creating runs at once) or none.
  • A question returns input_required with the mutation and its input, shortened to the 4,096-character limit; declined does not run. Users without a connection get connection_required instead of a question.
  • Each user's level is kept in the app's D1 database. approvalLevel reads it; setApprovalLevel asks for confirmation before asking less, and takes effect at once for asking more.
  • Users also choose the level on the app's page. The choice saves immediately and returns to the saved level with a notice if saving fails.

Results and errors. connected with data, or linear_error with Linear's errors (its userPresentableMessage where present). HTTP 401 and GraphQL authentication errors give reconnect_required; HTTP 429 and ratelimited errors give rate_limited with Retry-After. Questions have no status and other results no resultType, so callers can branch on either field.

Login.

  • Managed OAuth uses a registered Linear OAuth application (provider: "linear") with https://api.linear.app as its host and revocation at https://api.linear.app/oauth/revoke. The CIMD client for Linear's MCP server is no longer used.
  • Without managed OAuth, LINEAR_CLIENT_ID and LINEAR_CLIENT_SECRET as before. Better Auth's Linear provider reads the profile from the viewer query.
  • widefleet.jsonc declares only https://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.

Before After

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.ts against 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.
  • Documentation of the template with the CLI from Bound describe output and describe types by name #309: 1.8 MB, 824 types, 425 methods, no warnings; describing a typical method returns 15 to 29 KB.
  • pnpm check and pnpm exec vitest run pass. runtime-errors.integration.test.ts needs a built control plane, which my checkout lacked; it passes in a checkout with one.

Not covered by tests

  • Calls against Linear's production API: the managed Linear OAuth application is not configured in any installation yet.
  • The page in a real browser session; the screenshots render the page's HTML with synthetic values.

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

The PR appears safe to merge, with one non-blocking part of the previous optional-value finding still open.

Findings

  1. P2 Optional values stop valid requests ▶

Summary

Adds a Linear template with generated GraphQL methods, personal OAuth connections, typed field selections, and per-user approval levels.

  • Linear calls now use schema-checked methods with typed field selections.
  • Linear mutations ask users first according to their saved approval level.
  • Each user can connect a Linear account for app calls.
  • Linear appears as a deployable template in the catalog.

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]
Loading

Reviews (10) · Last reviewed commit: "Ask before creates that change existing ..." · Reviewed by Greptile

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs 2ca211e Nov 22 2026, 08:29 PM

Comment thread templates/linear/src/auth.ts Resolved
@tnkuehne tnkuehne changed the title Add a Linear template that reads teams and issues through Linear's MCP server Add a Linear template that exposes every tool of Linear's MCP server Nov 21, 2026
@tnkuehne tnkuehne changed the title Add a Linear template that exposes every tool of Linear's MCP server Add a Linear template with one method per tool of Linear's MCP server Nov 21, 2026
Comment thread templates/linear/src/linear.ts Resolved
@tnkuehne
tnkuehne force-pushed the feat/linear-template branch from 8cceb00 to bfa4de6 Compare November 22, 2026 19:22
@tnkuehne
tnkuehne changed the base branch from main to feat/describe-budget November 22, 2026 19:23
@tnkuehne
tnkuehne added this pull request to stack #310 November 22, 2026 19:23
@tnkuehne tnkuehne changed the title Add a Linear template with one method per tool of Linear's MCP server Build the Linear template on Linear's GraphQL API Nov 22, 2026
@tnkuehne
tnkuehne force-pushed the feat/linear-template branch from bfa4de6 to 787c2a5 Compare November 22, 2026 19:24
Comment thread templates/linear/scripts/operations.ts Resolved
Comment thread templates/linear/src/selection.ts Resolved
Comment thread templates/linear/src/selection.ts Resolved
Comment thread templates/linear/src/page.ts Resolved
…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.
@tnkuehne
tnkuehne force-pushed the feat/linear-template branch from 787c2a5 to b167bca Compare November 22, 2026 19:33
Comment thread templates/linear/src/graphql.ts Outdated

type Selection = z.infer<typeof selection>;

const argumentValues = z.record(z.string(), json.optional());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }.

Comment thread templates/linear/scripts/generate.ts Resolved
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.
Comment thread templates/linear/src/graphql.ts Resolved
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.
@tnkuehne
tnkuehne merged commit 576ad4b into main Nov 22, 2026
17 checks passed
@tnkuehne
tnkuehne deleted the feat/linear-template branch November 22, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant