@mcphero/fastify
v1.3.0
Published
MCP Hero Fastify REST Adapter
Readme
@mcphero/fastify
Fastify REST adapter for MCPHero — expose your actions as a REST API with auto-generated OpenAPI/Swagger documentation.
Install
pnpm add @mcphero/core @mcphero/fastifyUsage
import { mcphero } from '@mcphero/core'
import { fastify } from '@mcphero/fastify'
import { SearchAction } from './actions/search.js'
await mcphero({ name: 'my-api', description: 'My REST API', version: '1.0.0' })
.adapter(fastify({ host: 'localhost', port: 8080, logger: true }))
.action(SearchAction)
.start()Visit http://localhost:8080/ for the interactive Scalar API reference.
Route Mapping
Each action becomes a POST /{action.name} route. Zod schemas are converted to JSON Schema for request body validation and OpenAPI documentation.
| Action | Route | Body |
|--------|-------|------|
| name: 'search' | POST /search | { "query": "...", "limit": 10 } |
| name: 'greet' | POST /greet | { "name": "World" } |
Options
FastifyAdapterOptions extends Fastify's native FastifyHttpOptions, so any Fastify config is supported:
fastify({
host: 'localhost',
port: 8080,
logger: {
level: 'debug',
transport: { target: 'pino-pretty' }
},
connectionTimeout: 30000
})| Option | Type | Default | Description |
|--------|------|---------|-------------|
| host | string | undefined | Bind address |
| port | number | undefined | Listen port |
| ... | | | Any FastifyHttpOptions |
See Also
- MCPHero README — Full documentation
@mcphero/core— Core library
