.mjs file that describes how to interact with a REST API — what endpoints exist, what parameters they accept, and how responses should be transformed.
Prerequisites
Before creating a schema, you need:- The API documentation for the service you want to wrap
- An API key if the service requires authentication
- Node.js 18+ installed
- FlowMCP CLI installed (
npm install -g flowmcp-cli)
Creation Process
Choose namespace and identify endpoints
Pick a unique namespace for your schema and list the API endpoints you want to expose.The namespace becomes part of the tool name:
namespace_routeName. Keep it short and recognizable (e.g., coingecko, etherscan, defillama).Add output schemas
Each route can declare its response structure in the
output field. This tells AI clients what to expect:Add handlers (optional)
If the raw API response needs transformation, add a Handlers support two hooks per route:
handlers export. This is a factory function that receives shared lists and libraries:preRequest— modify the request before it is sentpostRequest— transform the response before it reaches the AI client
Validate with CLI
Run the schema through the validation pipeline:The validator checks 79 rules covering structure, security, and correctness.
Parameter Patterns
Parameters define how user input and server credentials map to API requests. Each parameter has aposition that controls where it goes:
Query Parameters
Appended to the URL as?key=value:
Path Parameters (insert)
Substituted into the URL path:Body Parameters
Sent in the request body for POST/PUT requests:Server Parameters
Injected from environment variables. Never exposed to the AI client:The
{{SERVER_PARAM:KEY_NAME}} syntax references a key declared in requiredServerParams. The runtime injects the value from the environment at execution time.Zod Validation
Each parameter includes az field that defines validation rules:
Shared List References
Schemas can reference shared lists for reusable value enumerations like chain IDs or token symbols:{{evmChains:etherscanAlias}} syntax interpolates the etherscanAlias field from all entries in the evmChains shared list that pass the filter. This generates an enum like enum(["ETH","POLYGON","ARBITRUM","OPTIMISM","BASE","BSC"]).
Handler Patterns
Response Filtering
Reduce large API responses to the fields the AI client needs:Pre-Request Modification
Modify request parameters before the API call:Best Practices
One concern per schema
Group related endpoints into a single schema. A schema for “Etherscan Gas Tracker” should contain gas-related routes, not all Etherscan endpoints.
Descriptive route names
Use verb-noun format:
getBalance, listProtocols, executeQuery. The route name becomes part of the MCP tool name.Include output schemas
Always define
output.schema for each route. This helps AI clients understand what data they will receive and select the right tool.Test with real data
Use
flowmcp test single to verify against the real API. Schema validation alone cannot catch API-side issues.