feat(server): advertise available tools dynamically
This commit is contained in:
+26
-5
@@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { z } from "zod";
|
||||
|
||||
import { CATALOG_IDENTITY } from "../src/catalogIdentity.js";
|
||||
|
||||
@@ -11,6 +12,29 @@ const fixturePath = fileURLToPath(
|
||||
new URL("./fixtures/fakeLauncher.mjs", import.meta.url),
|
||||
);
|
||||
|
||||
const expectAvailableToolInventory = async (client: Client): Promise<void> => {
|
||||
const listed = await client.listTools();
|
||||
const status = await client.callTool({
|
||||
name: "binary_session",
|
||||
arguments: { detail: "full" },
|
||||
});
|
||||
const availability = z
|
||||
.object({
|
||||
result: z.object({
|
||||
tool_availability: z.array(
|
||||
z.object({ name: z.string(), available: z.boolean() }),
|
||||
),
|
||||
}),
|
||||
})
|
||||
.parse(status.structuredContent).result.tool_availability;
|
||||
expect(availability).toHaveLength(CATALOG_IDENTITY.counts.mcp_tools);
|
||||
expect(new Set(listed.tools.map(({ name }) => name))).toEqual(
|
||||
new Set(
|
||||
availability.filter(({ available }) => available).map(({ name }) => name),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
describe("production stdio runtime", () => {
|
||||
it("starts the built entrypoint, lists the catalog, calls one, and shuts down", async () => {
|
||||
const transport = new StdioClientTransport({
|
||||
@@ -33,8 +57,7 @@ describe("production stdio runtime", () => {
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
const tools = await client.listTools();
|
||||
expect(tools.tools).toHaveLength(CATALOG_IDENTITY.counts.mcp_tools);
|
||||
await expectAvailableToolInventory(client);
|
||||
const result = await client.callTool({
|
||||
name: "current_document",
|
||||
arguments: {},
|
||||
@@ -80,9 +103,7 @@ describe("production stdio runtime", () => {
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
expect((await client.listTools()).tools).toHaveLength(
|
||||
CATALOG_IDENTITY.counts.mcp_tools,
|
||||
);
|
||||
await expectAvailableToolInventory(client);
|
||||
} finally {
|
||||
await client.close();
|
||||
await transport.close();
|
||||
|
||||
Reference in New Issue
Block a user