Skip to main content
Glama

Blockscout MCP Server

Official
230-api-route-tests.mdc1.52 kB
--- description: Guidelines for writing unit tests for REST API routes globs: tests/api/test_routes.py alwaysApply: false --- # REST API Route Test Guidelines When adding or modifying tests for the REST API in `tests/api/test_routes.py`, follow these practices: - Create a `FastMCP` instance and register routes using `register_api_routes` before making requests. - Use `httpx.AsyncClient` with `ASGITransport` to call the routes. - Patch the wrapped tool functions with `unittest.mock.patch` and `AsyncMock` to avoid real network calls. - Assert that each endpoint returns the expected HTTP status and JSON content. - Verify that the patched tool was invoked exactly once with the expected arguments. - Include error-case tests to confirm a `400` response is returned when required query parameters are missing. - Test the static endpoints (e.g. `/health`, `/`, `/llms.txt`) to ensure they return the correct status code and content type after `register_api_routes` is called. A separate test should confirm these routes are unavailable on a clean `FastMCP` instance before registration. - For each tool-based endpoint create **three** tests: 1. Success path with only the required parameters. 2. Success path including optional parameters, if any. 3. Failure path when a required parameter is missing, expecting HTTP `400`. ## Naming Convention Name the test functions after the endpoint without the `_rest` suffix. For example, prefer `test_get_chains_list_success` over `test_get_chains_list_rest_success`.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/blockscout/mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server