MCPcopy Create free account
hub / github.com/astercloud/aster / demonstrateMCPExtensions

Function demonstrateMCPExtensions

examples/recipe/main.go:136–195  ·  view source on GitHub ↗

演示 MCP 扩展

(tmpDir string)

Source from the content-addressed store, hash-verified

134
135// 演示 MCP 扩展
136func demonstrateMCPExtensions(tmpDir string) {
137 fmt.Println("\n📋 MCP 扩展配置")
138 fmt.Println(repeatStr("-", 50))
139
140 yamlContent := `
141version: "1.0"
142title: GitHub Assistant
143description: 集成 GitHub 的代码助手
144
145extensions:
146 - type: stdio
147 name: github
148 description: GitHub API 集成
149 cmd: npx
150 args:
151 - "-y"
152 - "@anthropics/mcp-github"
153 env:
154 GITHUB_TOKEN: "${GITHUB_TOKEN}"
155 timeout: 30
156 enabled: true
157
158 - type: sse
159 name: search
160 description: 搜索服务
161 url: http://localhost:3000/mcp
162 timeout: 10
163 enabled: true
164
165 - type: builtin
166 name: filesystem
167 description: 文件系统工具
168 enabled: true
169
170tools:
171 - Read
172 - Write
173 - Search
174`
175
176 yamlPath := filepath.Join(tmpDir, "github-assistant.yaml")
177 if err := os.WriteFile(yamlPath, []byte(yamlContent), 0644); err != nil {
178 log.Fatalf("写入 YAML 失败: %v", err)
179 }
180
181 r, err := recipe.LoadFromFile(yamlPath)
182 if err != nil {
183 log.Fatalf("加载 Recipe 失败: %v", err)
184 }
185
186 fmt.Printf(" ✓ 加载带 MCP 扩展的 Recipe\n")
187 fmt.Printf("\n 🔌 MCP 扩展:\n")
188 for _, ext := range r.Extensions {
189 enabled := "✓"
190 if ext.Enabled != nil && !*ext.Enabled {
191 enabled = "✗"
192 }
193 fmt.Printf(" [%s] %s (%s) - %s\n", enabled, ext.Name, ext.Type, ext.Description)

Callers 1

mainFunction · 0.85

Calls 4

LoadFromFileFunction · 0.92
PrintfMethod · 0.80
repeatStrFunction · 0.70
JoinMethod · 0.45

Tested by

no test coverage detected