MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / readMCPFile

Function readMCPFile

internal/aiagentconfig/builder.go:140–155  ·  view source on GitHub ↗

readMCPFile reads and parses .mcp.json from the given root directory. It resolves symlinks and verifies the file stays inside the root before reading.

(realRoot string)

Source from the content-addressed store, hash-verified

138// readMCPFile reads and parses .mcp.json from the given root directory.
139// It resolves symlinks and verifies the file stays inside the root before reading.
140func readMCPFile(realRoot string) ([]MCPServer, error) {
141 mcpPath := filepath.Join(realRoot, ".mcp.json")
142
143 content, _, err := safeReadFile(mcpPath, realRoot)
144 if err != nil {
145 return nil, err
146 }
147
148 servers, err := ExtractMCPServers(content)
149 if err != nil {
150 log.Debug().Err(err).Str("path", ".mcp.json").Msg("failed to parse MCP servers")
151 return nil, err
152 }
153
154 return servers, nil
155}
156
157// safeReadFile resolves symlinks, verifies the resolved path stays inside rootDir,
158// and reads the file content. Returns the content and the resolved real path.

Callers 1

extractMCPServersFunction · 0.85

Calls 3

safeReadFileFunction · 0.85
ExtractMCPServersFunction · 0.85
DebugMethod · 0.45

Tested by

no test coverage detected