mcp-extras.test.ts
This file
Path
apps/cli/test/mcp-extras.test.ts
170 lines · 4.8 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–8why, one step back1import { describe, expect, it } from "@effect/vitest";2import { commandDocs } from "@repo/agent-kit/command-doc";3import { readManaged } from "@repo/agent-kit/generated-file";4import { platformSkill } from "@repo/agent-kit/platform";5import { Brand } from "@repo/brand";6import { Contracts } from "@repo/protocol/contracts";7import { Ask, AskListing } from "@repo/protocol/domain/ask";8import { CheckSpec } from "@repo/protocol/domain/check";Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 9why, one step back9import { AskId, keyOf, ProjectName, RepoPath } from "@repo/protocol/ids";Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 10–14why, one step back10import { unanswered } from "@repo/protocol/testing";11import { Effect, Layer, Option, Schema } from "effect";1213import { session } from "./stdio.ts";14Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 15why, one step back15const project = ProjectName.make("oscabriel/datekit");Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 16–70why, one step back1617const fixWeek = AskId.make("fix-week");1819const want = "week reads the ISO week of a date";2021const askWire = {22 askedBy: "dora",23 blockedBy: [],24 brief: { want },25 check: Schema.encodeSync(CheckSpec)(26 CheckSpec.cases.RedThenGreen.make({27 path: RepoPath.make(`test/${fixWeek}.test.ts`),28 })29 ),30 file: `${Brand.configDir}/asks/${fixWeek}.ask.ts`,31 id: fixWeek,32 kind: "fix",33 openedAt: "2026-10-07T12:00:00.000Z",34 openedIn: "4444444444444444444444444444444444444444",35 project,36 state: "open",37 territory: { module: ".", paths: ["src/week.ts"] },38} as const;3940const brief = `# ${fixWeek}\n\n${want}.\n`;4142const datekit = Layer.mergeAll(43 unanswered,44 Contracts.toLayerHandler("showAsk", ({ ask }) =>45 ask === fixWeek46 ? Effect.succeed({ ask: Schema.decodeSync(Ask)(askWire), brief })47 : Effect.die(`the test asked for ${ask}`)48 ),49 Contracts.toLayerHandler("listAsks", () =>50 Effect.succeed({51 asks: [52 Schema.decodeSync(AskListing)({53 ask: fixWeek,54 blockedBy: [],55 claimed: false,56 kind: "fix",57 territory: ".",58 want,59 }),60 ],61 })62 )63);6465const meta = {66 "io.modelcontextprotocol/clientCapabilities": {},67 "io.modelcontextprotocol/clientInfo": { name: "test", version: "0.0.0" },68 "io.modelcontextprotocol/protocolVersion": "2026-07-28",69};70Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
line 71why, one step back71// The stateless 2026-07-28 protocol: every request carries its own `_meta`.Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 72–114why, one step back72const request = (73 id: number,74 method: string,75 params: Readonly<Record<string, Schema.Json>> = {}76) => ({ id, jsonrpc: "2.0", method, params: { _meta: meta, ...params } });7778const TextContents = Schema.Struct({79 contents: Schema.Array(80 Schema.Struct({81 mimeType: Schema.optionalKey(Schema.String),82 text: Schema.String,83 uri: Schema.String,84 })85 ),86});8788const PromptText = Schema.Struct({89 description: Schema.optionalKey(Schema.String),90 messages: Schema.NonEmptyArray(91 Schema.Struct({92 content: Schema.Struct({93 text: Schema.String,94 type: Schema.Literal("text"),95 }),96 role: Schema.Literal("user"),97 })98 ),99});100101const skillBody = platformSkill({ commands: commandDocs(Contracts) }).pipe(102 Effect.map(([file]) =>103 Option.match(104 Option.flatMap(Option.fromNullishOr(file), ({ content }) =>105 readManaged(content)106 ),107 { onNone: () => "", onSome: ({ body }) => body }108 )109 )110);111112describe("the CLI's MCP server over stdio, beside its tools", () => {113 it.effect("reads an ask's brief through the Client, in Markdown", () =>114 Effect.gen(function* () {Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 115why, one step back115 const uri = `${Brand.urlScheme}ask/${keyOf(project)}/${fixWeek}`;Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 116–170why, one step back116117 const replies = yield* session(datekit, [118 request(1, "server/discover"),119 request(2, "resources/read", { uri }),120 ]);121122 expect(replies.get(2), "resources/read gave a result").toBeDefined();123124 const read = yield* Schema.decodeUnknownEffect(TextContents)(125 replies.get(2)126 );127128 expect(read.contents).toStrictEqual([129 { mimeType: "text/markdown", text: brief, uri },130 ]);131 })132 );133134 it.effect("gives the platform's skill as the prompt contribute", () =>135 Effect.gen(function* () {136 const body = yield* skillBody;137138 const replies = yield* session(datekit, [139 request(1, "server/discover"),140 request(2, "prompts/get", { name: "contribute" }),141 request(3, "prompts/get", {142 arguments: { project },143 name: "contribute",144 }),145 ]);146147 expect(148 [replies.get(2), replies.get(3)],149 "prompts/get gave results"150 ).not.toContain(undefined);151152 const bare = yield* Schema.decodeUnknownEffect(PromptText)(153 replies.get(2)154 );155156 const named = yield* Schema.decodeUnknownEffect(PromptText)(157 replies.get(3)158 );159160 const text = named.messages.map(({ content }) => content.text).join("\n");161162 expect(body).toContain(`# ${Brand.name}`);163 expect(bare.messages.map(({ content }) => content.text)).toStrictEqual([164 body,165 ]);166 expect(text).toContain(body);167 expect(text).toContain(fixWeek);168 })169 );170});