Skip to content
Closed
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ A coding agent working a Gleap ticket names its coding session, with the `sessio

Without a session id nothing changes: no header, no extra lines.

The deep link that starts a session carries only one line with the session id. The agent's first call is `get_session_brief` with that id: its result is the whole kickoff (ticket, rules, findings, repository, the Gleap plugin skill to load). A kickoff without a session id works by ticket, as before.

## Available Tools

| Tool | Description |
Expand All @@ -76,14 +78,14 @@ Without a session id nothing changes: no header, no extra lines.
| `get_ticket_types` | List ticket types with their custom fields, status lanes and priorities |
| `get_ticket_messages` | Get the full conversation history (messages) for a ticket |
| `get_ticket_activity_log` | Get the console logs, network requests and click trail the SDK captured with a ticket. Coding agents call it on bug reports before reproducing, to see the console errors, failed requests and the user's clicks. Headers are never returned, secrets are redacted and long logs are trimmed (errors and failed requests first); `section` and `search` narrow it |
| `send_message` | Reply to a customer or add an internal note (Markdown). Agent workflows: the agent asks its operator in its own conversation (an instruction to answer or update the customer is the approval), then sends; with `sessionId` the reply is the session agent's and Gleap refuses a stale one (`stale_thread`, with the new messages) or one after a stop |
| `draft_reply_to_composer` | Stage a drafted reply in the ticket's dashboard composer for a person to review, edit and send. Sends nothing. For a person's own AI client, also when a `.gleap/session.json` from another ticket is still around: Gleap refuses Kai runs and the coding session working that ticket (410), which ask their operator and send with `send_message` |
| `send_message` | Reply to a customer or add an internal note (Markdown). A session started from a ticket's code fix never sends to the customer (Gleap refuses it; it drafts in `report_progress`). Other agent workflows: the agent asks its operator in its own conversation (an instruction to answer or update the customer is the approval), then sends; with `sessionId` the reply is the session agent's and Gleap refuses a stale one (`stale_thread`, with the new messages) or one after a stop |
| `draft_reply_to_composer` | Stage a drafted reply in the ticket's dashboard composer for a person to review, edit and send. Sends nothing. For a person's own AI client, also when a `.gleap/session.json` from another ticket is still around: Gleap refuses Kai runs and the coding session working that ticket (410): Kai runs ask their operator and send with `send_message`, a code-fix session drafts in `report_progress` |
| `get_session_brief` | The kickoff of a Gleap coding session (`sessionId`, required): `GET /gleapcode/sessions/{id}/agent-workflow` without a kind, which returns the brief as Markdown. The brief (ticket, ownership rules, Kai Support's findings, what an earlier session left, repository, skill and setup lines) is the first text block, then the operator feedback and the `.gleap/session.json` content; a stopped session gets only the STOP instruction. Not read-only: it hands out operator feedback, and a multi-project grant must name its project |
| `report_progress` | Report the fix status on the Gleap coding session you were started from (deeplink hand-off loop; session-scoped since 2026-08), the same snapshot every runtime reports: `status` (`queued`, `working`, `needs_input`, `completed`, `failed`, `cancelled`), `step` while working (`investigating`, `reproduced`, `fixing`), a one-line `message`, `question` with `needs_input` (`kind`, `prompt`, `options`, `audience` customer or team), `customerLine` (one sentence of status the customer may read), `howSolved` (one paragraph on how the ticket was solved, sent with the last report; it feeds Kai Support's learning), `agentKind`, `agentName` and `device`. The older `phase` still works: `status` wins, and a report with only `status` also sends the phase it stands for, for a Server from before the fix status. Registers PRs (`completed` with `prUrl`) and takes the two fix messages: `customerUpdateMessage` (sent right away) and `customerShipMessage` (sent when the fix is live, by the project's post-merge setting); the result says what happened to each. The ticket is done when the customer confirms or 24 hours after the last answer without a reply, not at the merge. The result also carries `stop`, `newCustomerMessages` (see Coding sessions) and the `hook` block for `.gleap/session.json` |
| `update_plan` | Live checklist on the Gleap coding session (`sessionId` or `ticketId`, like `report_progress`): the whole list each call, statuses `pending`/`in_progress`/`completed`/`cancelled` |
| `wrap_up` | End-of-turn card on the session: recap, at most one question, 0-2 actions (`merge_pr`, `open_pr`, `review_changes`, `open_preview`; `send_customer_update` is removed and refused) |
| `share_screenshot` | Post a screenshot (optionally a before/after pair) into the session thread. Returns the `curl -T` upload commands to run (the server cannot read local files); `imageBase64` (≤ 1.5 MB each) for agents without a shell |
| `publish_artifact` | Publish a self-contained HTML page (≤ 1 MB) into the session thread; `artifactId` publishes a new version |
| `get_agent_workflow` | The Gleap ticket workflow (`fix`, `answer`, `feature`) as Markdown, plus the `.gleap/session.json` content for the Gleap plugin |
| `get_ticket_screenshot` | The ticket's SDK screenshot as image content (Gleap file hosts only, ≤ 2 MB) |
| `describe_database` | The team's own databases Kai Code may read (read-only, this ticket's customer only): tables, columns, masked columns, query format. Kai Code runs on a ticket only (the run key's ticket pin); refused for every other connection |
| `query_database` | One read-only query (a SQL SELECT or a MongoDB JSON request) on the team's database, kept to the ticket's customer (`scope: team` across customers always waits for a data owner); at most 200 rows, sensitive columns masked. It may wait for a person's approval (`status: pending` with a `queryId`). Values from results never go into code, tests, fixtures, commits or PRs. Kai Code runs on a ticket only |
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ const publicUrlFor = (req: express.Request) =>
// agent-setup docs and the per-tool descriptions repeat them, but every
// client that surfaces instructions gets the policy without fetching a doc.
const SERVER_INSTRUCTIONS = `Gleap workspace tools. If you are working a ticket or feature request as a coding agent (a Gleap kickoff, workflow or the Gleap plugin brought you here), these rules apply:
1. Your session owns the ticket until it is solved: keep working it through the customer's replies. You work for the person who runs you, and Gleap never refuses your writes: when a teammate replies on the ticket or takes it over, tell your operator in one line and follow their call. Results list new customer messages you have not seen yet: read them before you go on. Close, archive or snooze the ticket, or change its assignee, only when your operator tells you to: Gleap marks it done when the customer confirms the fix, or 24 hours after the last answer without a reply.
2. Customer messages: ask your operator in your own conversation, then send what they approved with send_message (isNote: false, with your sessionId) and tell them in one line what you sent. When your operator tells you to answer, tell, reply to or update the customer, that is the approval. A coding session never stages a reply in the ticket composer (Gleap refuses it). If a send_message result lists new customer messages, they came in before your reply went out: read them, and if your reply no longer fits, tell your operator and follow up.
1. When a kickoff names a Gleap coding session, call get_session_brief with it first. A session started from a ticket's code fix owns the ticket until its pull request is open, then Operator has it again; otherwise your session owns it until it is solved. You work for the person who runs you: when a teammate replies on the ticket or takes it over, tell your operator in one line and follow their call. Results list new customer messages you have not seen yet: read them before you go on. Close, archive or snooze the ticket, or change its assignee, only when your operator tells you to: Gleap marks it done when the customer confirms the fix, or 24 hours after the last answer without a reply.
2. Customer messages: a session started from a ticket's code fix never sends anything to the customer (Gleap refuses its send_message): it reports with report_progress, drafts in customerLine, customerUpdateMessage and customerShipMessage, and Kai tells the customer. Otherwise (your own AI client on a ticket): ask your operator in your own conversation, then send what they approved with send_message (isNote: false, with your sessionId) and tell them in one line what you sent. When your operator tells you to answer, tell, reply to or update the customer, that is the approval. A coding session never stages a reply in the ticket composer (Gleap refuses it). If a send_message result lists new customer messages, they came in before your reply went out: read them, and if your reply no longer fits, tell your operator and follow up.
3. Report with report_progress on every step change: status working with step investigating, reproduced or fixing and a one-line message, plus customerLine (one sentence the customer may read) when the step matters to them. When you need an answer, report needs_input with the question instead of waiting silently; when you cannot fix it, report failed with the reason. Status, findings and PR links belong in report_progress, not in internal notes and not in the customer thread.
4. When you open a PR, report completed with prUrl and the customer messages (normally both): customerUpdateMessage (sent right away: the fix is built, it is being reviewed and deployed, and we will update them) and customerShipMessage (sent when the fix is live, following the project's settings; for SDK or app repositories say it ships in the next release). Write them in the customer's language as plain text, following the fix-message rules and the team's instructions for customer messages that every report_progress result gives you for this project. Feature requests pass neither: Gleap notifies the upvoters when the request ships. Never send your own "it's fixed" or "it's live" message. With the PR also pass problem and fix (one to three simple sentences each) for the team's Merge card. By default the ticket moves to Done when the PR merges to production; a customer reply reopens it.
5. When the ticket is solved, end with report_progress and howSolved: one paragraph on how it was solved (the cause, what changed or what you answered, how you checked it), with no customer data; it feeds Kai Support's learning. Work visibly in the Gleap session: keep a plan with update_plan for any task with more than two steps; after you checked a user-visible change, share_screenshot 1-3 screenshots with a one-line caption; use publish_artifact for reports, mockups or anything easier to read as a page; end EVERY turn with wrap_up (recap first, then at most one question with one or two actions, recommended first). When a result gives you the .gleap/session.json content, write it and add .gleap/ to .git/info/exclude.
Expand Down
4 changes: 2 additions & 2 deletions src/schemas/progress.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const FIX_STATUSES = ["queued", "working", "needs_input", "completed", "f
export const FIX_STEPS = ["investigating", "reproduced", "fixing"] as const;
export const QUESTION_KINDS = ["question", "approval", "auth", "choice"] as const;
export const QUESTION_AUDIENCES = ["customer", "team"] as const;
export const AGENT_KINDS = ["claude_code", "codex", "cursor", "other"] as const;
export const AGENT_KINDS = ["claude_code", "codex", "cursor", "antigravity", "other"] as const;
export const AGENT_PHASES = ["investigating", "reproduced", "fixing", "pr_opened", "blocked", "done"] as const;

export const ReportProgressArgs = z.object({
Expand Down Expand Up @@ -83,7 +83,7 @@ export const ReportProgressArgs = z.object({
agentKind: z
.enum(AGENT_KINDS)
.optional()
.describe("Which coding agent you are: claude_code, codex, cursor, or other (then name yourself in agentName). Tags the session and every message you write. Send it on every report."),
.describe("Which coding agent you are: claude_code, codex, cursor, antigravity, or other (then name yourself in agentName). Tags the session and every message you write. Send it on every report."),
agentName: z
.string()
.max(60)
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/session.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export const PublishArtifactArgs = z.object({
.describe("Pass the artifactId from an earlier result to publish a new version of the same page instead of a new one."),
});

export const GetSessionBriefArgs = z.object({
sessionId: SESSION_ID.unwrap().describe("The 24-char Gleap coding-session id your kickoff names."),
});

export const GetTicketScreenshotArgs = z.object({
ticketId: z
.string()
Expand Down
35 changes: 35 additions & 0 deletions src/tools/session.tool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import axios from "axios";
import {
GetSessionBriefArgs,
GetTicketScreenshotArgs,
MAX_ARTIFACT_HTML_BYTES,
MAX_SHARE_BASE64_BYTES,
Expand Down Expand Up @@ -61,7 +62,21 @@
/** Ticket screenshots the tool returns inline (MCP image content). */
export const MAX_TICKET_SCREENSHOT_BYTES = 2_000_000;

export const registerSessionTools = (server: McpServer) => {

Check warning on line 65 in src/tools/session.tool.ts

View workflow job for this annotation

GitHub Actions / quality

quality function-lines

[function-lines] src/tools/session.tool.ts:65 function "registerSessionTools": 174 -> 185 code lines (limit 80) Fix: Split by responsibility: extract a part into its own function or sub-component at module level. Never squeeze code onto fewer lines.
server.registerTool(
"get_session_brief",
{
title: "Get Session Brief",
description:
"The kickoff of a Gleap coding session: the first call when a kickoff names a Gleap coding session (its sessionId). The result is the agent's kickoff: the ticket, the ownership rules, Kai Support's findings, what an earlier session left, the repository and the setup steps. The workflow itself comes from the Gleap plugin skill the brief names. The result also carries the operator's newest feedback and the session file the Gleap plugin reads. A stopped session returns only the STOP instruction.",
inputSchema: GetSessionBriefArgs.shape,
// Not read-only: Gleap hands out operator feedback once, and a
// multi-project grant must name the session's project.
annotations: { ...WRITE, idempotentHint: true },
},
async ({ sessionId }): Promise<GleapApiResponse> => getSessionBrief(sessionId),
);

server.registerTool(
"update_plan",
{
Expand Down Expand Up @@ -289,6 +304,26 @@
);
};

/**
* The session's kickoff: GET agent-workflow without a kind, so the Server picks the session's own
* kind and returns the brief as Markdown (`markdown`; `brief` is its structured form).
*/
export const getSessionBrief = async (sessionId: string): Promise<GleapApiResponse> => {
const route = sessionRoute({ sessionId }, "agent-workflow");
if (!route) return failure("Pass sessionId: the 24-char Gleap coding-session id your kickoff names.");
const fetched = await gleapGetData(route.path);
if ("error" in fetched) return fetched.error;
const result = (fetched.data ?? {}) as Record<string, any>;

Check warning on line 316 in src/tools/session.tool.ts

View workflow job for this annotation

GitHub Actions / quality

quality type-assertion

[type-assertion] src/tools/session.tool.ts:316 `as` assertions in this file, new at line 316: 7 -> 8 found Fix: Narrow with a type guard, or fix the type where it comes from. `as const` is fine.

Check warning on line 316 in src/tools/session.tool.ts

View workflow job for this annotation

GitHub Actions / quality

quality any

[any] src/tools/session.tool.ts:316 `any` in this file, new at line 316: 11 -> 12 found Fix: Use the real type, or unknown with a type guard. `as unknown as T` is `any` in disguise.
const early = stoppedOrFailed(result);
if (early) return early;
const brief = typeof result.markdown === "string" ? result.markdown : "";
if (!brief.trim()) return failure("Gleap returned no brief for this session.");
return withLines(
{ content: [{ type: "text", text: brief }], structuredContent: result },
[operatorFeedbackLine(result), hookLine(result)],
);
};

const ticketRefPath = (ticketId: string): string => encodeURIComponent(ticketId.trim().replace(/^#/, ""));

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/mcp-endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ describe('API key headers', () => {
await client.close();
});

test("the instructions match the Server's code-fix rule: such a session never writes to the customer", async () => {
const client = await connect(apiKeyHeaders());
const instructions = client.getInstructions() ?? '';
await client.close();
assert.doesNotMatch(instructions, /never refuses your writes/);
// A session started from a ticket's code fix reports and drafts; Kai tells the customer.
assert.match(instructions, /code fix[^\n]*never send(s)? (anything )?to the customer/i);
assert.match(instructions, /customerUpdateMessage/);
// A person's own AI client working a ticket outside a code fix still asks its operator, then sends.
assert.match(instructions, /ask your operator[^\n]*send_message/i);
});

test('concurrent clients each get their own project, never another one', async () => {
gleapApi.answerWith((request) => ({ status: 200, data: [{ _id: request.headers.project, name: `team of ${request.headers.project}` }] }));
const projects = Array.from({ length: 12 }, (_, i) => `project-${i}`);
Expand Down
Loading