Skip to main content
Glama

OpenAPI Schema Explorer

mcp-test-helpers.ts1.58 kB
import { Client } from '@modelcontextprotocol/sdk/client/index.js'; import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; // import path from 'path'; // Export the interface export interface McpTestContext { client: Client; transport: StdioClientTransport; cleanup: () => Promise<void>; } interface StartServerOptions { outputFormat?: 'json' | 'yaml' | 'json-minified'; } /** * Start MCP server with test configuration */ export async function startMcpServer( specPath: string, options: StartServerOptions = {} ): Promise<McpTestContext> { let transport: StdioClientTransport | undefined; let client: Client | undefined; try { // Initialize transport with spec path as argument transport = new StdioClientTransport({ command: 'node', args: [ 'dist/src/index.js', // path.resolve(specPath), specPath, ...(options.outputFormat ? ['--output-format', options.outputFormat] : []), ], stderr: 'inherit', // Pass through server errors normally - they're part of E2E testing }); // Initialize client client = new Client({ name: 'test-client', version: '1.0.0', }); await client.connect(transport); // Create cleanup function const cleanup = async (): Promise<void> => { if (transport) { await transport.close(); } }; return { client, transport, cleanup, }; } catch (error) { // Clean up on error if (transport) { await transport.close(); } throw error; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kadykov/mcp-openapi-schema-explorer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server