api2mcp 0.0.1 → 0.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,138 @@
1
- # api2mcp
1
+ # api2mcp
2
+
3
+ 将 OpenAPI 规范动态转换为 MCP (Model Context Protocol) 工具。
4
+
5
+ ## 特性
6
+
7
+ - 🔧 **动态转换**: 只需配置 OpenAPI 文档 URL,自动将每个 API endpoint 转换为 MCP 工具
8
+ - 📝 **完整支持**: 支持 OpenAPI 3.x 规范,包括路径参数、查询参数、请求体等
9
+ - 🚀 **简单易用**: 通过 CLI 或配置文件快速启动
10
+ - 🔌 **MCP 兼容**: 完全兼容 MCP 协议,可在 Claude Desktop 等 MCP 客户端中使用
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ # 使用 pnpm
16
+ pnpm install
17
+
18
+ # 构建
19
+ pnpm build
20
+ ```
21
+
22
+ ## 使用方法
23
+
24
+ ### CLI
25
+
26
+ ```bash
27
+ # 基本使用
28
+ api2mcp --url https://petstore3.swagger.io/api/v3/openapi.json
29
+
30
+ # 指定基础 URL
31
+ api2mcp --url ./openapi.json --base-url https://api.example.com
32
+
33
+ # 带认证头
34
+ api2mcp --url https://api.example.com/openapi.json --headers '{"Authorization":"Bearer xxx"}'
35
+
36
+ # 带工具前缀
37
+ api2mcp --url https://api.example.com/openapi.json --prefix myapi
38
+
39
+ # 调试模式
40
+ api2mcp --url https://api.example.com/openapi.json --debug
41
+ ```
42
+
43
+ ### CLI 参数
44
+
45
+ | 参数 | 简写 | 说明 |
46
+ |------|------|------|
47
+ | `--url` | `-u` | OpenAPI 文档 URL 或本地文件路径 |
48
+ | `--base-url` | `-b` | API 基础 URL (覆盖 OpenAPI servers) |
49
+ | `--timeout` | `-t` | 请求超时时间 (毫秒) |
50
+ | `--headers` | `-h` | 自定义请求头 (JSON 字符串) |
51
+ | `--prefix` | `-p` | 工具名前缀 |
52
+ | `--debug` | `-d` | 启用调试模式 |
53
+
54
+ ### 配置文件
55
+
56
+ 支持以下配置文件名:
57
+ - `api2mcp.json`
58
+ - `api2mcp.config.json`
59
+ - `.api2mcp.json`
60
+
61
+ 配置文件示例:
62
+
63
+ ```json
64
+ {
65
+ "openapiUrl": "https://api.example.com/openapi.json",
66
+ "baseUrl": "https://api.example.com",
67
+ "timeout": 30000,
68
+ "headers": {
69
+ "Authorization": "Bearer your-token"
70
+ },
71
+ "toolPrefix": "myapi"
72
+ }
73
+ ```
74
+
75
+ ### 环境变量
76
+
77
+ | 环境变量 | 说明 |
78
+ |----------|------|
79
+ | `OPENAPI_URL` | OpenAPI 文档 URL |
80
+ | `API_BASE_URL` | API 基础 URL |
81
+ | `API_TIMEOUT` | 请求超时时间 (毫秒) |
82
+ | `API_HEADERS` | 自定义请求头 (JSON 字符串) |
83
+ | `DEBUG` | 启用调试模式 |
84
+
85
+ ### 在 Claude Desktop 中使用
86
+
87
+ 在 Claude Desktop 配置文件中添加:
88
+
89
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
90
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "api2mcp": {
96
+ "command": "node",
97
+ "args": ["/path/to/api2mcp/bin/api2mcp.js", "--url", "https://api.example.com/openapi.json"]
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ ## 配置优先级
104
+
105
+ 配置加载优先级 (从高到低):
106
+
107
+ 1. CLI 参数
108
+ 2. 环境变量
109
+ 3. 配置文件
110
+
111
+ ## 开发
112
+
113
+ ```bash
114
+ # 安装依赖
115
+ pnpm install
116
+
117
+ # 开发模式 (监听文件变化)
118
+ pnpm dev
119
+
120
+ # 构建
121
+ pnpm build
122
+
123
+ # 类型检查
124
+ pnpm typecheck
125
+ ```
126
+
127
+ ## 技术栈
128
+
129
+ - TypeScript
130
+ - Node.js (>=18)
131
+ - [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) - MCP 协议实现
132
+ - [@apidevtools/swagger-parser](https://github.com/APIDevTools/swagger-parser) - OpenAPI 解析
133
+ - [zod](https://github.com/colinhacks/zod) - Schema 定义
134
+ - [commander](https://github.com/tj/commander.js) - CLI 框架
135
+
136
+ ## License
137
+
138
+ MIT
package/bin/api2mcp.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('../dist/cli.js');