8000 fix(cli): serve 2026 from source by aeitwoen · Pull Request #428 · agntn/keys · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ function servesSource(): boolean {

/**
* Serves the live `createMcpServer` over stdio, so an edit costs a restart, not a build.
* @returns {Promise<void>} Once the server is connected.
* @returns {Promise<void>} Once the server listens.
*/
async function serveSource(): Promise<void> {
const module: unknown = await import(sourceMcp.href);
if (!isMcpModule(module)) throw new TypeError("The MCP module has no createMcpServer");
const { StdioServerTransport } = await import("@modelcontextprotocol/server/stdio");
await module.createMcpServer().connect(new StdioServerTransport());
const { serveStdio } = await import("@agntn/tools/stdio");
serveStdio(() => module.createMcpServer());
}

/**
Expand Down
58 changes: 58 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { join, resolve } from "node:path";
import { pathToFileURL } from "node:url";
import { promisify } from "node:util";
import { commandName } from "@agntn/tools/cli";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { beforeAll, describe, expect, it } from "vite-plus/test";
import { keysTools } from "../src/tools.ts";

Expand Down Expand Up @@ -240,3 +242,59 @@ describe("keys usage paths", () => {
}
});
});

/* Connects to `keys mcp`, where `dist: false` lets the checkout serve `src/`. */
async function connect(
dist: boolean,
mode: "legacy" | Readonly<{ pin: "2026-07-28" }>,
): Promise<Client> {
const env = Object.fromEntries(
Object.entries(process.env).filter(
(entry): entry is [string, string] =>
entry[0] !== "KEYS_DIST" && entry[0] !== "NODE_OPTIONS" && entry[1] !== undefined,
),
);
const client = new Client(
{ name: "keys-test", version: "1.0.0" },
{ versionNegotiation: { mode } },
);
await client.connect(
new StdioClientTransport({
command: process.execPath,
args: [bin, "mcp"],
env: dist ? { ...env, KEYS_DIST: "1" } : env,
stderr: "ignore",
}),
);
return client;
}

describe("keys mcp protocol versions", () => {
const builds = [
{ from: "source", dist: false },
{ from: "bundle", dist: true },
];
const toolNames = keysTools.map((tool) => tool.name);

it.each(builds)("lets a client pinned to 2026 listen, from the $from", async ({ dist }) => {
const client = await connect(dist, { pin: "2026-07-28" });
try {
expect(client.getNegotiatedProtocolVersion()).toBe("2026-07-28");
const subscription = await client.listen({ toolsListChanged: true });
expect((await client.listTools()).tools.map((tool) => tool.name)).toEqual(toolNames);
await subscription.close();
} finally {
await client.close();
}
});

it.each(builds)("still opens a 2025 client with initialize, from the $from", async ({ dist }) => {
const client = await connect(dist, "legacy");
try {
expect(client.getNegotiatedProtocolVersion()).toMatch(/^2025-/u);
expect((await client.listTools()).tools.map((tool) => tool.name)).toEqual(toolNames);
} finally {
await client.close();
}
});
});
Loading
0