
SuFetch
带MCP服务器的类型安全的OpenAPI客户端,用于AI驱动的API探索
目录
______________________________________________________________________
SuFetch是什么?
SuFetch结合了两个强大的工具:
- 类型安全的API客户端 -根据OpenAPI规范生成全类型TypeScript客户端
- MCP服务器 -让AI助手(如Claude)探索您的API并生成代码
内置 阿匹富 对于类型安全的OpenAPI客户端。
特性
- ✨ 完全类型安全 -所有API调用的自动完成和类型检查
- 🤖 MCP集成 -AI助手可以为您的API探索和生成代码
- 🔄 自动发现 -自动服务检测和类型生成
- 🛠️ 现代堆栈 -TypeScript 5.7,ESNext,严格模式
- 🧪 测试良好 -76+次测试,覆盖率>60%
安装
用于使用API客户端
# npm
npm install sufetch
# pnpm
pnpm add sufetch
# yarn
yarn add sufetch用于MCP服务器(全局)
# Install globally
npm install -g sufetch
# Verify installation
sufetch-mcp --version为了发展
git clone https://github.com/productdevbook/sufetch.git
cd sufetch
pnpm install
pnpm build快速开始
使用类型安全的API客户端
import { createClient, cloud } from 'sufetch/hetzner'
// Create a typed client
const client = createClient({
baseURL: 'https://api.hetzner.cloud/v1',
headers: {
'Authorization': 'Bearer your-api-token'
}
}).with(cloud)
// Fully typed requests and responses
const servers = await client('/servers', {
method: 'GET' // ✅ Type-checked
})
// TypeScript knows the response type
console.log(servers.servers) // ✅ Autocomplete works看 支持的API 对于所有可用的服务。
高级字体安全的字体助手
从端点提取特定类型以获得最大类型安全性:
import type { HetznerCloud } from 'sufetch/hetzner'
// Extract request body type
type CreateServerBody = HetznerCloud['request']
// Extract response type
type GetServerResponse = HetznerCloud['response']
// Extract query parameters
type ListServersQuery = HetznerCloud['query']
// Extract path parameters
type ServerPathParams = HetznerCloud['path']
// Use in functions for type safety
function processServer(server: GetServerResponse) {
console.log(server.server.id) // ✅ Full autocomplete
console.log(server.server.name) // ✅ Type-checked
}
function createServer(body: CreateServerBody) {
// TypeScript enforces correct structure
return client('/servers', {
method: 'POST',
body // ✅ Type-safe
})
}可用属性:
['request']-请求正文类型['response']-成功响应(200/201)['query']-查询参数['path']-路径参数['responses'][status]-特定状态代码响应
适用于所有API: HetznerCloud, DigitalOcean, OryKaratos, OryHydra.
使用AI助手(MCP)
看 MCP服务器设置 下面的部分。
支持的API
SuFetch目前包括:
| API | 描述 | 端点 | 导入 |
|---|---|---|---|
| 数字海洋 | 完整的云平台API | 200+ | sufetch/digitalocean |
| Hetzner 云 | 云基础设施管理 | 100+ | sufetch/hetzner |
| 奥里·奎托斯 | 身份和用户管理 | 50+ | sufetch/ory |
| Ory Hydra | OAuth 2.0和OpenID连接 | 40+ | sufetch/ory |
想添加更多吗? 看 添加新API.
MCP服务器设置
快速设置
1.安装(选择一个):
npm install -g sufetch # Global
npx sufetch-mcp # No install2.配置:
Claude Desktop (click to expand)
编辑配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 窗户:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"sufetch": {
"command": "sufetch-mcp"
}
}
}重新启动克劳德桌面。
Claude Code CLI (click to expand)
claude mcp add --transport stdio --scope project sufetch -- sufetch-mcp或创建 .mcp.json:
{
"mcpServers": {
"sufetch": {
"command": "sufetch-mcp"
}
}
}3.测试: 问Claude:“使用sufetch列出可用的API”
可用的MCP工具
| 工具 | 说明 |
|---|---|
list_apis | 列出所有可用的API |
get_api_info | 获取API元数据 |
search_endpoints | 按路径/方法/描述搜索 |
get_endpoint_details | 获取完整的端点规格 |
get_schema_details | 获取数据模式 |
generate_code_example | 生成TypeScript代码 |
get_quickstart | 获取API快速启动指南 |
添加新API
Click to see how to add your own OpenAPI specs
- 创建目录:
mkdir -p openapi-specs/myapi - 添加您的
myapi.jsonOpenAPI规范 - 复制
apiful.config.ts和index.ts从openapi-specs/ory/作为模板 - 跑
pnpm build
完成!您的API现在可用作 sufetch/myapi 在MCP服务器中。
看 CLAUDE.md 详细说明。
发展
pnpm install # Install
pnpm build # Build
pnpm test # Test
pnpm lint:fix # Lint看 CLAUDE.md 架构、构建管道和贡献指南。
故障排除
MCP Server not showing?
# Test server works
sufetch-mcp # Should output: "SuFetch MCP server running on stdio"
# Check config
claude mcp list # For Claude Code
cat .mcp.json # Check file exists
# Restart Claude Desktop (if using Desktop)Build issues?
rm -rf node_modules pnpm-lock.yaml dist
pnpm install && pnpm build还在卡住吗? 打开一个问题 包含您的节点版本和错误消息。
贡献
欢迎投稿!看 贡献.md.
git clone https://github.com/productdevbook/sufetch.git
cd sufetch
pnpm install && pnpm build
# Make changes, run `pnpm test && pnpm lint:fix`链接
许可证
麻省理工学院©2025
______________________________________________________________________
