Back to Agentic

TypeScript FastMCP

docs/publishing/guides/ts-fastmcp.mdx

8.4.42.1 KB
Original Source

FastMCP is a popular open source TypeScript framework for building MCP servers.

1. Install dependencies

<Info> **Prerequisite**: Please install [Node.js](https://nodejs.org) before proceeding. </Info> <CodeGroup>
bash
npm add fastmcp zod
bash
pnpm add fastmcp zod
bash
bun add fastmcp zod
bash
yarn add fastmcp zod
</CodeGroup>

2. Create a FastMCP server

ts
import { FastMCP } from 'fastmcp'
import { z } from 'zod' // Or any validation library that supports Standard Schema

const server = new FastMCP({
  name: 'Example',
  version: '0.0.1'
})

server.addTool({
  name: 'add',
  description: 'Add two numbers',
  parameters: z.object({
    a: z.number(),
    b: z.number()
  }),
  execute: async (args) => {
    return String(args.a + args.b)
  }
})

server.start({
  transportType: 'httpStream',
  httpStream: {
    port: 8080
  }
})
<Note> Make sure to run your server with the `transportType: 'httpStream'` option to use the Streamable HTTP transport. </Note>

3. Deploy your MCP server remotely

Deploy your server publicly or use a tool like ngrok to expose it to the internet.

<Warning> Tools like `ngrok` expose your unauthenticated server to the internet. Only run this command in a safe environment if you understand the risks. </Warning>

We recommend deploying your server to a cloud provider like Cloudflare Workers, Vercel (for instance, using the Hono API template), Render, Porter, or Fly.io. Or one of the big boys AWS, GCP, or Azure.

4. Deploy your origin MCP server to Agentic

Now that you have a publicly available MCP server, you can follow the existing MCP server guide to deploy it to Agentic.