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

Function parseWorkspaceListJSON

internal/mcp/dispatch.go:316–336  ·  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

314// optional fields — only `slug` is required; everything else gets
315// zero values when absent.
316func parseWorkspaceListJSON(body string) ([]WorkspaceHint, error) {
317 body = strings.TrimSpace(body)
318 if body == "" || body == "null" {
319 return nil, nil
320 }
321 var raw []map[string]any
322 if err := json.Unmarshal([]byte(body), &raw); err != nil {
323 return nil, fmt.Errorf("decode workspace list: %w", err)
324 }
325 out := make([]WorkspaceHint, 0, len(raw))
326 for _, w := range raw {
327 slug, _ := w["slug"].(string)
328 if slug == "" {
329 continue
330 }
331 name, _ := w["name"].(string)
332 isDefault, _ := w["default"].(bool)
333 out = append(out, WorkspaceHint{Slug: slug, Name: name, Default: isDefault})
334 }
335 return out, nil
336}
337
338// BuildCLIArgs translates an MCP tool call's JSON arguments into the
339// CLI argument list that should be appended after the command path.

Callers 2

ListWorkspacesMethod · 0.85

Calls

no outgoing calls

Tested by 1