kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
09f623ad4e
commit
ced0c8b7d3
|
@ -3,4 +3,54 @@ title: Python FastMCP
|
|||
description: This guide shows how to publish an MCP server to Agentic using the Python fastmcp package.
|
||||
---
|
||||
|
||||
**TODO**
|
||||
[Python's FastMCP](https://gofastmcp.com) is a popular [open source](https://github.com/jlowin/fastmcp) MCP server framework for Python.
|
||||
|
||||
## 1. Install the `fastmcp` package
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash uv
|
||||
uv add fastmcp
|
||||
```
|
||||
|
||||
```bash pip
|
||||
pip install fastmcp
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## 2. Create a FastMCP server
|
||||
|
||||
```py server.py
|
||||
from fastmcp import FastMCP
|
||||
|
||||
mcp = FastMCP("Demo 🚀")
|
||||
|
||||
@mcp.tool
|
||||
def add(a: int, b: int) -> int:
|
||||
"""Add two numbers"""
|
||||
return a + b
|
||||
|
||||
if __name__ == "__main__":
|
||||
mcp.run(transport="http", host="127.0.0.1", port=8000, path="/mcp")
|
||||
```
|
||||
|
||||
<Note>
|
||||
Make sure to run your server with the `transport="http"` option to use the
|
||||
Streamable HTTP transport.
|
||||
</Note>
|
||||
|
||||
## 3. Deploy your server
|
||||
|
||||
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 [render](https://render.com/docs/deploy-fastapi), [platform.sh](https://docs.platform.sh/languages/python.html), [porter](https://docs.porter.run/guides/fastapi/deploy-fastapi), 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.
|
||||
|
|
|
@ -3,4 +3,77 @@ title: TS FastMCP
|
|||
description: This guide shows how to publish an MCP server to Agentic using the TypeScript fastmcp package.
|
||||
---
|
||||
|
||||
**TODO**
|
||||
[FastMCP](https://github.com/punkpeye/fastmcp) is a popular open source MCP server framework for TypeScript.
|
||||
|
||||
## 1. Install dependencies
|
||||
|
||||
<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 server
|
||||
|
||||
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), [render](https://render.com/docs/deploy-fastapi) (for instance, using the [hono](https://vercel.com/templates/hono/hono-on-vercel) API template), [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.
|
||||
|
|
|
@ -3,4 +3,95 @@ title: TS MCP Hono
|
|||
description: This guide shows how to publish an MCP server to Agentic using TypeScript and Hono's MCP support.
|
||||
---
|
||||
|
||||
**TODO**
|
||||
[Hono](https://hono.dev) is a popular open source framework for building HTTP servers, and `@hono/mcp`](https://github.com/honojs/middleware/tree/main/packages/mcp) is a Hono middleware for MCP servers.
|
||||
|
||||
## 1. Install dependencies
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash npm
|
||||
npm add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
|
||||
```
|
||||
|
||||
```bash pnpm
|
||||
pnpm add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
|
||||
```
|
||||
|
||||
```bash bun
|
||||
bun add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn add hono @hono/node-server @hono/mcp @modelcontextprotocol/sdk zod
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## 2. Create a Hono MCP Node.js server
|
||||
|
||||
```ts server.ts
|
||||
import { StreamableHTTPTransport } from '@hono/mcp'
|
||||
import { serve } from '@hono/node-server'
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
||||
import { Hono } from 'hono'
|
||||
import { logger } from 'hono/logger'
|
||||
import { z } from 'zod'
|
||||
|
||||
const app = new Hono()
|
||||
app.use(logger())
|
||||
|
||||
const mcpServer = new McpServer({
|
||||
name: 'Example',
|
||||
version: '0.0.1'
|
||||
})
|
||||
|
||||
mcpServer.registerTool(
|
||||
'add',
|
||||
{
|
||||
description: 'Add two numbers',
|
||||
inputSchema: z.object({
|
||||
a: z.number(),
|
||||
b: z.number()
|
||||
})
|
||||
},
|
||||
async (args) => {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
content: String(args.a + args.b)
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
app.all('/mcp', async (c) => {
|
||||
const transport = new StreamableHTTPTransport()
|
||||
await mcpServer.connect(transport)
|
||||
return transport.handleRequest(c)
|
||||
})
|
||||
|
||||
serve({ fetch: app.fetch, port: 8787 })
|
||||
```
|
||||
|
||||
<Note>
|
||||
Hono is really flexible, so if you'd rather deploy your server to Cloudflare
|
||||
Workers instead of using Node.js (or any other platform), just follow [Hono's
|
||||
docs](https://hono.dev/docs/getting-started/basic).
|
||||
</Note>
|
||||
|
||||
## 3. Deploy your server
|
||||
|
||||
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), [render](https://render.com/docs/deploy-fastapi) (for instance, using the [hono](https://vercel.com/templates/hono/hono-on-vercel) API template), [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.
|
||||
|
|
|
@ -3,4 +3,102 @@ title: TS OpenAPI Hono
|
|||
description: This guide shows how to publish an OpenAPI service to Agentic using TypeScript and Hono's OpenAPI support.
|
||||
---
|
||||
|
||||
**TODO**
|
||||
[Hono](https://hono.dev) is a popular open source framework for building HTTP servers, and `@hono/zod-openapi`](https://hono.dev/examples/zod-openapi) is an excellent solution for auto-generating an OpenAPI spec from your Hono routes.
|
||||
|
||||
## 1. Install dependencies
|
||||
|
||||
<CodeGroup>
|
||||
|
||||
```bash npm
|
||||
npm add hono @hono/node-server @hono/zod-openapi zod
|
||||
```
|
||||
|
||||
```bash pnpm
|
||||
pnpm add hono @hono/node-server @hono/zod-openapi zod
|
||||
```
|
||||
|
||||
```bash bun
|
||||
bun add hono @hono/node-server @hono/zod-openapi zod
|
||||
```
|
||||
|
||||
```bash yarn
|
||||
yarn add hono @hono/node-server @hono/zod-openapi zod
|
||||
```
|
||||
|
||||
</CodeGroup>
|
||||
|
||||
## 2. Create a Hono OpenAPI Node.js server
|
||||
|
||||
```ts server.ts
|
||||
import { serve } from '@hono/node-server'
|
||||
import { createRoute, OpenAPIHono, z } from '@hono/zod-openapi'
|
||||
import { logger } from 'hono/logger'
|
||||
|
||||
const app = new OpenAPIHono()
|
||||
app.use(logger())
|
||||
|
||||
const echoRoute = createRoute({
|
||||
description: 'Echoes the request body',
|
||||
// The OpenAPI `operationId` will be used as the tool name in Agentic
|
||||
operationId: 'echo',
|
||||
method: 'post',
|
||||
path: '/echo',
|
||||
request: {
|
||||
body: {
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: z.object({}).passthrough()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
description: 'Echoed request body',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: z.object({}).passthrough()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return app.openapi(echoRoute, async (c) => {
|
||||
return c.json(c.req.valid('json'))
|
||||
})
|
||||
|
||||
app.doc31('/docs', {
|
||||
openapi: '3.1.0',
|
||||
info: {
|
||||
title: 'Example',
|
||||
description: 'Example description',
|
||||
version: '0.0.1'
|
||||
}
|
||||
})
|
||||
|
||||
serve({ fetch: app.fetch, port: 8787 })
|
||||
```
|
||||
|
||||
Note that the auto-generated OpenAPI spec will be available at `/docs` in this example.
|
||||
|
||||
<Note>
|
||||
Hono is really flexible, so if you'd rather deploy your server to Cloudflare
|
||||
Workers instead of using Node.js (or any other platform), just follow [Hono's
|
||||
docs](https://hono.dev/docs/getting-started/basic).
|
||||
</Note>
|
||||
|
||||
## 3. Deploy your server
|
||||
|
||||
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), [render](https://render.com/docs/deploy-fastapi) (for instance, using the [hono](https://vercel.com/templates/hono/hono-on-vercel) API template), [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 OpenAPI service to Agentic
|
||||
|
||||
Now that you have a publicly available MCP server, you can follow the [existing OpenAPI server guide](/publishing/guides/existing-openapi-server) to deploy it to Agentic.
|
||||
|
|
Ładowanie…
Reference in New Issue