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 Jest
Create a Jest configuration file for E2E tests:jest.e2e.config.ts
package.json:
package.json
Step 3: Write Your First Test
Create a test file next to your server entry point:src/main.e2e.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:
calculator.e2e.ts
Complete Example
Here’s a complete test file:src/main.e2e.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