6357b245a5
- Fixed resource refresh tracking by storing connection references alongside promises to prevent stale deduplication. - Fixed update target resolution to explicitly handle missing ompPath and use path.resolve() for consistent normalization. - Added error handling and logging in Smithery registry detail fetching to gracefully handle failures and track issues. - Fixed virtualization context cleanup in error paths to prevent partially-started instances from remaining active. - Fixed API key retrieval to use dynamic provider configuration instead of hardcoded provider string. - Enhanced test utilities to capture and verify request parameters for improved test coverage and debugging.
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { MCPServerCapabilities, MCPServerConnection, MCPTransport } from "../src/mcp/types";
|
|
|
|
export function createMockTransport(
|
|
responses: Map<string, unknown[]>,
|
|
onRequest?: (method: string, params: Record<string, unknown> | undefined) => void,
|
|
): MCPTransport {
|
|
const callCounts = new Map<string, number>();
|
|
return {
|
|
connected: true,
|
|
async request<T>(method: string, params?: Record<string, unknown>): Promise<T> {
|
|
onRequest?.(method, params);
|
|
const count = callCounts.get(method) ?? 0;
|
|
callCounts.set(method, count + 1);
|
|
const queue = responses.get(method);
|
|
if (!queue || count >= queue.length) {
|
|
throw new Error(`No mock response for ${method} call #${count}`);
|
|
}
|
|
return queue[count] as T;
|
|
},
|
|
async notify() {},
|
|
async close() {},
|
|
};
|
|
}
|
|
|
|
export function createMockConnection(
|
|
capabilities: MCPServerCapabilities,
|
|
transport: MCPTransport,
|
|
): MCPServerConnection {
|
|
return {
|
|
name: "test-server",
|
|
config: { type: "stdio" as const, command: "echo" },
|
|
transport,
|
|
serverInfo: { name: "test", version: "1.0" },
|
|
capabilities,
|
|
};
|
|
}
|