@purplesquirrel/mcp-core-ts
v0.1.0
Published
Shared MCP server infrastructure — TypeScript mirror of psm-mcp-core (Rust)
Maintainers
Readme
@purplesquirrel/mcp-core-ts
Shared MCP server infrastructure for TypeScript. Mirror of psm-mcp-core (Rust).
Modules
| Module | What it does |
|--------|-------------|
| error | PsmMcpError (10 variants, JSON-RPC codes), sanitizeError() |
| input | validateNoInjection(), validateName(), requireString(), optionalString() |
| tool | ToolHandler, McpAction, textResult(), jsonResult(), errorResult() |
| filter | OutputFilter — 9 secret patterns + 4 PII patterns |
| health | HealthCheck, healthy(), degraded(), unhealthy() |
| audit | AuditLogger — in-memory FIFO, max 50K entries |
| rate-limit | RateLimiter — sliding window, per-key |
| policy | PolicyEnforcer — 5 default rules (SQLi, XXE, path traversal, command injection, secrets) |
| shell | runCommand() with timeout, shellEscape(), stripAnsi() |
Install
npm install @purplesquirrel/mcp-core-ts
# or local:
npm install --save file:../psm-mcp-core-tsUsage
import {
requireString, validateNoInjection, sanitizeError,
textResult, errorResult, OutputFilter,
} from "@purplesquirrel/mcp-core-ts";
// In your tool handler:
const name = requireString(args, "name");
validateNoInjection(name, "name");
// Filter output:
const filter = new OutputFilter();
const result = filter.filter(apiResponse);
// Error handling:
catch (err) {
return errorResult(sanitizeError(err.message));
}Tests
npm test # 117 tests (63 core + 54 shared vectors)
npm run check:typesShared test vectors in tests/shared-vectors.json run identically in both TypeScript and Rust.
