关于 mcp-tool-factory
MCP Tool Factory 是用于生成 MCP 服务的 TypeScript 工具,面向希望从描述、API 规范、数据模式或本体构建工具的开发者。它本身也可作为 MCP 服务运行,并提供命令行和编程接口。
主要功能
- 01根据自然语言描述生成
- 02导入 OpenAPI 和 GraphQL 模式
- 03根据数据库模式创建工具
- 04从 RDF、JSON-LD 和 YAML 本体生成
- 05生成工具、资源和提示词
- 06验证生成的 TypeScript
适用场景
- 01根据 API 规范创建 MCP 服务
- 02将数据库操作公开为 MCP 工具
- 03根据本体生成服务代码
MCP 相关
它本身就是 MCP 服务,向 MCP 客户端提供生成和 TypeScript 验证工具。生成的服务支持 MCP 工具、资源和提示词,并采用 Streamable HTTP 传输。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
npx -y @heshamfsalama/mcp-tool-factoryANTHROPIC_API_KEY密钥Anthropic Claude API key (one of the 4 provider keys is required)CLAUDE_CODE_OAUTH_TOKEN密钥Claude Code OAuth token (one of the 4 provider keys is required)OPENAI_API_KEY密钥OpenAI GPT API key (one of the 4 provider keys is required)GOOGLE_API_KEY密钥Google Gemini API key (one of the 4 provider keys is required)本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
MCP Tool Factory (TypeScript)
根据自然语言描述、OpenAPI 规范、数据库架构、GraphQL 架构或本体,生成可用于生产环境的 MCP(Model Context Protocol)服务。
为什么选择 MCP?
Model Context Protocol (MCP) 是一项开放标准,可让 AI 助手安全地连接外部数据源和工具。MCP 服务提供的工具可供以下对象使用:
- Claude Code 和 Claude Desktop
- OpenAI Agents SDK
- Google ADK (Agent Development Kit)
- LangChain 和 CrewAI
- 任何兼容 MCP 的客户端
MCP Tool Factory 可在几秒内生成完整、可用于生产环境的 MCP 服务。
功能
| 功能 | 描述 |
|---|---|
| 自然语言 | 用通俗易懂的英语描述工具 |
| 导入 OpenAPI | 将任意 REST API 规范转换为 MCP 工具 |
| 数据库 CRUD | 根据 SQLite 或 PostgreSQL 架构生成工具 |
| 导入 GraphQL | 将 GraphQL 架构转换为 MCP 工具(查询转换为读取操作,变更转换为写入操作) |
| 导入本体 | 根据 RDF/OWL、JSON-LD 或 YAML 本体生成 |
| 资源与提示词 | 全面支持 MCP 的全部三种基本元素:工具、资源和提示词 |
| 10 个大模型提供商 | Anthropic、OpenAI、Google、Mistral、DeepSeek、Groq、xAI、Azure、Cohere,以及通过 Vercel AI SDK 使用 Claude Code |
| 成本跟踪 | 按调用计算成本、设置预算上限、比较提供商成本 |
| 并行生成 | 并发生成工具实现,加快输出速度 |
| 大模型响应缓存 | 使用可配置的 TTL 消除重复的大模型调用 |
| Streamable HTTP | 生成的服务使用现代的 Streamable HTTP 传输方式 |
| 网页搜索 | 自动获取 API 文档,提升生成效果 |
| 适用于生产环境 | 内置日志记录、指标、速率限制和重试机制 |
| 类型安全 | 完整的 TypeScript 支持,并启用严格模式 |
| MCP Registry | 生成用于发布到注册表的 server.json |
| 本身也是 MCP 服务 | 可直接与 Claude 搭配使用,按需即时生成服务 |
作为 MCP 服务使用
MCP Tool Factory 本身就是一个 MCP 服务!将其添加到 Claude Desktop、Claude Code、Cursor 或 VS Code,即可通过对话生成 MCP 服务。
第 1 层——零配置(Claude Code)
Claude Code 会自动注入 CLAUDE_CODE_OAUTH_TOKEN,无需环境变量:
claude mcp add mcp-tool-factory -- node /path/to/mcp-tool-factory-ts/bin/mcp-server.js
第 2 层——标准配置(任选一个提供商)
设置一个 API 密钥即可使用。工厂会自动检测提供商:
Claude Desktop / Cursor / VS Code——添加到 MCP 配置(claude_desktop_config.json、.cursor/mcp.json 或 .vscode/mcp.json):
{
"mcpServers": {
"mcp-tool-factory": {
"command": "node",
"args": ["/path/to/mcp-tool-factory-ts/bin/mcp-server.js"],
"env": {
"ANTHROPIC_API_KEY": "your-key-here"
}
}
}
}
以下任一 API 密钥均可使用:ANTHROPIC_API_KEY、OPENAI_API_KEY、GOOGLE_API_KEY、MISTRAL_API_KEY、DEEPSEEK_API_KEY、GROQ_API_KEY、XAI_API_KEY、AZURE_OPENAI_API_KEY、COHERE_API_KEY。
第 3 层 — 完全控制(提供商 + 模型 + 预算)
使用 MCP_FACTORY_PROVIDER、MCP_FACTORY_MODEL 和 MCP_FACTORY_BUDGET 覆盖自动检测:
{
"mcpServers": {
"mcp-tool-factory": {
"command": "node",
"args": ["/path/to/mcp-tool-factory-ts/bin/mcp-server.js"],
"env": {
"OPENAI_API_KEY": "your-key-here",
"MCP_FACTORY_PROVIDER": "openai",
"MCP_FACTORY_MODEL": "gpt-5.2",
"MCP_FACTORY_BUDGET": "0.50"
}
}
}
}
| 环境变量 | 用途 | 示例 |
|---|---|---|
MCP_FACTORY_PROVIDER | 覆盖自动检测到的提供商 | openai、groq、deepseek |
MCP_FACTORY_MODEL | 覆盖默认模型 | gpt-5.2、deepseek-chat |
MCP_FACTORY_BUDGET | 每次生成的预算上限(美元) | 0.50 |
完全控制的 Claude Code CLI:
claude mcp add mcp-tool-factory \
-e DEEPSEEK_API_KEY=your-key \
-e MCP_FACTORY_PROVIDER=deepseek \
-e MCP_FACTORY_MODEL=deepseek-chat \
-e MCP_FACTORY_BUDGET=0.25 \
-- node /path/to/mcp-tool-factory-ts/bin/mcp-server.js
可用工具
| 工具 | 描述 |
|---|---|
generate_mcp_server | 根据自然语言描述生成 |
generate_from_openapi | 根据 OpenAPI 规范生成 |
generate_from_database | 根据数据库架构生成 |
generate_from_graphql | 根据 GraphQL 架构生成 |
generate_from_ontology | 根据 RDF/OWL、JSON-LD 或 YAML 本体生成 |
validate_typescript | 验证 TypeScript 代码 |
list_providers | 列出可用的大模型提供商 |
get_factory_info | 获取工厂功能信息 |
对话示例
你: 为 GitHub API 创建一个 MCP 服务,包含用于列出仓库、创建问题和管理拉取请求的工具
Claude: 使用
generate_mcp_server工具我已生成一个完整的 MCP 服务,其中包含以下工具:
list_repositories- 列出用户仓库create_issue- 创建新问题list_pull_requests- 列出仓库的 PRmerge_pull_request- 合并 PR我来把这些文件写入你的项目……
快速开始
安装
# Global installation
npm install -g @heshamfsalama/mcp-tool-factory
# Or use npx
npx @heshamfsalama/mcp-tool-factory generate "Create tools for managing a todo list"
设置 API 密钥
至少需要一个提供商 API 密钥:
# Anthropic Claude (recommended)
export ANTHROPIC_API_KEY=your-key-here
# Or Claude Code OAuth
export CLAUDE_CODE_OAUTH_TOKEN=your-token-here
# Or any other supported provider
export OPENAI_API_KEY=your-key-here
export GOOGLE_API_KEY=your-key-here
export MISTRAL_API_KEY=your-key-here
export DEEPSEEK_API_KEY=your-key-here
export GROQ_API_KEY=your-key-here
export XAI_API_KEY=your-key-here
export AZURE_OPENAI_API_KEY=your-key-here
export COHERE_API_KEY=your-key-here
生成你的第一个服务
# From natural language
mcp-factory generate "Create tools for fetching weather data by city and converting temperatures"
# From OpenAPI spec
mcp-factory from-openapi ./api-spec.yaml
# From database
mcp-factory from-database ./data.db
# From GraphQL schema
mcp-factory from-graphql ./schema.graphql
# From ontology
mcp-factory from-ontology ./ontology.owl --format rdf
使用方法
自然语言生成
mcp-factory generate "Create tools for managing a todo list with priorities" \
--name todo-server \
--output ./servers/todo \
--web-search \
--logging \
--metrics
OpenAPI 规范
# From local file
mcp-factory from-openapi ./openapi.yaml --name my-api-server
# With custom base URL
mcp-factory from-openapi ./spec.json --base-url https://api.example.com
数据库架构
# SQLite
mcp-factory from-database ./myapp.db --tables users,posts,comments
# PostgreSQL
mcp-factory from-database "postgresql://user:pass@localhost/mydb" --type postgresql
GraphQL 架构
# From a GraphQL SDL file
mcp-factory from-graphql ./schema.graphql --name my-graphql-server
# From a URL endpoint
mcp-factory from-graphql https://api.example.com/graphql --name my-api-server
GraphQL 查询会映射为只读 MCP 工具,变更操作会映射为写入工具。GraphQL 类型会自动转换为 Zod 验证架构。
本体
# From RDF/OWL (.owl, .rdf, .ttl)
mcp-factory from-ontology ./ontology.owl --format rdf --name knowledge-server
# From JSON-LD (.jsonld)
mcp-factory from-ontology ./schema.jsonld --format jsonld --name linked-data-server
# From custom YAML ontology
mcp-factory from-ontology ./domain.yaml --format yaml --name domain-server
OWL 类会映射为 MCP 资源,ObjectProperties 会转换为工具,DataProperties 会转换为工具参数。
测试与服务
# Run tests
mcp-factory test ./servers/my-server
# Start server for testing
mcp-factory serve ./servers/my-server
生成的服务结构
servers/my-server/
├── src/
│ └── index.ts # MCP server with tools, resources, and prompts
├── tests/
│ └── tools.test.ts # Vitest tests (InMemoryTransport)
├── package.json # Dependencies
├── tsconfig.json # TypeScript config
├── Dockerfile # Container deployment
├── README.md # Usage documentation
├── skill.md # Claude Code skill file
├── server.json # MCP Registry manifest
├── EXECUTION_LOG.md # Generation trace (optional)
└── .github/
└── workflows/
└── ci.yml # GitHub Actions CI/CD
生成的服务会导出一个 createServer() 工厂函数,便于测试。服务使用 Streamable HTTP 传输,包含一个 /mcp POST 端点和一个 /health GET 端点。测试使用 InMemoryTransport.createLinkedPair(),通过 vitest 在进程内进行快速、可靠的测试。
CLI 参考
| 命令 | 描述 |
|---|---|
generate <description> | 根据自然语言生成 MCP 服务 |
from-openapi <spec> | 根据 OpenAPI 规范生成 |
from-database <path> | 根据数据库架构生成 |
from-graphql <schema> | 根据 GraphQL 架构生成 |
from-ontology <file> | 根据 RDF/OWL、JSON-LD 或 YAML 本体生成 |
test <server-path> | 运行生成服务的测试 |
serve <server-path> | 启动服务以进行测试 |
info | 显示工厂信息 |
生成选项
mcp-factory generate "..." \
--output, -o <path> # Output directory (default: ./servers)
--name, -n <name> # Server name
--description, -d <desc> # Package description
--github-username, -g <user> # GitHub username for MCP Registry
--version, -v <ver> # Server version (default: 1.0.0)
--provider, -p <provider> # LLM provider (anthropic, openai, google, mistral, deepseek, groq, xai, azure, cohere, claude_code)
--model, -m <model> # Specific model to use
--web-search, -w # Search web for API documentation
--auth <vars...> # Environment variables for auth
--health-check # Include health check endpoint (default: true)
--logging # Enable structured logging (default: true)
--metrics # Enable Prometheus metrics
--rate-limit <n> # Rate limiting (requests per minute)
--retries # Enable retry logic (default: true)
--budget <amount> # Maximum spend in USD (aborts if exceeded)
--compare-costs # Show cost comparison across providers before generating
配置
环境变量
| 变量 | 描述 | 是否必需 |
|---|---|---|
ANTHROPIC_API_KEY | Anthropic Claude API 密钥 | 至少需要一个 |
CLAUDE_CODE_OAUTH_TOKEN | Claude Code OAuth 令牌 | 提供商密钥 |
OPENAI_API_KEY | OpenAI API 密钥 | 必需 |
GOOGLE_API_KEY | Google Gemini API 密钥 | 用于生成 |
MISTRAL_API_KEY | Mistral AI API 密钥 | |
DEEPSEEK_API_KEY | DeepSeek API 密钥 | |
GROQ_API_KEY | Groq API 密钥 | |
XAI_API_KEY | xAI Grok API 密钥 | |
AZURE_OPENAI_API_KEY | Azure OpenAI API 密钥 | |
COHERE_API_KEY | Cohere API 密钥 |
LLM 提供商
所有提供商都通过统一的 UnifiedLLMProvider 类使用 Vercel AI SDK,并采用延迟动态导入机制——运行时只会加载所选提供商对应的 @ai-sdk/* 包。
| 提供商 | 模型 | 最适用于 |
|---|---|---|
| Anthropic | claude-opus-4-6, claude-sonnet-4-5, claude-haiku-4-5 | 最高质量 |
| OpenAI | gpt-5.2, gpt-5.2-codex, o3, o4-mini | 快速生成 |
| gemini-3-pro, gemini-3-flash, gemini-2.5-pro | 高性价比 | |
| Mistral | mistral-large, codestral, magistral | 欧洲 AI、代码 |
| DeepSeek | deepseek-chat, deepseek-reasoner | 超低成本 |
| Groq | llama-3.3-70b, llama-4-maverick | 超快推理 |
| xAI | grok-4, grok-3, grok-code-fast | 推理 |
| Azure | gpt-4o(由 Azure 托管) | 企业合规 |
| Cohere | command-a, command-r+ | RAG、企业搜索 |
| Claude Code | claude-sonnet-4-5(OAuth) | Claude Code 用户 |
编程方式使用
基本用法
import { ToolFactoryAgent, writeServerToDirectory, formatCost } from '@heshamfsalama/mcp-tool-factory';
// Create agent (auto-detects provider from env vars)
const agent = new ToolFactoryAgent();
// Generate from description
const server = await agent.generateFromDescription(
'Create tools for managing a todo list with priorities',
{
serverName: 'todo-server',
webSearch: true,
parallel: true, // Enable parallel generation (default)
maxConcurrency: 5, // Max concurrent LLM calls (default)
budget: 1.00, // Optional: abort if cost exceeds $1.00
productionConfig: {
enableLogging: true,
enableMetrics: true,
},
}
);
// Cost tracking — see how much the generation cost
if (server.executionLog) {
console.log(`Cost: ${formatCost(server.executionLog.totalCost)}`);
}
// Write to directory
await writeServerToDirectory(server, './servers/todo');
从 OpenAPI 创建
import { ToolFactoryAgent, writeServerToDirectory } from '@heshamfsalama/mcp-tool-factory';
import { readFileSync } from 'fs';
import yaml from 'js-yaml';
const spec = yaml.load(readFileSync('./openapi.yaml', 'utf-8'));
const agent = new ToolFactoryAgent({ requireLlm: false });
const server = await agent.generateFromOpenAPI(spec, {
serverName: 'my-api-server',
baseUrl: 'https://api.example.com',
});
await writeServerToDirectory(server, './servers/api');
从数据库创建
import { ToolFactoryAgent, writeServerToDirectory } from '@heshamfsalama/mcp-tool-factory';
const agent = new ToolFactoryAgent({ requireLlm: false });
// SQLite (auto-detected from file path)
const server = await agent.generateFromDatabase('./data/app.db', {
serverName: 'app-database-server',
tables: ['users', 'posts', 'comments'],
});
// PostgreSQL (auto-detected from connection string)
const pgServer = await agent.generateFromDatabase(
'postgresql://user:pass@localhost/mydb',
{ serverName: 'postgres-server' }
);
await writeServerToDirectory(server, './servers/app-db');
从 GraphQL 创建
import { ToolFactoryAgent, writeServerToDirectory } from '@heshamfsalama/mcp-tool-factory';
import { readFileSync } from 'fs';
const schema = readFileSync('./schema.graphql', 'utf-8');
const agent = new ToolFactoryAgent({ requireLlm: false });
const server = await agent.generateFromGraphQL(schema, {
serverName: 'my-graphql-server',
});
await writeServerToDirectory(server, './servers/graphql');
从本体创建
import { ToolFactoryAgent, writeServerToDirectory } from '@heshamfsalama/mcp-tool-factory';
import { readFileSync } from 'fs';
const ontologyData = readFileSync('./ontology.owl', 'utf-8');
const agent = new ToolFactoryAgent({ requireLlm: false });
const server = await agent.generateFromOntology(ontologyData, {
serverName: 'knowledge-server',
format: 'rdf',
});
await writeServerToDirectory(server, './servers/knowledge');
代码验证
import { validateTypeScriptCode, validateGeneratedServer } from '@heshamfsalama/mcp-tool-factory';
// Validate TypeScript syntax
const result = await validateTypeScriptCode(code);
// { valid: false, errors: [{ line: 4, column: 1, message: "'}' expected." }] }
// Validate complete server
const serverResult = await validateGeneratedServer(serverCode);
// { valid: true, errors: [], summary: 'Generated server code is syntactically valid' }
与 AI 框架配合使用
Claude Code / Claude Desktop
添加到 MCP 设置(claude_desktop_config.json):
{
"mcpServers": {
"my-server": {
"command": "npx",
"args": ["tsx", "./servers/my-server/src/index.ts"]
}
}
}
OpenAI Agents SDK
from agents import Agent
from agents.mcp import MCPServerStdio
async with MCPServerStdio(
command="npx",
args=["tsx", "./servers/my-server/src/index.ts"]
) as mcp:
agent = Agent(
name="My Agent",
tools=mcp.list_tools()
)
Google ADK
from google.adk.tools.mcp_tool import MCPToolset
tools = MCPToolset(
connection_params=StdioServerParameters(
command="npx",
args=["tsx", "./servers/my-server/src/index.ts"]
)
)
LangChain
from langchain_mcp_adapters.client import MCPClient
client = MCPClient(
command="npx",
args=["tsx", "./servers/my-server/src/index.ts"]
)
tools = client.get_tools()
生产环境功能
结构化日志
mcp-factory generate "..." --logging
生成的服务使用 pino 记录结构化 JSON 日志:
const logger = pino({ level: 'info' });
logger.info({ tool: 'get_weather', params }, 'Tool called');
Prometheus 指标
mcp-factory generate "..." --metrics
生成的服务使用 prom-client 记录指标:
mcp_tool_calls_total- 工具调用次数计数器mcp_tool_duration_seconds- 执行时间直方图
速率限制
mcp-factory generate "..." --rate-limit 100
可为每个客户端配置基于滑动窗口的速率限制。
重试逻辑
mcp-factory generate "..." --retries
针对暂时性故障进行指数退避重试。
结构化错误代码
生成的服务使用结构化错误代码,确保错误处理方式一致:
INVALID_INPUT- 工具参数格式错误或无效NOT_FOUND- 请求的资源不存在AUTH_ERROR- 身份验证或授权失败INTERNAL_ERROR- 意外的服务端错误
增强型健康检查
/health 端点会返回详细的服务状态:
{
"status": "ok",
"version": "1.0.0",
"uptime": 3600,
"memory": { "rss": 52428800, "heapUsed": 20971520 },
"transport": "streamable-http"
}
发布到 MCP Registry
将生成的服务发布到 MCP Registry,以便用户发现。
生成支持 Registry 的文件
mcp-factory generate "Create weather tools" \
--name weather-server \
--github-username your-github-username \
--description "Weather tools for Claude" \
--version 1.0.0
此操作会生成符合 Registry 规范的文件:
package.json:
{
"name": "@your-github-username/weather-server",
"mcpName": "io.github.your-github-username/weather-server"
}
server.json:
{
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "io.github.your-github-username/weather-server",
"packages": [{
"registryType": "npm",
"identifier": "@your-github-username/weather-server",
"transport": { "type": "stdio" }
}],
"tools": [...]
}
发布工作流
# 1. Build and publish to npm
cd ./servers/weather-server
npm install && npm run build
npm publish --access public
# 2. Install mcp-publisher
brew install modelcontextprotocol/tap/mcp-publisher
# 3. Authenticate
mcp-publisher login github
# 4. Publish to registry
mcp-publisher publish
详细说明请参阅发布指南。
架构
┌───────────────────────────────────────────────────────────────────────┐
│ MCP Tool Factory │
├───────────────────────────────────────────────────────────────────────┤
│ Input Sources │
│ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌───────────┐ ┌─────────┐│
│ │ Natural │ │ OpenAPI │ │ Database │ │ GraphQL │ │Ontology ││
│ │ Language │ │ Spec │ │ Schema │ │ Schema │ │RDF/YAML ││
│ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ └─────┬─────┘ └────┬────┘│
│ └──────────┬───┴─────────────┴─────────────┴────────────┘ │
│ ▼ │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ ToolFactoryAgent │ │
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
│ │ │ UnifiedLLMProvider (Vercel AI SDK) │ │ │
│ │ │ Anthropic │ OpenAI │ Google │ Mistral │ DeepSeek │ │ │
│ │ │ Groq │ xAI │ Azure │ Cohere + Claude Code OAuth │ │ │
│ │ └─────────────────────────────────────────────────────────┘ │ │
│ │ ┌──────────────┐ ┌──────────────┐ ┌───────────────────────┐ │ │
│ │ │ LLM Cache │ │ Cost │ │ Parallel Generation │ │ │
│ │ │ (TTL-based) │ │ Tracking │ │ (max concurrency: 5) │ │ │
│ │ └──────────────┘ └──────────────┘ └───────────────────────┘ │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ Generators │ │
│ │ ServerGenerator │ DocsGenerator │ TestsGenerator │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ GeneratedServer │ │
│ │ Tools │ Resources │ Prompts │ Tests │ Docs │ Dockerfile │ │
│ └────────────────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌────────────────────────────────────────────────────────────────┐ │
│ │ Streamable HTTP Transport │ │
│ │ POST /mcp │ GET /health │ │
│ └────────────────────────────────────────────────────────────────┘ │
└───────────────────────────────────────────────────────────────────────┘
开发
# Clone the repository
git clone https://github.com/HeshamFS/mcp-tool-factory-ts.git
cd mcp-tool-factory-ts
# Install dependencies
pnpm install
# Build
pnpm run build
# Run tests
pnpm test
# Type check
pnpm run typecheck
# Lint
pnpm run lint
项目结构
mcp-tool-factory-ts/
├── src/
│ ├── agent/ # Main ToolFactoryAgent
│ ├── auth/ # OAuth2 providers
│ ├── cache/ # LLM response caching with configurable TTL
│ ├── cli/ # Command-line interface
│ ├── config/ # Configuration management
│ ├── database/ # Database introspection (SQLite, PostgreSQL)
│ ├── execution-logger/ # Execution logging
│ ├── generators/ # Code generators (server, docs, tests)
│ ├── graphql/ # GraphQL SDL parsing and server generation
│ ├── middleware/ # Validation middleware
│ ├── models/ # Data models
│ ├── observability/ # Telemetry and tracing
│ ├── ontology/ # Ontology parsing (RDF/OWL, JSON-LD, YAML)
│ ├── openapi/ # OpenAPI spec parsing
│ ├── production/ # Production code generation
│ ├── prompts/ # LLM prompt templates
│ ├── providers/ # LLM providers (10 providers via Vercel AI SDK + Claude Code)
│ ├── security/ # Security scanning
│ ├── server/ # MCP server mode (factory-as-a-server)
│ ├── templates/ # Handlebars templates for generated files
│ ├── validation/ # Code validation and Zod schemas
│ └── web-search/ # Web search integration
├── docs/ # Documentation
├── tests/ # Test files
└── dist/ # Built output
文档
故障排除
常见问题
未找到 API 密钥
# Check your environment
echo $ANTHROPIC_API_KEY
# Set it
export ANTHROPIC_API_KEY=your-key-here
生成的服务无法启动
# Install dependencies first
cd ./servers/my-server
npm install
npx tsx src/index.ts
TypeScript 错误
# Validate generated code
import { validateGeneratedServer } from '@heshamfsalama/mcp-tool-factory';
const result = await validateGeneratedServer(code);
console.log(result.errors);
更多解决方案请参阅故障排除指南。
更新日志
v0.3.0
- 迁移至 Vercel AI SDK - 所有大模型提供商现在都通过单个
UnifiedLLMProvider类使用 Vercel AI SDK,并采用延迟动态导入。移除了约 473 行提供商专属实现代码。运行时只会加载您所选提供商对应的@ai-sdk/*包。 - 10 个大模型提供商 - 在现有的 Anthropic、OpenAI、Google 和 Claude Code 提供商之外,新增了 Mistral、DeepSeek、Groq、xAI、Azure 和 Cohere。所有提供商都使用相同的统一接口。
- 成本跟踪 - 每次大模型调用现在都会使用内置的 50 多种模型定价表计算预估成本。显示单次调用成本、生成总成本以及各阶段的成本明细(工具提取、实现、测试、文档)。详细的令牌明细包括来自 AI SDK 的缓存读取/写入令牌和推理令牌。
- 预算限制(
--budget <amount>)- 设置以 USD 计的最高支出。如果累计成本超出预算,生成过程会通过BudgetExceededError优雅中止。 - 提供商成本比较(
--compare-costs)- 生成前,估算所有可用提供商的成本,并显示按成本排序的比较表。无需额外 API 调用——使用静态定价表即可。 - 各阶段成本明细 - CLI 输出和执行日志会显示哪些生成步骤成本最高(工具提取、实现、资源提取、提示词提取、测试生成、文档生成)。
- OpenAI 推理模型支持 - 对于不支持温度参数的 OpenAI o 系列和 gpt-5.x 模型,会自动省略该参数。
v0.2.0
- 可流式 HTTP 传输 - 生成的服务使用原生
http模块和StreamableHTTPServerTransport,取代 Express/SSE(已于 2025 年 6 月弃用)。使用单个/mcpPOST 端点和/healthGET 端点。 - MCP SDK v1.26.0 - 从
^1.0.0更新至^1.26.0 - 资源与提示词 - 完整支持全部三种 MCP 基元。资源用于公开结构化数据(文档、数据库记录、文件树)。提示词提供可复用模板,用于引导大模型工作流。Agent 会通过大模型自动从描述中提取资源和提示词。
- GraphQL 输入源 - 新增
from-graphqlCLI 命令和generate_from_graphqlMCP 工具。查询映射为读取工具,变更映射为写入工具,GraphQL 类型则转换为 Zod 架构。 - 本体输入源 - 新增
from-ontologyCLI 命令和generate_from_ontologyMCP 工具。支持 RDF/OWL、JSON-LD 和自定义 YAML 格式。OWL 类映射为资源,对象属性映射为工具,数据属性映射为工具参数。 - 大模型响应缓存 - 通过可配置的 TTL 对相同的大模型调用去重。可通过
skipCache选项绕过缓存。 - 并行生成 - 默认并发生成工具实现(
parallel: true、maxConcurrency: 5)。显著提升多工具服务的生成速度。 - InMemoryTransport 测试 - 生成的测试使用
InMemoryTransport.createLinkedPair(),而不是启动子进程。服务会导出createServer()工厂函数,以便进行测试。 - 生产环境增强 - 在工具处理程序中接入了速率限制、结构化日志记录、指标和耗时跟踪。增强了健康检查,加入版本、运行时间、内存和传输信息。结构化错误代码:
INVALID_INPUT、NOT_FOUND、AUTH_ERROR、INTERNAL_ERROR。
v0.1.0
- 首个 TypeScript 版本
- 使用 Claude、Claude Code、OpenAI、Google Gemini 进行自然语言生成
- 导入 OpenAPI 3.0+ 规范
- 生成数据库 CRUD(SQLite、PostgreSQL)
- 生产环境功能(日志记录、指标、速率限制)
- 生成 MCP Registry 的 server.json
- TypeScript 语法验证
- 搜索 API 文档
- 生成 GitHub Actions CI/CD
- MCP 服务模式:使用 Claude 即时生成
许可证
MIT
Links
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。