Skip to content

Bound relation output: paginate list_relations, cap get_document relations and the cascade advisory #26

Description

@ivklgn

Summary

Relation data sent to the agent has no size limit. This breaks .archcore/code-quality/bounded-and-deterministic-output.rule.md: clause 1 (an MCP tool response and session context must be bounded by a named constant), clause 3 (order before cutting), and clause 6 (the ceiling is stated in the contract the caller reads).

The issue is real at current scale. In this repository, an unfiltered list_relations returns 41.9 KB for 326 relations, about 10–12K tokens. That already exceeds the budget list_documents protects.

Write-path performance moved to #33. Graph-shape analysis and the needs-design items stay in .archcore/mcp/relation-write-path-graph-growth.idea.md.

Current behavior (v0.8.3)

  • list_relations with no path returns m.Relations in full, with no cap and no truncated flag (internal/mcp/tools/list_relations.go:40-41).
  • m.Relations is in insertion order, not sorted, so a cut would not be deterministic.
  • get_document returns all incoming and outgoing relations with no cap (internal/mcp/tools/get_document.go:79-91).
  • The post-tool-use cascade advisory lists every incoming dependent with no cap (cmd/hook_post_tool_use.go:96-104). This is session context.
  • list_documents already implements the pattern: listDefaultLimit = 100, listMaxLimit = 500, clamped limit, errors on negative limit or offset, an envelope struct, and the ceiling stated in the tool description (internal/mcp/tools/list_documents.go:15-68).

Scope

  • list_relations: add limit and offset, and return {relations, total, offset, returned, truncated}, mirroring list_documents. Use named constants with a doc comment that names the budget.
  • list_relations: sort by (source, target, type) before cutting. Apply the same cap when path is set.
  • list_relations: state the ceiling and the envelope in the tool description.
  • get_document: cap the incoming and outgoing relation lists with a named constant, and report truncation. State it in the tool description.
  • Cascade advisory: cap the listed dependents with a named constant, and add a "+N more" line.
  • Update internal/mcp/tools/list_relations_test.go. It decodes into map[string][]sync.Relation and breaks once the envelope has non-array fields. Add table-driven cases for the cap, the offset, and the ordering.
  • Plugin repository: update the "full relation graph" wording in the archcore-auditor and archcore-assistant agents to describe pagination.

Files: internal/mcp/tools/list_relations.go, internal/mcp/tools/get_document.go, cmd/hook_post_tool_use.go (+ tests)

Acceptance: no relation output reaches the agent without a named ceiling. Cut results are deterministic. Each ceiling is visible in the tool description or the advisory text.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestmcpMCP server and toolsperformanceRead-path and scaling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions