MCP Fusion/Operate and integrate/Testing

Testing

Ask AI about Vinkius

@mcpfusion/testing runs your tools through the real pipeline in memory: no servers, no tokens, full fidelity on validation, middleware, redaction and Presenters.

Testing an MCP server usually means mocking the protocol and losing confidence. @mcpfusion/testing goes the other way: it runs your real registry through the real pipeline in memory, so a passing test validates the same code path that production executes.

bash
npm install @mcpfusion/testing

The harness

typescript
import { createMCPFusionTester } from '@mcpfusion/testing';
import registry from './src/server';

const t = createMCPFusionTester(registry, { contextFactory: () => ({ db: testDb }) });

test('get_invoice hides PII and teaches units', async () => {
  const result = await t.callAction('billing', 'get_invoice', {
    id: 'inv_2026_0417',
  });

  expect(result.data.email).toBeUndefined();
  expect(result.systemRules).toContain(
    'amount_cents is in CENTS. Divide by 100.',
  );
  expect(result.rawResponse).toContain('billing.remind');
});

One call, and the assertion inspects exactly what the agent would receive: the structured content after redaction, the system rules the Presenter injects, the affordances it suggests.

What runs for real

StageFidelity
Input validationReal Zod schemas from the builder
MiddlewareReal chains, real context derivation
RedactionReal compiled redaction functions
Presenter shapingReal schemas, rules, UI blocks, affordances
TransportMocked, the only part replaced

Because the harness runs in memory with no server and no tokens, tests are fast enough to run on every push, including in CI.

What to test

  • The egress contract. Assert PII fields are absent from result.data. This is the test that catches the day someone adds a field and forgets the redaction path.
  • The rules. Assert systemRules contains the unit and currency lines your Presenter promises.
  • Affordances. Assert .suggest() offers the right next actions per state.
  • Failure shape. Assert Result failures come back with availableActions so agents self heal.
  • State gating. With FSM bound tools, assert a tool is absent from the tool list in states that forbid it.

If your AI coding agent wrote the tool, this is where you verify its work. The SKILL.md contract makes the agent promise the pattern; these tests make the CI enforce it. See Skills.

CI

bash
npx vitest run
mcpfusion lock --check ./dist/server.js

Pair the harness with the capability lockfile check from Governance: tests verify behavior, the lockfile verifies the surface did not drift. Together they are the two gates every change passes before deploy.

Next steps

  • Tools: what the harness exercises
  • Governance: the lockfile and CI gate
  • Deploy: ship with confidence, for free