Flows category icon
MCP & Tooling
Intermediate

Testing MCP Tools

Bring TDD discipline to MCP servers: unit-test handlers, protocol-test the surface, and contract-test against a real host.

4 steps12 verify checks60-90 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

The Route

0/4 verified

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
My MCP server works until it does not - host updates, schema drift, and edge inputs break it silently. The best MCP codebases treat tools as testable functions with protocol-level and contract-level suites on top.

GOAL:
Build a three-layer test suite for my MCP server: handler unit tests, protocol surface tests, and host contract tests wired into CI.

REQUIREMENTS:
- Unit tests for every tool handler: happy paths, validation rejections, error conversion
- Protocol tests: initialization, tool listing, invocation, and error responses over the transport
- Contract tests pinning the tool surface (names, schemas, descriptions) against golden files
- Regression cases for every bug found in host integration
- The suite running in CI on every change

CONSTRAINTS:
- Handlers must be testable without the transport - separate logic from protocol glue
- Golden-file changes require an explicit, reviewed update - surface drift is a decision

DEFINITION OF DONE:
- Every handler has happy, invalid-input, and internal-error tests
- Protocol tests pass against the running server, not mocks alone
- A deliberate schema change fails the contract test until goldens are updated
- CI blocks merges on any suite failure

COMMON FAILURES TO AVOID:
- Testing handlers only, missing serialization and protocol bugs entirely
- No contract pinning, so tool renames silently break every downstream host
- Bugs fixed without regression tests, returning two releases later
- A suite that exists but does not run automatically

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More MCP & Tooling flows that share ground with this one.

Flows category icon
MCP & Tooling

Build Your First MCP Server

Stand up a working MCP server exposing your own tools, connect a client, and validate the full call loop.

01Choose tools worth exposing and set up the SDK
02Implement the server and tools
03Connect a host and verify discovery

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps90-120 minutesIntermediate
Flows category icon
MCP & Tooling

Deferred Tool Loading

Stop paying context for tools the task never needs: load a core set eagerly and expand the toolset on demand.

01Measure usage and pick the core
02Build the catalog and discovery
03Implement dynamic registration

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-120 minutesAdvanced
Flows category icon
MCP & Tooling

Tool Descriptions That Steer the Model

Treat tool descriptions as prompt engineering: when-to-use guidance, negative cases, and worked examples that fix tool-choice errors.

01Collect misroutes and map overlaps
02Rewrite descriptions to steer
03Verify with a routing test

Best foryour first pass at this - no prior setup assumed

3 steps45-60 minutesBeginner

Made with Emergent