use-mcp/test
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Glen Maddern fe65d50ec3
Fixing /sse support (#12)
* /sse still not working

* Add transport type selector to inspector UI and comprehensive transport testing

- Add transport type dropdown to inspector UI (auto, HTTP, SSE) with session storage persistence
- Update test framework to support transport type selection in test scenarios
- Add comprehensive test cases covering:
  * Working /mcp endpoints with auto and HTTP transports
  * SSE endpoint with SSE transport (expected to pass)
  * SSE endpoint with auto transport (expected to fail - demonstrates current fallback issue)
- Test structure now provides clear visibility into transport-specific behavior
- All tests properly named and categorized for easy identification of failing scenarios

* Gearing up to "make amp do it"

* fix: improve SSE fallback logic in auto transport mode

- Fix issue where SSE fallback was not attempted when HTTP transport failed
- Specific error types (404, 405, CORS) now correctly trigger SSE fallback
- Allow SSE fallback even when component state is 'failed' from previous attempts
- Maintain proper error handling for non-fallback HTTP errors
- All 6 transport scenarios now pass integration tests

The core issue was that failConnection() was being called for HTTP errors
before returning 'fallback', which set the component state to 'failed' and
prevented the orchestration logic from attempting SSE fallback. Now only
specific HTTP errors that should trigger fallback avoid calling failConnection
immediately, allowing the SSE transport to be attempted as expected.

---------

Co-authored-by: Glen Maddern <glen@glenmaddern.com>
2025-07-01 12:14:32 +10:00
..
integration Fixing /sse support (#12) 2025-07-01 12:14:32 +10:00
setup Fixing /sse support (#12) 2025-07-01 12:14:32 +10:00
package.json Merge pull request #10 from modelcontextprotocol/e2e-testing 2025-06-30 21:07:45 +10:00
pnpm-lock.yaml Merge pull request #10 from modelcontextprotocol/e2e-testing 2025-06-30 21:07:45 +10:00
README.md Merge pull request #10 from modelcontextprotocol/e2e-testing 2025-06-30 21:07:45 +10:00
tsconfig.json Merge pull request #10 from modelcontextprotocol/e2e-testing 2025-06-30 21:07:45 +10:00
vitest.config.ts Merge pull request #10 from modelcontextprotocol/e2e-testing 2025-06-30 21:07:45 +10:00

Integration Test Suite

This directory contains integration tests for the use-mcp project that test the complete flow:

  1. Building the use-mcp library
  2. Building the inspector example
  3. Starting MCP server(s)
  4. Testing browser connections to MCP servers

Setup

Install test dependencies:

cd test
pnpm install

Running Tests

Run all integration tests (shows browser window):

cd test
pnpm test

Run tests headlessly (no browser window):

cd test
pnpm test:headless

Run tests in watch mode (re-runs on file changes):

cd test
pnpm test:watch

Run tests with interactive UI:

cd test  
pnpm test:ui

Debug hanging processes:

cd test
pnpm test:debug

Test Architecture

  • Global Setup (setup/global-setup.ts):

    • Builds use-mcp library and inspector
    • Starts hono-mcp server on port 9901
    • Starts static file server for inspector dist files
  • Global Teardown (setup/global-teardown.ts):

    • Stops all servers and cleans up resources
  • Integration Tests (integration/mcp-connection.test.ts):

    • Uses Playwright to automate browser interactions
    • Tests connection to MCP servers defined in MCP_SERVERS array
    • Verifies successful connections and tool availability
    • Logs debug information on failures

Adding New MCP Servers

To test additional MCP servers, add them to the MCP_SERVERS array in the test file:

const MCP_SERVERS = [
  {
    name: 'hono-mcp',
    url: 'http://localhost:9901/mcp',
    expectedTools: 1,
  },
  {
    name: 'new-server',
    url: 'http://localhost:9902/mcp',
    expectedTools: 2,
  },
]

Make sure to also update the global setup to start the new server process.

Test Output

Successful connections will log:

  • ✅ Connection success message
  • 📋 List of available tools with count

Failed connections will log:

  • ❌ Failure message
  • 🐛 Debug log from the inspector interface

Troubleshooting

If tests fail:

  1. Check that all required dependencies are installed
  2. Verify that ports 9901 and 8000+ are available
  3. Look at the debug log output for MCP connection errors
  4. Check browser console logs for JavaScript errors
  5. Run tests with --headed flag to see browser interactions