无服务器MCP开发示例

展示如何使用Netlify Functions开发和运行无服务器MCP的示例站点,包括部署的服务器less函数链接和自定义URL访问示例。

  • by Dc39313n
  • HTML
  • 本地部署
  • 更新于
在 GitHub 查看 Dc39313n/MCP

使用说明

MCP示例Netlify Express

查看此演示网站根据您提供的信息,以下是原文内容的中文翻译:

关于此示例网站

这个网站展示了一个使用Netlify Functions开发和运行无服务器MCP(多容器部署)的非常基础的示例。它包含了已部署无服务器函数的链接以及使用自定义URL访问该函数的示例。

重要的是,由于Express处理路由映射的方式,请确保你设置了 netlify.toml 重定向到正确的路径。在这个例子中,我们有以下内容来确保 /mcp捕获了发送到此服务器的所有请求:

[[redirects]]
  force = true
  from = "/mcp"
  status = 200
  to = "/.netlify/functions/express-mcp-server"

迅速部署您自己的版本

点击下面的“部署到Netlify”按钮,即可部署此示例网站的自定义版本。这将自动:

  • 从示例库中克隆此示例的副本到您自己的GitHub帐户
  • 在您的(环境中)创建一个新项目 Netlify账户,与你的新仓库链接
  • 创建一个自动化部署流水线来监控你仓库中的更改
  • 构建并部署您的新网站
  • 这个仓库随后可以用于在本地进行迭代使用 netlify dev

在本地安装并运行示例

你可以克隆这个完整的示例仓库来探索这个和其他示例,并在本地运行它们。


# 1. Clone the examples repository to your local development environment
git clone git@github.com:netlify/examples

# 2. Move into the project directory for this example
cd examples/mcp/express-mcp

# 3. Install the Netlify CLI to let you locally serve your site using Netlify's features
npm i -g netlify-cli

# 4. Serve your site using Netlify Dev to get local serverless functions
netlify dev

# 5. While the site is running locally, open a separate terminal tab to run the MCP inspector or client you desire
npx @modelcontextprotocol/inspector npx mcp-remote@next http://localhost:8888/mcp