How prefecthq/fastmcp-ts works
fastmcp-ts is a TypeScript framework for building MCP servers, clients, and interactive server-side apps, with a CLI for running and exploring servers. The principal workflow is to define tools, resources, and prompts, serve them over MCP, and let a host or FastMCP client discover and invoke them. Server context, middleware, and authentication support request handling; separate branches cover OpenAPI-backed servers, remote-server composition, UI apps, and client-side sampling. The README documents these capabilities; unsampled modules are represented by their exact tree paths, with only documented relationships shown.
Main entry points: FastMCP.ts Server runtime · FastMCPApp.ts FastMCP app · client.ts Client API · tool.ts Tool handlers
Components 24
MCP server
- FastMCP API
src/server/FastMCP.ts - Server runtime
src/server/FastMCP.ts - Tool handlers
src/server/tool.ts - Resources
src/server/resource.ts - Prompts
src/server/prompt.ts - Request context
src/server/context.ts - Middleware
src/server/middleware.ts - Auth providers
src/server/auth
MCP client
- Client API
src/client/client.ts - Client transports
src/client/transports.ts - Multi-server client
src/client/multi-server.ts - Sampling adapters
src/client/sampling
Interactive apps
- FastMCP app
src/server/apps/FastMCPApp.ts - UI components
src/server/apps/components.ts - UI providers
src/server/apps/providers - Generative UI
src/server/apps/generative.ts
Server integrations
- OpenAPI server
src/server/openapi - Server proxy
src/server/proxy.ts
Command line
- FastMCP CLI
src/cli/index.ts - CLI commands
src/cli/commands
Other components
- Server developer
- MCP host
- MCP SDK
- LLM provider
Connections 31
- Server developer → FastMCP API: defines capabilities
- FastMCP API → Tool handlers: registers tools
- FastMCP API → Resources: registers resources
- FastMCP API → Prompts: registers prompts
- FastMCP API → Server runtime: starts runtime
- Server runtime → MCP SDK: serves MCP
- MCP host → Server runtime: sends requests
- Server runtime → Tool handlers: dispatches calls
- Server runtime → Resources: dispatches reads
- Server runtime → Prompts: dispatches requests
- Server runtime → Middleware: applies middleware
- Server runtime → Auth providers: verifies access
- Tool handlers → Request context: uses context
- Server developer → Client API: connects client
- Client API → Client transports: resolves transport
- Client transports → Server runtime: exchanges MCP
- Client API → Sampling adapters: handles sampling
- Sampling adapters → LLM provider: requests completion
- Client API → Multi-server client: supports multi-server
- Server developer → FastMCP app: defines app
- FastMCP app → UI components: renders component tree
- FastMCP app → UI providers: mounts providers
- FastMCP app → Generative UI: enables composition
- FastMCP app → FastMCP API: uses server
- Server developer → OpenAPI server: creates API server
- OpenAPI server → FastMCP API: registers MCP routes
- Server developer → Server proxy: creates proxy
- Server proxy → FastMCP API: mounts remote server
- Server developer → FastMCP CLI: runs commands
- FastMCP CLI → CLI commands: dispatches commands
- CLI commands → Server runtime: runs or inspects