MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / parseWorkspaceListJSON

Function parseWorkspaceListJSON

internal/mcp/dispatch.go:345–365  ·  view source on GitHub ↗

parseWorkspaceListJSON decodes the JSON shape `pad workspace list --format json` emits into the WorkspaceHint slice. Lenient about optional fields — only `slug` is required; everything else gets zero values when absent.

(body string)

Source from the content-addressed store, hash-verified

343// optional fields — only `slug` is required; everything else gets
344// zero values when absent.
345func parseWorkspaceListJSON(body string) ([]WorkspaceHint, error) {
346 body = strings.TrimSpace(body)
347 if body == "" || body == "null" {
348 return nil, nil
349 }
350 var raw []map[string]any
351 if err := json.Unmarshal([]byte(body), &raw); err != nil {
352 return nil, fmt.Errorf("decode workspace list: %w", err)
353 }
354 out := make([]WorkspaceHint, 0, len(raw))
355 for _, w := range raw {
356 slug, _ := w["slug"].(string)
357 if slug == "" {
358 continue
359 }
360 name, _ := w["name"].(string)
361 isDefault, _ := w["default"].(bool)
362 out = append(out, WorkspaceHint{Slug: slug, Name: name, Default: isDefault})
363 }
364 return out, nil
365}
366
367// BuildCLIArgs translates an MCP tool call's JSON arguments into the
368// CLI argument list that should be appended after the command path.

Callers 2

ListWorkspacesMethod · 0.85

Calls 2

appendFunction · 0.85
makeFunction · 0.50

Tested by 1