File size: 1,632 Bytes
7a1ad33 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | /**
* @license
* Copyright 2026 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Response structure for a test tool call.
*/
export interface TestToolResponse {
content: { type: 'text'; text: string }[];
isError?: boolean;
}
/**
* Definition of a test tool.
*/
export interface TestTool {
name: string;
description: string;
/** JSON Schema for input arguments */
inputSchema?: Record<string, unknown>;
response: TestToolResponse;
}
/**
* Configuration structure for the generic test MCP server template.
*/
export interface TestMcpConfig {
name: string;
version?: string;
tools: TestTool[];
}
/**
* Builder to easily configure a Test MCP Server in tests.
*/
export class TestMcpServerBuilder {
private config: TestMcpConfig;
constructor(name: string) {
this.config = { name, tools: [] };
}
/**
* Adds a tool to the test server configuration.
* @param name Tool name
* @param description Tool description
* @param response The response to return. Can be a string for simple text responses.
* @param inputSchema Optional JSON Schema for validation/documentation
*/
addTool(
name: string,
description: string,
response: TestToolResponse | string,
inputSchema?: Record<string, unknown>,
): this {
const responseObj =
typeof response === 'string'
? { content: [{ type: 'text' as const, text: response }] }
: response;
this.config.tools.push({
name,
description,
inputSchema,
response: responseObj,
});
return this;
}
build(): TestMcpConfig {
return this.config;
}
}
|