Zum Inhalt springen

Output Schema

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Output schemas make tool responses predictable. AI clients can know in advance what shape the data will have, enabling structured reasoning without parsing guesswork.

Without output schemas, an AI client calling a FlowMCP tool receives an opaque blob of JSON. Output schemas solve this by declaring the expected response shape at the route level:

  • AI clients can pre-allocate structured reasoning about response fields
  • Schema validators can verify handler output matches the declaration
  • Documentation generators can produce accurate response tables automatically

Each route can optionally define an output field:

routes: {
getTokenPrice: {
method: 'GET',
path: '/simple/price',
description: 'Get current token price',
parameters: [ /* ... */ ],
output: {
mimeType: 'application/json',
schema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Token identifier' },
symbol: { type: 'string', description: 'Token symbol' },
price: { type: 'number', description: 'Current price in USD' },
marketCap: { type: 'number', description: 'Market capitalization', nullable: true },
volume24h: { type: 'number', description: 'Trading volume (24h)' }
}
}
}
}
}
FieldTypeRequiredDescription
mimeTypestringYesResponse content type
schemaobjectYesSimplified JSON Schema describing the data field
MIME TypeDescriptionSchema type
application/jsonJSON response (default)object or array
image/pngPNG image, base64-encodedstring with format: 'base64'
text/plainPlain text responsestring

Every FlowMCP tool response is wrapped in a standard envelope:

// Success Response
{
status: true,
messages: [],
data: { /* described by output.schema */ }
}
// Error Response
{
status: false,
messages: [ 'E001 getTokenPrice: API returned 404' ],
data: null
}
FieldTypeDescription
statusbooleantrue on success, false on error
messagesarrayEmpty on success, error descriptions on failure
dataobject or nullResponse payload on success, null on error

FlowMCP uses a deliberately constrained subset of JSON Schema:

KeywordDescriptionExample
typeValue type'string', 'number', 'boolean', 'object', 'array'
propertiesObject properties{ name: { type: 'string' } }
itemsArray item schema{ type: 'object', properties: {...} }
descriptionHuman-readable description'Current price in USD'
nullableCan be nulltrue
enumAllowed values['active', 'inactive']
formatSpecial format hint'base64', 'date-time', 'uri'
  • $ref — no schema references; output schemas are self-contained
  • oneOf, anyOf, allOf — no union types
  • required — all declared properties are informational
  • additionalProperties — APIs may return extra fields
  • pattern, minimum, maximum — no regex or range validation on output
output: {
mimeType: 'application/json',
schema: {
type: 'object',
properties: {
id: { type: 'string', description: 'Token identifier' },
price: { type: 'number', description: 'Current price in USD' },
marketCap: { type: 'number', description: 'Market cap', nullable: true }
}
}
}
output: {
mimeType: 'application/json',
schema: {
type: 'array',
items: {
type: 'object',
properties: {
name: { type: 'string', description: 'Protocol name' },
tvl: { type: 'number', description: 'Total value locked in USD' }
}
}
}
}
output: {
mimeType: 'image/png',
schema: {
type: 'string',
format: 'base64',
description: 'Chart image as base64-encoded PNG'
}
}

Fields that may be null in a successful response must declare nullable: true:

properties: {
marketCap: { type: 'number', description: 'Market cap', nullable: true },
website: { type: 'string', description: 'Project URL', nullable: true }
}

Output schema validation is non-blocking. A mismatch produces a validation warning, not an error. The response is still delivered.

flowchart TD
A[Handler returns data] --> B{Schema declared?}
B -->|No| C[Pass through]
B -->|Yes| D{Data matches schema?}
D -->|Yes| E[Return data]
D -->|No| F[Log warning]
F --> G[Return data anyway]