静态mcpify
](https://www.npmjs.com/package/static-mcpify)
将任何结构化内容转换为静态内容 MCP(模型上下文协议) 服务器。
static-mcpify 从CMS(当前为Contentful)中提取内容,将其构建为静态Markdown和JSON文件,然后将这些文件作为功能齐全的MCP服务器提供。你的AI代理可以即时访问你的内容——没有数据库,没有运行时依赖关系。
网站 · ** · **

快速开始
1.安装
npm install static-mcpify2.初始化
在 .env 文件:
CONTENTFUL_API_TOKEN=your_token_here
SPACE_ID=your_space_id_here运行init向导以选择内容类型和配置工具:
npx smcp init --output my-mcp3.建造
从Contentful中提取内容并生成静态文件:
npx smcp build --output my-mcp仅构建特定内容类型:
npx smcp build --output my-mcp --content-type blog --content-type author4.发球
无服务器(Netlify Functions、Cloudflare Workers、Deno、Bun)
使用web标准处理程序——它需要一个 Request 并返回a Response:
import { handleMcpRequest } from 'static-mcpify/web-handler';
export default async (req: Request) => {
if (req.method === 'GET') {
return new Response(JSON.stringify({ status: 'ok' }), {
headers: { 'Content-Type': 'application/json' },
});
}
return handleMcpRequest('./my-mcp/content', req);
};Express/Node.js HTTP
在传统服务器环境中使用Node.js处理程序:
import { handleMcpRequest } from 'static-mcpify/handler';
import express from 'express';
const app = express();
app.use(express.json());
app.all('/mcp', async (req, res) => {
await handleMcpRequest('./my-mcp/content', req, res);
});
app.listen(3000);运作原理
内容结构
构建后,您的输出目录如下:
my-mcp/
├── config.json
└── content/
├── assets/
│ └── photo.json
└── entries/
├── person/
│ ├── config.json # defaultTool + tools: biography, skills
│ ├── bob-smith/
│ │ ├── data.json # All non-rich-text fields
│ │ └── tools/
│ │ ├── _default.md # Output for get_person
│ │ ├── biography.md # Output for get_person_biography
│ │ └── skills.md
│ └── steve-baker/
│ ├── data.json
│ └── tools/
│ ├── _default.md
│ ├── biography.md
│ └── skills.md
└── place/
├── config.json
└── work-site/
├── data.json
└── tools/
└── description.md_default.md 仅在以下情况下生成 defaultTool 为该条目类型配置。命名工具文件,如 biography.md 或 description.md 仅为中列出的条目生成 tools.
自动生成的工具
MCP服务器根据内容结构动态创建工具:
| 工具 | 说明 |
|---|---|
list_assets | 列出资产,带可选过滤器 |
get_asset | 按名称获取资产详细信息 |
list_ | 列出内容类型的条目,带有可选筛选器 |
get_ | 按标题段获取配置的默认工具内容 |
get__metadata | 启用时,通过标题slug获取条目元数据JSON |
get__ | 按标题slug获取工具的标记 |
工具名称是MCP安全的标识符,因此内容类型ID或工具名称中的破折号被规范化为下划线。例如, agent-skill 成为 get_agent_skill.
所有列表工具返回MCP structuredContent 呈...形状 { "titles": ["...", "..."] } 并做广告 outputSchema 对于这个回应。
例如,对于内容类型 person (默认工具已启用,工具:传记、技能)和 place (工具:说明):
list_person/get_person/get_person_metadata/get_person_biography/get_person_skillslist_place/get_place/get_place_descriptionlist_assets/get_asset
配置
输出配置(config.json)
{
"source": "contentful",
"instructions": [
"Use list_* tools before get_* tools when you need to discover available titles."
]
}instructions 是可选的。如果省略,则默认为 "Use list_* tools before get_* tools when you need to discover available titles.".
这些指令在MCP中发送 initialize 响应作为客户端的服务器级指导。
条目配置(content/entries//config.json)
{
"contentType": "person",
"format": "json",
"listTool": {
"description": "List all available people."
},
"includeMetadataTool": true,
"defaultTool": {
"description": "Get the primary biography for a specific person.",
"fields": ["biography"]
},
"tools": [
{
"name": "biography",
"fields": ["biography"]
},
{
"name": "skills",
"fields": ["skills", "certifications"]
}
]
}format 是可选的,默认为 "string".
listTool 是可选的。如果存在,它允许您覆盖显示的描述 list_.
includeMetadataTool 是可选的,默认为 false.
defaultTool 是可选的。当存在时,它控制由返回的内容 get_当省略时, get_ 未注册。
tools 是可选的。每个命名工具都定义了一个名称和要包含的Contentful字段。
当 format 是 "string",工具输出呈现为连接的Markdown,并在MCP中返回 content 现场。
当 format 是 "json",每个配置的字段都作为MCP上的属性返回 structuredContent,生成的工具定义包括 outputSchema.
列出始终使用的工具 structuredContent,不管 format.
现场实例
通过将这些添加到您的VS代码中,尝试托管示例MCP服务器 mcp.json:
静态内容示例 (人物和地点):
{
"static-example": {
"type": "http",
"url": "https://static-mcpify.alexlockhart.me/example/static/mcp"
}
}有内容的例子 (奇幻冒险和战役):
{
"contentful-example": {
"type": "http",
"url": "https://static-mcpify.alexlockhart.me/example/contentful/mcp"
}
}添加新的源适配器
要添加对新CMS(例如Sanity、Strapi)的支持:
- 创建
module/src/cli/sources//index.ts - 实施
SourceAdapter接口来自module/src/cli/sources/adapter.ts - 在中注册
module/src/cli/sources/index.ts - 将源名称添加到Zod枚举中
module/src/types/config.ts
发展
先决条件
- Node.js 22+
- npm
项目结构
module/ # Publishable npm package (static-mcpify)
├── src/
│ ├── types/ # Zod schemas and TypeScript types
│ ├── cli/ # smcp CLI tool (init + build commands)
│ │ └── sources/ # Source adapters (pluggable)
│ │ └── contentful/
│ └── server/ # MCP server + handlers
├── package.json
└── tsconfig.json
netlify/ # Brand website + hosted examples
├── brand/ # Static HTML/CSS brand website
├── functions/ # Netlify serverless function handlers
└── package.json
examples/ # Example content and configs
├── static/ # Pre-built static content (no CMS needed)
└── contentful/ # Contentful-backed content (built at deploy time)
test/ # Sanity tests这是一个包含两个包的npm工作区:
module/--可出版的static-mcpifynpm包(CLI+MCP服务器)netlify/--用于托管示例的品牌网站和Netlify无服务器功能
命令
| 命令 | 描述 |
|---|---|
npm start | 启动MCP服务器(静态+内容)和品牌网站 |
npm run build | TypeScript编译+构建内容丰富的示例 |
npm run build:ts | 仅编译TypeScript |
npm test | 健全性检查MCP服务器端点 |
npm run lint | 运行ESLint |
npm run fix | 运行ESLint并自动修复 |
本地开发
npm start 同时运行三个服务:
- 静态MCP服务器 在
http://localhost:3100/mcp - 内容丰富的MCP服务器 在
http://localhost:3101/mcp - 品牌网站 在
http://localhost:3102
测试
运行健全性测试,启动两个MCP服务器并验证健康状况和MCP初始化响应:
npm test在提交之前,始终运行lint和TypeScript编译:
npm run lint
npm run build:tsNetlify部署
项目部署到 静态mcpify.alexlockhart.me 通过Netlify。
- 推到
main触发自动部署 - 构建命令:
npm run build:ts && npm run build:contentful node_bundler = "nft"(节点文件跟踪)解析函数中的工作区包- 环境变量
CONTENTFUL_API_TOKEN和SPACE_ID在Netlify上被设置为秘密
Netlify函数使用 static-mcpify/web-handler 它封装了MCP SDK WebStandardStreamableHTTPServerTransport 随着 enableJsonResponse: true。这将返回JSON响应,而不是无状态无服务器环境所需的SSE流。
许可证
国际学生委员会
______________________________________________________________________
由...制作 亚历克斯·洛克哈特
