MCPcopy Create free account
hub / github.com/github/gh-aw / ParseMCPConfig

Function ParseMCPConfig

pkg/parser/mcp.go:417–456  ·  view source on GitHub ↗

ParseMCPConfig parses MCP configuration from various formats (map or JSON string)

(toolName string, mcpSection any, toolConfig map[string]any)

Source from the content-addressed store, hash-verified

415
416// ParseMCPConfig parses MCP configuration from various formats (map or JSON string)
417func ParseMCPConfig(toolName string, mcpSection any, toolConfig map[string]any) (RegistryMCPServerConfig, error) {
418 mcpLog.Printf("Parsing MCP configuration for tool: %s", toolName)
419 config := RegistryMCPServerConfig{
420 BaseMCPServerConfig: types.BaseMCPServerConfig{
421 Env: make(map[string]string),
422 Headers: make(map[string]string),
423 },
424 Name: toolName,
425 }
426
427 appendBuiltinAllowedTools(&config, toolConfig)
428 mcpConfig, err := parseMCPSectionMap(mcpSection, toolName)
429 if err != nil {
430 return config, err
431 }
432
433 config.Type, err = inferOrReadMCPType(mcpConfig, toolName)
434 if err != nil {
435 return config, err
436 }
437 if err := parseMCPRegistryValue(mcpConfig, toolName, &config); err != nil {
438 return config, err
439 }
440
441 mcpLog.Printf("Extracting %s configuration for tool: %s", config.Type, toolName)
442 switch config.Type {
443 case "stdio":
444 if err := parseMCPStdioTypeConfig(mcpConfig, toolName, &config); err != nil {
445 return config, err
446 }
447 case "http":
448 if err := parseMCPHTTPTypeConfig(mcpConfig, toolName, &config); err != nil {
449 return config, err
450 }
451 default:
452 return config, fmt.Errorf("unsupported MCP type '%s' for tool '%s'. Valid types are: stdio, http. Example:\nmcp-servers:\n %s:\n type: stdio\n command: \"npx @my/tool\"\n args: [\"--port\", \"3000\"]", config.Type, toolName, toolName)
453 }
454
455 return config, nil
456}
457
458func parseMCPSectionMap(mcpSection any, toolName string) (map[string]any, error) {
459 switch v := mcpSection.(type) {

Calls 8

parseMCPSectionMapFunction · 0.85
inferOrReadMCPTypeFunction · 0.85
parseMCPRegistryValueFunction · 0.85
parseMCPStdioTypeConfigFunction · 0.85
parseMCPHTTPTypeConfigFunction · 0.85
PrintfMethod · 0.45
ErrorfMethod · 0.45