@mcpspec/core
v1.2.2
Published
Core engine for [MCPSpec](https://www.npmjs.com/package/mcpspec) — the reliability platform for MCP servers. MCP client, test runner, security scanner (including Tool Poisoning detection), performance profiler, documentation generator, quality scorer, rec
Downloads
941
Readme
@mcpspec/core
Core engine for MCPSpec — the reliability platform for MCP servers. MCP client, test runner, security scanner (including Tool Poisoning detection), performance profiler, documentation generator, quality scorer, recording/replay, and mock server generator.
For CLI usage, install
mcpspecinstead. This package is for programmatic use — embedding MCPSpec capabilities in your own tools.
Installation
npm install @mcpspec/coreUsage
Connect to an MCP server
import { MCPClient } from '@mcpspec/core';
const client = new MCPClient({
transport: 'stdio',
command: 'npx',
args: ['@modelcontextprotocol/server-filesystem', '/tmp'],
});
await client.connect();
const tools = await client.listTools();
const result = await client.callTool('read_file', { path: '/tmp/test.txt' });
await client.disconnect();Run a test collection
import { TestRunner, ConsoleReporter, loadYamlSafely } from '@mcpspec/core';
import { readFileSync } from 'node:fs';
const yaml = readFileSync('./collection.yaml', 'utf-8');
const collection = loadYamlSafely(yaml);
const runner = new TestRunner();
const results = await runner.run(collection, {
reporter: new ConsoleReporter(),
});
console.log(`${results.summary.passed}/${results.summary.total} passed`);Exports
Client
MCPClient— Core MCP client (stdio, SSE, streamable-http transports)MCPClientInterface— Abstract interface for swappabilityConnectionManager— Connection state machine with reconnectionLoggingTransport— Protocol message logging
Process Management
ProcessManagerImpl— Spawn, monitor, and cleanup MCP server processesProcessRegistry— Track all managed processesregisterCleanupHandlers— Graceful shutdown on SIGINT/SIGTERM
Testing
TestRunner— Orchestrates collection executionTestExecutor— Executes individual test casesTestScheduler— Parallel execution with dependency resolution
Assertions
Evaluated via TestExecutor — schema, equals, contains, exists, matches, type, length, latency, mimeType, expression (safe expr-eval).
Reporters
ConsoleReporter— Terminal output with colorsJsonReporter— JSON outputJunitReporter— JUnit XML for CIHtmlReporter— Standalone HTML reportTapReporter— TAP protocol
Comparison
BaselineStore— Save and load test run baselinesResultDiffer— Diff two test runs
Security
SecurityScanner— Orchestrates security auditsScanConfig— Safety controls and mode filtering- Rules:
PathTraversalRule,InputValidationRule,ResourceExhaustionRule,AuthBypassRule,InjectionRule,InformationDisclosureRule,ToolPoisoningRule,ExcessiveAgencyRule getSafePayloads,getPlatformPayloads,getPayloadsForMode— Payload management
Performance
Profiler,computeStats— Timing and statisticsBenchmarkRunner— Iterative benchmarking with warmupWaterfallGenerator— Waterfall chart data
Documentation
DocGenerator— Orchestrates doc generation from server introspectionMarkdownGenerator— Markdown outputHtmlDocGenerator— HTML output
Scoring
MCPScoreCalculator— 0–100 quality score across 5 categories; schema quality uses opinionated linting (property types, descriptions, constraints, naming conventions)BadgeGenerator— shields.io-style SVG badges
Recording & Replay
RecordingStore— Save, load, list, and delete session recordingsRecordingReplayer— Replay recorded steps against a live serverRecordingDiffer— Diff original recording vs replayed results (matched/changed/added/removed)
Mock Server
MockMCPServer— Start a mock MCP server from a recording (stdio transport, drop-in replacement)ResponseMatcher— Match incoming tool calls to recorded responses (matchorsequentialmode)MockGenerator— Generate standalone.jsmock server files (only requires@modelcontextprotocol/sdk)
Utilities
loadYamlSafely— FAILSAFE_SCHEMA YAML parsingSecretMasker— Redact secrets from outputresolveVariables— Template variable resolutionqueryJsonPath— JSONPath queriesgetPlatformInfo— Cross-platform data/config directoriesRateLimiter— Throttle MCP callsMCPSpecError,formatError— Structured error handling
License
MIT
