@aibuilders/mcp-coach-server 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 AI Builders
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # AI Builders MCP Coach Server
2
+
3
+ MCP服务器作为AI部署教练,通过标准化接口向AI传授部署知识、API调用方法和最佳实践。
4
+
5
+ ## 核心功能
6
+
7
+ - **get_api_specification()**: 获取AI Builders平台的OpenAPI规范和endpoint信息
8
+ - **get_deployment_guide()**: 获取部署指导(带缓存机制)
9
+ - **explain_authentication_model()**: 详细解释认证机制和使用最佳实践
10
+ - **get_auth_token()**: 返回环境中的 AI_BUILDER_TOKEN(默认打码)
11
+ - **create_env_file()**: 在指定目录创建包含 AI_BUILDER_TOKEN 的 .env 文件
12
+
13
+ ## 本地开发和使用
14
+
15
+ ### 快速开始(开发模式)
16
+
17
+ ```bash
18
+ # 1. 克隆项目
19
+ git clone <repository-url>
20
+ cd student_portal_mcp
21
+
22
+ # 2. 安装依赖
23
+ npm install
24
+
25
+ # 3. 配置环境变量
26
+ cp .env.example .env
27
+ # 编辑 .env 文件,添加你的 AI_BUILDER_TOKEN
28
+
29
+ # 4. 运行开发服务器
30
+ npm run dev
31
+ ```
32
+
33
+ ### 使用MCP Inspector测试
34
+
35
+ ```bash
36
+ # 安装Inspector
37
+ npm install -g @modelcontextprotocol/inspector
38
+
39
+ # 运行Inspector(在另一个终端)
40
+ mcp-inspector
41
+
42
+ # 在Inspector界面中,选择以下任一方式:
43
+ # 方式1(推荐): npx tsx /Users/grapeot/co/student_portal_mcp/src/index.ts
44
+ # 方式2: node /Users/grapeot/co/student_portal_mcp/dist/index.js
45
+ # 然后点击 Connect
46
+ ```
47
+
48
+ ### 正式发布后使用
49
+
50
+ 等发布到npm后,可以这样使用:
51
+
52
+ ```bash
53
+ # 安装
54
+ npm install -g @ai-builders/mcp-coach-server
55
+
56
+ # 运行
57
+ npx @ai-builders/mcp-coach-server
58
+ ```
59
+
60
+ ### 配置到AI编辑器
61
+
62
+ 在Claude Desktop配置文件中添加:
63
+
64
+ ```json
65
+ {
66
+ "mcpServers": {
67
+ "ai-builders-coach": {
68
+ "command": "npx",
69
+ "args": ["tsx", "/Users/grapeot/co/student_portal_mcp/src/index.ts"],
70
+ "env": {
71
+ "AI_BUILDER_TOKEN": "your_token_here"
72
+ }
73
+ }
74
+ }
75
+ }
76
+ ```
77
+
78
+ ## 工具使用示例
79
+
80
+ ```json
81
+ {
82
+ "tool": "get_api_specification",
83
+ "arguments": {}
84
+ }
85
+ ```
86
+
87
+ 返回内容为英文,并包含:
88
+ - `endpoint_info.base_url`(自动从 OpenAPI servers 推断)
89
+ - `sdk_compatibility.openai_sdk_compatible`(标注兼容 OpenAI SDK)
90
+ - 示例:`/v1/chat/completions`
91
+
92
+ ```json
93
+ {
94
+ "tool": "get_auth_token",
95
+ "arguments": { "masked": true }
96
+ }
97
+ ```
98
+
99
+ 返回打码后的 token;若需要写入 .env:
100
+
101
+ ```json
102
+ {
103
+ "tool": "create_env_file",
104
+ "arguments": { "target_dir": "/path/to/project", "overwrite": false }
105
+ }
106
+ ```
107
+
108
+ ## 开发
109
+
110
+ ```bash
111
+ # 克隆项目
112
+ git clone <repository-url>
113
+ cd ai-builders-mcp-coach
114
+
115
+ # 安装依赖
116
+ npm install
117
+
118
+ # 开发模式运行
119
+ npm run dev
120
+
121
+ # 构建
122
+ npm run build
123
+ ```
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,314 @@
1
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
4
+ import dotenv from "dotenv";
5
+ import { readFile, writeFile, access, mkdir } from "fs/promises";
6
+ import { join } from "path";
7
+ import { homedir } from "os";
8
+ dotenv.config();
9
+ const CACHE_DIR = join(homedir(), ".ai-builders-mcp-cache");
10
+ const DEPLOYMENT_GUIDE_CACHE = join(CACHE_DIR, "deployment_guide_cache.json");
11
+ async function ensureCacheDir() {
12
+ try {
13
+ await access(CACHE_DIR);
14
+ }
15
+ catch {
16
+ await mkdir(CACHE_DIR, { recursive: true });
17
+ }
18
+ }
19
+ function getDefaultDeploymentGuide(serviceType = "fastapi") {
20
+ return `# ${serviceType.toUpperCase()} Service Deployment Guide
21
+
22
+ ## Prerequisites
23
+ - Public GitHub repository
24
+ - Listen on PORT environment variable
25
+ - Include dependency files (requirements.txt/package.json)
26
+
27
+ ## Deployment Steps
28
+ 1. Prepare a Dockerfile
29
+ 2. Configure environment variables
30
+ 3. Set AI_BUILDER_TOKEN
31
+ 4. Deploy to target platform
32
+
33
+ ## Authentication
34
+ - Use Bearer Token authentication
35
+ - Read AI_BUILDER_TOKEN from environment variables
36
+ - Include token in Authorization header
37
+
38
+ ## Environment Example
39
+ \`\`\`bash
40
+ AI_BUILDER_TOKEN=your_token_here
41
+ DEPLOYMENT_TARGET=production
42
+ PORT=8000
43
+ \`\`\`
44
+
45
+ ## Code Example
46
+ \`\`\`python
47
+ import os
48
+
49
+ token = os.getenv("AI_BUILDER_TOKEN")
50
+ headers = {"Authorization": f"Bearer {token}"}
51
+ \`\`\``;
52
+ }
53
+ async function getCachedDeploymentGuide() {
54
+ await ensureCacheDir();
55
+ try {
56
+ const cacheContent = await readFile(DEPLOYMENT_GUIDE_CACHE, 'utf-8');
57
+ const cacheData = JSON.parse(cacheContent);
58
+ const cachedTime = new Date(cacheData.cached_at);
59
+ const now = new Date();
60
+ if (now.getTime() - cachedTime.getTime() < 24 * 60 * 60 * 1000) {
61
+ return cacheData;
62
+ }
63
+ }
64
+ catch {
65
+ }
66
+ try {
67
+ const response = await fetch("https://www.ai-builders.com/resources/students/deployment-prompt.md");
68
+ if (response.ok) {
69
+ const content = await response.text();
70
+ const cacheData = {
71
+ content,
72
+ cached_at: new Date().toISOString(),
73
+ source: "remote"
74
+ };
75
+ try {
76
+ await writeFile(DEPLOYMENT_GUIDE_CACHE, JSON.stringify(cacheData, null, 2));
77
+ }
78
+ catch (error) {
79
+ console.error("Cache write failed:", error);
80
+ }
81
+ return cacheData;
82
+ }
83
+ }
84
+ catch (error) {
85
+ console.error("Failed to fetch remote deployment guide:", error);
86
+ }
87
+ return {
88
+ content: getDefaultDeploymentGuide(),
89
+ cached_at: new Date().toISOString(),
90
+ source: "default"
91
+ };
92
+ }
93
+ const server = new Server({
94
+ name: "ai-builders-coach",
95
+ version: "1.0.0",
96
+ }, {
97
+ capabilities: {
98
+ tools: {},
99
+ },
100
+ });
101
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
102
+ const { name, arguments: args } = request.params;
103
+ try {
104
+ switch (name) {
105
+ case "get_api_specification": {
106
+ const response = await fetch("https://www.ai-builders.com/resources/students-backend/openapi.json");
107
+ if (!response.ok) {
108
+ throw new Error(`Failed to fetch OpenAPI specification: HTTP ${response.status}`);
109
+ }
110
+ const openapiSpec = await response.json();
111
+ let baseUrl = "https://www.ai-builders.com/resources/students-backend";
112
+ try {
113
+ if (openapiSpec?.servers?.length) {
114
+ const url = openapiSpec.servers[0].url;
115
+ if (url.startsWith("http")) {
116
+ baseUrl = url;
117
+ }
118
+ else {
119
+ baseUrl = `https://www.ai-builders.com${url}`;
120
+ }
121
+ }
122
+ }
123
+ catch { }
124
+ return {
125
+ content: [
126
+ {
127
+ type: "text",
128
+ text: JSON.stringify({
129
+ openapi_spec: openapiSpec,
130
+ endpoint_info: {
131
+ base_url: baseUrl,
132
+ description: "Base URL for the AI Builders API",
133
+ note: "All API calls should use this base URL"
134
+ },
135
+ authentication: {
136
+ type: "bearer_token",
137
+ header: "Authorization: Bearer {AI_BUILDER_TOKEN}",
138
+ token_source: "Environment variable AI_BUILDER_TOKEN"
139
+ },
140
+ sdk_compatibility: {
141
+ openai_sdk_compatible: true,
142
+ recommendation: "We strongly recommend using the OpenAI SDK to interact with this API. It provides a clean, well-documented interface and handles authentication automatically.",
143
+ usage_note: "You can use OpenAI-compatible SDKs against this API. The OpenAI SDK is the recommended approach.",
144
+ example_node: {
145
+ baseURL: baseUrl,
146
+ endpoint: "/v1/chat/completions",
147
+ code_example: `import OpenAI from 'openai';\n\nconst openai = new OpenAI({\n baseURL: '${baseUrl}',\n apiKey: process.env.AI_BUILDER_TOKEN,\n});\n\nconst completion = await openai.chat.completions.create({\n model: 'gpt-4',\n messages: [{ role: 'user', content: 'Hello!' }],\n});`
148
+ },
149
+ example_python: {
150
+ code_example: `from openai import OpenAI\nimport os\n\nclient = OpenAI(\n base_url='${baseUrl}',\n api_key=os.getenv('AI_BUILDER_TOKEN')\n)\n\ncompletion = client.chat.completions.create(\n model='gpt-4',\n messages=[{'role': 'user', 'content': 'Hello!'}]\n)`
151
+ }
152
+ },
153
+ mcp_recommendation: {
154
+ note: "If running via an MCP server, call get_auth_token to retrieve AI_BUILDER_TOKEN and configure your environment manually",
155
+ tools: ["get_auth_token"],
156
+ env_key: "AI_BUILDER_TOKEN"
157
+ }
158
+ }, null, 2)
159
+ }
160
+ ]
161
+ };
162
+ }
163
+ case "get_deployment_guide": {
164
+ const serviceType = args?.service_type || "fastapi";
165
+ const cachedGuide = await getCachedDeploymentGuide();
166
+ return {
167
+ content: [
168
+ {
169
+ type: "text",
170
+ text: JSON.stringify({
171
+ deployment_guide: cachedGuide.content,
172
+ service_type: serviceType,
173
+ cached_at: cachedGuide.cached_at,
174
+ source: cachedGuide.source,
175
+ authentication_note: "Both deployment and development require AI_BUILDER_TOKEN; manage it via a .env file"
176
+ }, null, 2)
177
+ }
178
+ ]
179
+ };
180
+ }
181
+ case "explain_authentication_model": {
182
+ return {
183
+ content: [
184
+ {
185
+ type: "text",
186
+ text: JSON.stringify({
187
+ authentication_model: {
188
+ token_type: "AI_BUILDER_TOKEN",
189
+ usage_scenarios: ["deployment", "development", "api_calls"],
190
+ shared_principle: "Use the same token for both deployment and development",
191
+ best_practices: [
192
+ ".env file management",
193
+ "Do not hardcode tokens",
194
+ "Add .env to .gitignore",
195
+ "Use different tokens per environment"
196
+ ]
197
+ },
198
+ environment_setup: {
199
+ example_env_content: "AI_BUILDER_TOKEN=your_token_here\nDEPLOYMENT_TARGET=development",
200
+ loading_method: "Load environment variables using dotenv or similar",
201
+ usage_example: `import os\nfrom dotenv import load_dotenv\n\nload_dotenv()\n\ntoken = os.getenv("AI_BUILDER_TOKEN")\nheaders = {"Authorization": f"Bearer {token}"}`
202
+ },
203
+ deployment_note: "Platforms may inject AI_BUILDER_TOKEN at deploy time; set it manually during development"
204
+ }, null, 2)
205
+ }
206
+ ]
207
+ };
208
+ }
209
+ case "get_auth_token": {
210
+ const masked = args?.masked !== false;
211
+ const token = process.env.AI_BUILDER_TOKEN || "";
212
+ const available = !!token;
213
+ let value = token;
214
+ if (masked && token) {
215
+ const start = token.slice(0, 4);
216
+ const end = token.slice(-4);
217
+ value = `${start}${"*".repeat(Math.max(0, token.length - 8))}${end}`;
218
+ }
219
+ return {
220
+ content: [
221
+ {
222
+ type: "text",
223
+ text: JSON.stringify({
224
+ available,
225
+ token: value,
226
+ masked,
227
+ note: available
228
+ ? "Use this token to configure your .env as AI_BUILDER_TOKEN"
229
+ : "AI_BUILDER_TOKEN is not set in server environment"
230
+ }, null, 2)
231
+ }
232
+ ]
233
+ };
234
+ }
235
+ default:
236
+ throw new Error(`Unknown tool: ${name}`);
237
+ }
238
+ }
239
+ catch (error) {
240
+ const errorMessage = error instanceof Error ? error.message : String(error);
241
+ return {
242
+ content: [
243
+ {
244
+ type: "text",
245
+ text: JSON.stringify({
246
+ error: errorMessage,
247
+ suggestion: "Check network connection or retry later"
248
+ })
249
+ }
250
+ ],
251
+ isError: true
252
+ };
253
+ }
254
+ });
255
+ server.setRequestHandler(ListToolsRequestSchema, async () => {
256
+ return {
257
+ tools: [
258
+ {
259
+ name: "get_api_specification",
260
+ description: "Retrieve the OpenAPI specification with endpoint details",
261
+ inputSchema: {
262
+ type: "object",
263
+ properties: {}
264
+ }
265
+ },
266
+ {
267
+ name: "get_deployment_guide",
268
+ description: "Get deployment guidance with caching",
269
+ inputSchema: {
270
+ type: "object",
271
+ properties: {
272
+ service_type: {
273
+ type: "string",
274
+ description: "Service type (e.g., fastapi, express)",
275
+ default: "fastapi"
276
+ }
277
+ }
278
+ }
279
+ },
280
+ {
281
+ name: "explain_authentication_model",
282
+ description: "Explain authentication model for shared deployment and development use",
283
+ inputSchema: {
284
+ type: "object",
285
+ properties: {}
286
+ }
287
+ },
288
+ {
289
+ name: "get_auth_token",
290
+ description: "Return AI_BUILDER_TOKEN from environment (masked by default)",
291
+ inputSchema: {
292
+ type: "object",
293
+ properties: {
294
+ masked: {
295
+ type: "boolean",
296
+ description: "Return masked token if true",
297
+ default: true
298
+ }
299
+ }
300
+ }
301
+ }
302
+ ]
303
+ };
304
+ });
305
+ async function main() {
306
+ const transport = new StdioServerTransport();
307
+ await server.connect(transport);
308
+ console.error("AI Builders MCP Coach Server started");
309
+ }
310
+ main().catch((error) => {
311
+ console.error("Server failed to start:", error);
312
+ process.exit(1);
313
+ });
314
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@aibuilders/mcp-coach-server",
3
+ "version": "1.0.0",
4
+ "description": "MCP server as AI deployment coach for AI Builders platform",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "bin": {
8
+ "mcp-coach-server": "dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsx src/index.ts",
13
+ "start": "node dist/index.js",
14
+ "test": "tsx src/test.ts",
15
+ "prepublishOnly": "npm run build"
16
+ },
17
+ "keywords": [
18
+ "mcp",
19
+ "model-context-protocol",
20
+ "ai",
21
+ "deployment",
22
+ "coach",
23
+ "ai-builders"
24
+ ],
25
+ "author": "AI Builders",
26
+ "license": "MIT",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {
31
+ "@modelcontextprotocol/sdk": "^0.5.0",
32
+ "dotenv": "^16.4.5"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^20.11.0",
36
+ "tsx": "^4.7.0",
37
+ "typescript": "^5.3.3"
38
+ },
39
+ "files": [
40
+ "dist/index.js",
41
+ "dist/index.d.ts",
42
+ "README.md",
43
+ "LICENSE"
44
+ ]
45
+ }