Skip to content

refactor(mcp): relocate tool result envelope into core to clear a layering back-edge#381

Merged
gbrlcustodio merged 1 commit into
devfrom
fix/mcp-core-tools-layering
Jul 9, 2026
Merged

refactor(mcp): relocate tool result envelope into core to clear a layering back-edge#381
gbrlcustodio merged 1 commit into
devfrom
fix/mcp-core-tools-layering

Conversation

@gbrlcustodio

Copy link
Copy Markdown
Member

What

Moves tool_error_envelope from tools/ to core/ so pipefy_mcp.core no longer imports pipefy_mcp.tools.

Why

core/tool_middleware.py (short_circuit_error) imported tools/tool_error_envelope. That is a back-edge against the intended inward-only layering, where tools (an adapter) sits above core. #378 introduced the edge when the tool-call middleware landed on dev. The error/success envelope is the shared result currency used both by the tool adapters and by the core middleware, so its home is core, not tools.

Changes

  • git mv the module to core/tool_error_envelope.py and its unit test to tests/core/.
  • Repoint every importer (26 source modules, 24 tests) from pipefy_mcp.tools.tool_error_envelope to pipefy_mcp.core.tool_error_envelope.
  • Hoist the previously lazy import in short_circuit_error to a top-level import: relocating the module removes the load-time cycle that forced the lazy form.
  • Module content is unchanged, so there is no behavior change.

Relationship to #380

The intra-package import-linter contract lives in #380, not on dev. This fix is what makes that contract pass once #380 rebases onto the updated dev: I verified locally by transiently applying #380's contract (plus its core/__init__.py) and running lint-imports, which reports 1 kept, 0 broken. Two prose spots in #380 still describe the envelope as living under tools/ (the layer-model mapping and the disabled-ratchet comment); those should be refreshed on that branch after this merges.

Testing

core/tool_middleware.short_circuit_error imported
tools/tool_error_envelope, a back-edge against the inward-only layering
where tools sits above core. The error/success envelope is the shared
result currency used both by the tool adapters and by the core
middleware, so it belongs at core, not in tools.

Move the module to core/tool_error_envelope.py (and its test to
tests/core/), repoint every importer, and hoist the previously lazy
import in short_circuit_error now that relocating the module removes the
load-time cycle that forced it. No behavior change: the module content
is untouched.

This clears the pipefy_mcp.core -> pipefy_mcp.tools edge so the
intra-package layering contract holds.
@gbrlcustodio
gbrlcustodio merged commit 0b8ee45 into dev Jul 9, 2026
2 checks passed
@gbrlcustodio
gbrlcustodio deleted the fix/mcp-core-tools-layering branch July 9, 2026 19:11
gbrlcustodio added a commit that referenced this pull request Jul 9, 2026
PR #381 relocated tool_error_envelope.py from tools/ to core/. Refresh
the two spots that still described it under tools/: the domain mapping in
docs/architecture.md and the disabled-ratchet comment in pyproject.toml.
Also name core/tool_middleware.py alongside fastmcp_tool_lifecycle.py as
adapter code that currently lives under core/.
adriannoes added a commit that referenced this pull request Jul 9, 2026
Keep stack-2 observability choices (stderr emitter, INFO pin, HTTP-only
configure) over the #375 stdout/run_server wiring; take #381's tool-error
envelope relocation into core.
@gbrlcustodio gbrlcustodio self-assigned this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant