Skip to content

fix: convert MCP query/analyze/context responses from JSON to formatted text#8

Open
ulascanzorer wants to merge 1 commit intomainfrom
feat/mcp-text-responses
Open

fix: convert MCP query/analyze/context responses from JSON to formatted text#8
ulascanzorer wants to merge 1 commit intomainfrom
feat/mcp-text-responses

Conversation

@ulascanzorer
Copy link
Copy Markdown
Collaborator

@ulascanzorer ulascanzorer commented Apr 10, 2026

Summary

Convert mymir_query, mymir_analyze, and mymir_context (summary depth) MCP tool responses from raw JSON to pre-formatted markdown text. Reduces token consumption by 30-50% in agent context windows. Mutation tools (mymir_project, mymir_task, mymir_edge) intentionally kept as JSON since agents need returned IDs for follow-up calls.

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Documentation

Testing

  • Tested locally with bun run dev
  • Linting passes (bun run lint)
  • Typecheck passes (bun run typecheck)

Notes for reviewer

  • Added text() helper alongside existing json() in helpers.ts
  • New formatters.ts with 11 formatter functions (one per response shape)
  • analyze.ts, query.ts, context.ts updated to use formatters instead of json()
  • Shared handlers in lib/ai/tool-handlers.ts unchanged — web app still gets structured objects

@ulascanzorer ulascanzorer self-assigned this Apr 10, 2026
@ulascanzorer ulascanzorer requested a review from FrkAk as a code owner April 10, 2026 14:23
decisionsCount: number;
hasImplementationPlan: boolean;
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] Missing JSDoc. All 11 exported functions in this file need @param/@returns docstrings.

// ---------------------------------------------------------------------------
// Context: summary
// ---------------------------------------------------------------------------

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] These local types duplicate handler return shapes. Please, import from tool-handlers.ts

critical_path: formatCriticalPath,
plannable: formatPlannableTasks,
} as const;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] as any bypasses type safety. Please consider a discriminated union on type to properly narrow result.data.

};

export function formatBlockedTasks(data: BlockedTask[]): string {
if (data.length === 0) return "# Blocked Tasks (0)\n\nNo blocked tasks.";
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] Inconsistent empty states: plain sentences (lines 75, 107, 132) vs heading+sentence (lines 267, 285, 301). Please, pick one pattern.

  • Plain sentence: lines 75, 107, 132 ("No results found.", "No tasks.", "No edges.")
  • Heading + sentence: lines 267, 285, 301 ("# Blocked Tasks (0)\n\nNo blocked tasks.")

Comment on lines +55 to +57
// ---------------------------------------------------------------------------
// Query: search
// ---------------------------------------------------------------------------
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] please remove all the inline comments

edges: formatEdges,
overview: formatOverview,
} as const;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] same concern, lets try to avoid any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants