kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
85 wiersze
2.3 KiB
Markdown
85 wiersze
2.3 KiB
Markdown
---
|
|
title: TypeScript FastMCP
|
|
description: This guide shows how to publish an MCP server to Agentic using the TypeScript FastMCP package.
|
|
---
|
|
|
|
[FastMCP](https://github.com/punkpeye/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
|
|
npm add fastmcp zod
|
|
```
|
|
|
|
```bash pnpm
|
|
pnpm add fastmcp zod
|
|
```
|
|
|
|
```bash bun
|
|
bun add fastmcp zod
|
|
```
|
|
|
|
```bash yarn
|
|
yarn add fastmcp zod
|
|
```
|
|
|
|
</CodeGroup>
|
|
|
|
## 2. Create a FastMCP server
|
|
|
|
```ts 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](https://ngrok.com) 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](https://workers.cloudflare.com), [Vercel](https://vercel.com/guides/hosting-backend-apis) (for instance, using the [Hono](https://vercel.com/templates/hono/hono-on-vercel) API template), [Render](https://render.com/docs/deploy-fastapi), [Porter](https://docs.porter.run/guides/nodejs/deploy-nodejs), or [Fly.io](https://fly.io/docs/python/frameworks/fastapi/). Or one of the big boys [AWS](https://aws.amazon.com), [GCP](https://cloud.google.com), or [Azure](https://azure.microsoft.com).
|
|
|
|
## 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](/publishing/guides/existing-mcp-server) to deploy it to Agentic.
|