Get the FREE Ultimate OpenClaw Setup Guide →

mcp-mock-client

Scanned
npx machina-cli add skill a5c-ai/babysitter/mcp-mock-client --openclaw
Files (1)
SKILL.md
1.1 KB

MCP Mock Client

Create mock MCP client for server testing.

Generated Patterns

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { spawn } from 'child_process';

export async function createTestClient(serverCmd: string, args: string[]) {
  const proc = spawn(serverCmd, args, { stdio: ['pipe', 'pipe', 'inherit'] });
  const transport = new StdioClientTransport({ reader: proc.stdout!, writer: proc.stdin! });
  const client = new Client({ name: 'test-client', version: '1.0.0' }, { capabilities: {} });
  await client.connect(transport);
  return { client, close: () => proc.kill() };
}

export async function testTool(client: Client, name: string, args: Record<string, unknown>) {
  const result = await client.callTool({ name, arguments: args });
  return result;
}

Target Processes

  • mcp-server-testing-suite
  • mcp-tool-implementation

Source

git clone https://github.com/a5c-ai/babysitter/blob/main/plugins/babysitter/skills/babysit/process/specializations/cli-mcp-development/skills/mcp-mock-client/SKILL.mdView on GitHub

Overview

mcp-mock-client provides a mock MCP client that runs a server process and communicates over stdio for end-to-end server testing. It enables request/response simulation against an MCP server, validating integration without a live tool. This helps ensure reliable behavior in mcp-server-testing-suite and mcp-tool-implementation workflows.

How This Skill Works

It spawns the server process, wraps its stdio with StdioClientTransport, and creates a Client instance from the MCP SDK. It connects the client to the transport and exposes a close function to terminate the server. The testTool helper then calls the MCP tool by name with a arguments map and returns the result.

When to Use It

  • End-to-end testing of an MCP server by driving it with a mocked client and simulated tool calls
  • Integrating a new MCP tool implementation and verifying correct request handling
  • Regression tests that exercise different argument payloads and responses
  • Sandboxed experiments to observe server behavior under failure or timeout conditions
  • Prototype a test harness that automates common MCP tool invocations against a server

Quick Start

  1. Step 1: Start a mock server using createTestClient(serverCmd, args)
  2. Step 2: Call testTool with the desired tool name and arguments, e.g., testTool(client, 'toolName', { key: value })
  3. Step 3: Close the server with the returned object's close() to terminate the process

Best Practices

  • Start the server in a deterministic environment (fixed versions) to ensure repeatable results
  • Reuse the same client instance for related calls to minimize startup overhead
  • Validate both success and error paths by varying tool names and arguments
  • Always terminate the spawned server with the returned close() function to avoid leaks
  • Log the tool name, arguments, and response for easier debugging

Example Use Cases

  • Run mcp-server-testing-suite against a mocked server to validate end-to-end flows
  • Test mcp-tool-implementation by invoking tools via testTool and asserting outputs
  • Simulate a tool failure and verify client handles error responses
  • Benchmark latency by timing a sequence of testTool calls
  • Validate transport wiring by ensuring the client connects only after spawn completes

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers