Skip to content
Back to search

fastmcp-ts

The official FastMCP TypeScript library for building MCP servers, clients, and apps 🏎️ 🏎️ 🏎️

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today

Check it deeper on your machine

It has changed since its scan on 11 Nov 2026.

As a Claude Code plugin, install it and then ask Claude Code:

/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/PrefectHQ/fastmcp-ts with scanskillsafety

Or from a terminal, clone it and run it:

git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/PrefectHQ/fastmcp-ts'

It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.

Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/prefecthq--fastmcp-ts/badge.svg)](/listings/prefecthq--fastmcp-ts)

HTML

<a href="/listings/prefecthq--fastmcp-ts"><img src="/api/listings/prefecthq--fastmcp-ts/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

npm install @prefecthq/fastmcp-ts

---

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 326 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # fastmcp-ts
  2. The TypeScript framework for building [Model Context Protocol](https://modelcontextprotocol.io) servers, clients, and apps. The official TypeScript counterpart to [FastMCP for Python](https://github.com/PrefectHQ/fastmcp) - built and maintained with 💙 by the same team at [Prefect](https://prefect.io).
  3. Built on version 2 of the official [MCP TypeScript SDK](https://github.com/modelcontextprotocol/typescript-sdk) — the scoped `@modelcontextprotocol/server` and `@modelcontextprotocol/client` packages. FastMCP handles the protocol plumbing so you can focus on what your server actually does.
  4. FastMCP 1.0 speaks both MCP protocol generations: the 2025 legacy era and the 2026-07-28 modern era. A server serves both at once, and a client negotiates one. The client negotiates automatically by default: it probes once at connect, uses the modern era when the server offers it, and falls back to legacy otherwise, so upgrading from 0.x keeps your existing code running against servers of either generation. Pass `versionNegotiation: { mode: 'legacy' }` to opt out of the probe. The [migration guide](docs/migration.mdx) covers the upgrade path.
  5. ## Installation
  6. ```bash
  7. npm install @prefecthq/fastmcp-ts
  8. ```
  9. ---
  10. ## Servers
  11. Turn TypeScript functions into MCP tools, resources, and prompts. Input schemas are inferred automatically from any [Standard Schema](https://standardschema.dev)-compatible library: Zod, Valibot, ArkType, and others.
  12. ```typescript
  13. import { FastMCP } from '@prefecthq/fastmcp-ts/server'
  14. import { z } from 'zod'
  15. const server = new FastMCP({ name: 'my-server', version: '1.0.0' })
  16. server.tool(
  17. {
  18. name: 'add',
  19. description: 'Add two numbers',
  20. input: z.object({ a: z.number(), b: z.number() }),
  21. },
  22. ({ a, b }) => a + b
  23. )
  24. server.resource(
  25. { uri: 'config://settings', description: 'App configuration' },
  26. () => JSON.stringify({ theme: 'dark', lang: 'en' })
  27. )
  28. server.resource(
  29. { uri: 'user://{id}', description: 'User by ID' },
  30. ({ id }) => `User #${id}`
  31. )
  32. server.prompt(
  33. {
  34. name: 'review_code',
  35. description: 'Review code for quality and correctness',
  36. arguments: [
  37. { name: 'code', required: true },
  38. { name: 'language', required: false },
  39. ],
  40. },
  41. ({ code, language }) =>
  42. `Review this ${language ?? 'code'} for quality and correctness:\n\n${code}`
  43. )
  44. await server.run() // stdio (default)
  45. // await server.run({ transport: 'http', port: 3000 })
  46. ```
  47. Save this file as `server.ts`. Installing `@prefecthq/fastmcp-ts` also installs the `fastmcp` CLI. Use it to inspect the server and call a tool, with no build step:
  48. ```bash
  49. npx fastmcp inspect --file server.ts
  50. npx fastmcp call add --file server.ts a=1 b=2
  51. ```
  52. ### Context
  53. Handlers access logging, progress, LLM sampling, user elicitation, and per-session state through an ambient context with no prop-drilling.
  54. ```typescript
  55. import { FastMCP } from '@prefecthq/fastmcp-ts/server'
  56. import { z } from 'zod'
  57. const server = new FastMCP({ name: 'assistant' })
  58. server.tool(
  59. {
  60. name: 'summarize',
  61. description: 'Summarize a document',
  62. input: z.object({ text: z.string() }),
  63. },
  64. async ({ text }) => {
  65. const ctx = server.getContext()
  66. await ctx.info('Sending document to LLM')
  67. await ctx.reportProgress(0, 1, 'Sampling…')
  68. const { content } = await ctx.sample({
  69. messages: [{ role: 'user', content: { type: 'text', text: `Summarize:\n${text}` } }],
  70. maxTokens: 512,
  71. })
  72. return content.type === 'text' ? content.text : ''
  73. }
  74. )
  75. ```
  76. ### Middleware & Auth
  77. ```typescript
  78. import { FastMCP, LoggingMiddleware, RateLimitingMiddleware, jwtVerifier } from '@prefecthq/fastmcp-ts/server'
  79. const server = new FastMCP({
  80. name: 'secure-server',
  81. auth: jwtVerifier({
  82. jwksUri: 'https://auth.example.com/.well-known/jwks.json',
  83. issuer: 'https://auth.example.com',
  84. audience: 'my-mcp-server',
  85. }),
  86. })
  87. server.use(new LoggingMiddleware())
  88. server.use(new RateLimitingMiddleware(100, 60_000)) // 100 requests per minute
  89. await server.run({ transport: 'http', port: 3000 })
  90. ```
  91. ### Composition
  92. Mount child servers onto a parent with optional name-prefix namespacing.
  93. ```typescript
  94. import { FastMCP, createProxy } from '@prefecthq/fastmcp-ts/server'
  95. const weather = new FastMCP({ name: 'weather' })
  96. weather.tool({ name: 'forecast', description: 'Get a forecast', input: z.object({ city: z.string() }) }, ({ city }) => `Forecast for ${city}`)
  97. // Wrap a remote server as a mountable instance
  98. const maps = await createProxy({ type: 'http', url: 'http://maps-service/mcp' })
  99. const gateway = new FastMCP({ name: 'gateway' })
  100. gateway.mount(weather, 'weather') // → weather_forecast
  101. gateway.mount(maps, 'maps') // → maps_<tool_name>
  102. await gateway.run({ transport: 'http', port: 3000 })
  103. ```
  104. ---
  105. ## Clients
  106. ```typescript
  107. import { Client } from '@prefecthq/fastmcp-ts/client'
  108. const client = await Client.connect('http://localhost:3000')
  109. const tools = await client.listTools()
  110. const resources = await client.listResources()
  111. const prompts = await client.listPrompts()
  112. const result = await client.callTool('add', { a: 1, b: 2 })
  113. const config = await client.readResource('config://settings')
  114. const review = await client.getPrompt('review_code', { code: 'const x = 1' })
  115. await client.close()
  116. ```
  117. Use `await using` for automatic cleanup:
  118. ```typescript
  119. await using client = await Client.connect('http://localhost:3000')
  120. const result = await client.callTool('add', { a: 1, b: 2 })
  121. // client closed automatically on scope exit
  122. ```
  123. ### Sampling Adapters
  124. Forward LLM sampling requests from servers to your AI provider with a single line:
  125. ```typescript
  126. import { Client, AnthropicSamplingAdapter } from '@prefecthq/fastmcp-ts/client'
  127. import Anthropic from '@anthropic-ai/sdk'
  128. const client = await Client.connect('http://localhost:3000', {
  129. handlers: {
  130. sampling: new AnthropicSamplingAdapter(new Anthropic()).asHandler(),
  131. },
  132. })
  133. ```
  134. Also ships with `OpenAISamplingAdapter` and `GoogleSamplingAdapter`.
  135. ### Multi-Server
  136. Connect to multiple servers from a single client. Tools, resources, and prompts are namespaced by server name automatically.
  137. ```typescript
  138. import { Client } from '@prefecthq/fastmcp-ts/client'
  139. const client = await Client.connect({
  140. mcpServers: {
  141. weather: { url: 'http://localhost:3001' },
  142. maps: { url: 'http://localhost:3002' },
  143. },
  144. })
  145. // tool names become weather_forecast, maps_geocode, …
  146. const forecast = await client.callTool('weather_forecast', { city: 'New York' })
  147. ```
  148. ---
  149. ## Apps
  150. FastMCP ships a server-side component library for building interactive UIs rendered directly in MCP host conversations.
  151. ```typescript
  152. import { FastMCPApp, Column, Row, Text, Input, Button, Table } from '@prefecthq/fastmcp-ts/server'
  153. const app = new FastMCPApp({ name: 'search-app', version: '1.0.0' })
  154. // Entry-point tool: visible to the LLM, auto-linked to a ui:// resource
  155. app.entrypoint(
  156. { name: 'search', description: 'Search the product catalog' },
  157. () =>
  158. Column({}, [
  159. Text('Product Search'),
  160. Row({}, [
  161. Input({ name: 'query', placeholder: 'Search products…' }),
  162. Button({ label: 'Search', action: app.toolRef('run_search') }),
  163. ]),
  164. ])
  165. )
  166. // Backend tool: hidden from the LLM, callable only from within the rendered UI
  167. app.backendTool(
  168. { name: 'run_search', description: 'Execute the search query' },
  169. async ({ query }: { query: string }) => {
  170. const rows = await db.search(query)
  171. return Table({ columns: ['Name', 'Price', 'Stock'], rows })
  172. }
  173. )
  174. await app.server.run({ transport: 'http', port: 3000 })
  175. ```
  176. ### Built-in Providers
  177. Ready-to-mount interactive primitives:
  178. ```typescript
  179. import { FastMCP, Approval, Choice, FileUpload, FormInput } from '@prefecthq/fastmcp-ts/server'
  180. import { z } from 'zod'
  181. const server = new FastMCP({ name: 'my-server' })
  182. server.addProvider(new Approval()) // confirm/deny card injected back into the conversation
  183. server.addProvider(new Choice()) // clickable option list
  184. server.addProvider(new FileUpload()) // drag-and-drop file picker; file bytes never pass through the LLM
  185. // Auto-generated, validated form from any Standard Schema
  186. server.addProvider(
  187. new FormInput({
  188. name: 'contact_form',
  189. description: 'Contact form',
  190. schema: z.object({ name: z.string(), email: z.string() }),
  191. }),
  192. )
  193. ```
  194. ### Generative UI
  195. Let the LLM compose component trees at runtime:
  196. ```typescript
  197. import { FastMCP, GenerativeUI } from '@prefecthq/fastmcp-ts/server'
  198. const server = new FastMCP({ name: 'my-server' })
  199. server.addProvider(new GenerativeUI())
  200. // registers generate_ui and search_components tools
  201. await server.run()
  202. ```
  203. ---
  204. ## CLI
  205. ```bash
  206. # Start a server
  207. fastmcp run server.ts
  208. fastmcp run server.ts --transport http --port 3000
  209. # Inspect a server's tools, resources, and prompts
  210. fastmcp inspect --file server.ts
  211. fastmcp inspect --url http://localhost:3000
  212. fastmcp inspect --file server.ts --json
  213. fastmcp inspect --file server.ts --legacy # force the legacy 2025 era, no probe
  214. fastmcp inspect --file server.ts --pin 2026-07-28 # require that exact era
  215. # Call a tool, read a resource, or get a prompt
  216. fastmcp call add --file server.ts a=1 b=2
  217. fastmcp call config://settings --url http://localhost:3000
  218. # Connect to a running server and list its components
  219. fastmcp list --url http://localhost:3000
  220. fastmcp list --url http://localhost:3000 --resources --prompts --json
  221. # Open the MCP Inspector UI with file-watch reload
  222. fastmcp dev inspector server.ts
  223. # Install into editor/client configs
  224. fastmcp install claude-code server.ts
  225. fastmcp install cursor server.ts
  226. fastmcp install claude-desktop server.ts
  227. # Find locally configured MCP servers
  228. fastmcp discover
  229. ```
  230. `fastmcp inspect`, `fastmcp list`, and `fastmcp call` negotiate the protocol era automatically on every transport: one probe at connect, the modern 2026-07-28 era when the server offers it, and the legacy 2025 era otherwise. Add `--legacy` to skip the probe and force the legacy era. `--pin <version>` works on every transport, including HTTP. It forces that exact protocol revision. The connection fails if the server does not offer it. `--modern` is a deprecated no-op, kept for compatibility.
  231. ---
  232. ## Ecosystem
  233. | Package | Role |
  234. |---|---|
  235. | [`@modelcontextprotocol/server`](https://www.npmjs.com/package/@modelcontextprotocol/server) | Official MCP TypeScript SDK v2 — the server-side protocol implementation FastMCP builds on |
  236. | [`@modelcontextprotocol/client`](https://www.npmjs.com/package/@modelcontextprotocol/client) | Official MCP TypeScript SDK v2 — the client-side protocol implementation FastMCP builds on |
  237. | [`fastmcp` (PyPI)](https://github.com/PrefectHQ/fastmcp) | The Python original this project models its API after |
  238. | [`@modelcontextprotocol/ext-apps`](https://github.com/modelcontextprotocol/ext-apps) | Official MCP Apps extension — foundation for the Apps pillar |

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.