Prerequisites:
- A FrontMCP project with at least one tool (see Your First Tool)
- Basic familiarity with Jest
What You’ll Build
A complete E2E test suite that:- Starts your MCP server automatically
- Tests tool execution with various inputs
- Validates error handling
- Tests resources and prompts
Step 1: Install the Testing Library
Step 2: Configure Testing
Thefrontmcp test command auto-generates the correct Jest/SWC config. No manual jest.e2e.config.ts needed.
Add a script to your package.json:
package.json
Step 3: Write Your First Test
Create a test file in thee2e/ directory using the .e2e.spec.ts extension (not .e2e.ts). The frontmcp test command discovers tests matching e2e/**/*.e2e.spec.ts:
e2e/server.e2e.spec.ts
- Starts your FrontMCP server
- Connects an MCP client
- Runs your test
- Cleans up after completion
Step 4: Test Tool Execution
Testing Successful Execution
Testing Multiple Scenarios
Testing Error Cases
Step 5: Test Tool Discovery
Verify your tools are properly registered:Step 6: Test Resources
If your app has resources:Step 7: Test Prompts
If your app has prompts:Step 8: Organize Your Tests
Recommended file structure:test.describe() to group related tests:
e2e/calculator.e2e.spec.ts
Complete Example
Here’s a complete test file:e2e/server.e2e.spec.ts
Best Practices
Use descriptive test names
Use descriptive test names
Test both success and error cases
Test both success and error cases
Always test:
- Happy path (valid inputs)
- Edge cases (zero, negative, empty)
- Error cases (invalid inputs, missing params)
Use custom matchers
Use custom matchers
Use port: 0 in CI
Use port: 0 in CI
Auto-select ports to avoid conflicts:
Next Steps
Test Fixtures
Learn about all available test fixtures
Custom Matchers
Full reference for MCP-specific matchers
Auth Testing
Test authentication and authorization
HTTP Mocking
Mock external API calls