Skip to content

Conversation

@betterclever
Copy link
Contributor

@betterclever betterclever commented Jan 24, 2026

Overview

Implements ENG-132 tool-mode orchestration end-to-end: tool-mode nodes bind to agents via graph edges, agents discover tools through the MCP gateway at runtime, and tool execution is scoped per agent to only the connected tool nodes.

Key Changes

DSL + Compiler + Temporal

  • Add connectedToolNodeIds metadata and expose an agent tools port for graph binding.
  • Compiler populates connectedToolNodeIds from tool→agent tools port edges (virtual tools port support).
  • Temporal workflow passes tool binding metadata into component execution context.

Backend MCP Gateway

  • Registry/gateway filtering by allowed node IDs and session-scoped access.
  • Session token includes allowedNodeIds for per-agent tool visibility.
  • Gateway tool discovery stabilized with nodeId-based scoping and caching.

Worker + Agent

  • ToolLoopAgent now discovers tools via MCP gateway and executes tool calls through it.
  • Tool schema handling aligned (MCP input/output normalization + string output handling).
  • Agent tests updated to match the new schema expectations.

Tests + Cleanup

  • Align ai-agent tests with schema expectations.
  • E2E tool-mode orchestration coverage (agent-tool-mode).
  • Remove interim ENG-132/Zod migration docs and debug log noise after validation.

Commits (Chronological)

  • 226dcea docs: add ENG-132 tool mode orchestration implementation plan
  • bae5b7f feat(dsl): add connectedToolNodeIds metadata and agent tools port
  • 5160bb4 feat(compiler): track tool->agent edges and handle virtual tools port
  • 0117af4 feat(temporal): pass connectedToolNodeIds to agent execution context
  • 80b6fbf feat(gateway): implement nodeId-based tool scoping and session API
  • 7260cb1 feat(worker): propagate tool binding metadata to component context
  • 8ad0133 feat(agent): implement gateway-based tool discovery and execution
  • 63185b4 fix(mcp): implement multi-agent tool scoping and gateway-based discovery
  • 2e19ea3 fix(agent): ensure tool execution returns string values
  • 45d79a1 chore(logging): implement structured file-based debug logging
  • 3603558 docs: add comprehensive ENG-132 implementation summary
  • 7a7adce feat(logging): add detailed tool execution debug logging
  • c96e64a committed the changes.
  • a16c969 refactor: rework ai agent mcp tools
  • 498dacf test: align ai agent tests with schemas
  • 9d9aa50 fix: stabilize mcp tool discovery
  • 881a62e fix: align mcp tool schemas and agent logging
  • 4be4bb2 chore: remove ai agent debug logs
  • 9e18750 chore: remove eng-132 interim docs

Testing

  • RUN_E2E=true bun test e2e-tests/agent-tool-mode.test.ts (user-reported pass)

@betterclever betterclever changed the title chore: remove eng-132 interim docs feat: implement tool-mode orchestration (ENG-132) Jan 24, 2026
@betterclever betterclever force-pushed the eng-132/tool-mode-orchestration branch from 9e18750 to 0e50bc2 Compare January 24, 2026 14:20
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e1875057c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +48 to +51
const cacheKey =
allowedNodeIds && allowedNodeIds.length > 0
? `${runId}:${allowedNodeIds.sort().join(',')}`
: runId;

Choose a reason for hiding this comment

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

P2 Badge Clean up scoped MCP servers keyed by allowedNodeIds

This change stores MCP servers under a cache key that includes allowedNodeIds, but cleanupRun(runId) (and the controller’s disconnect handler) still deletes by runId only. That means any agent run that uses scoped tools will leave its server instance in memory forever, because the key no longer matches. Consider updating cleanupRun to remove all entries for the run (or accept the same cache key) so scoped servers are closed on disconnect.

Useful? React with 👍 / 👎.

Detailed plan for enabling graph-based tool→agent binding:
- Phase 1: Compiler tracks tool→agent edges
- Phase 2: Runtime passes connectedToolNodeIds to agent
- Phase 3: Agent queries MCP Gateway for tools
- Phase 4: Gateway filters tools by nodeIds
- Phase 5: E2E tests

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Phase 1 of ENG-132:
- Added connectedToolNodeIds to WorkflowNodeMetadata (backend/worker)
- Added tools input port to AI agent component
- Included connectedToolNodeIds in RunComponentActivityInput metadata

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Phase 2 of ENG-132:
- Modified compiler to collect connectedToolNodeIds from graph edges
- Updated validator to allow multiple edges to 'tools' port
- Virtualized 'tools' output port for nodes in tool mode
- Updated DTO schemas to support tool mode metadata
- Added unit test to verify tool->agent binding

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Phase 3 of ENG-132:
- Updated shipsecWorkflowRun to extract connectedToolNodeIds from node metadata
- Included connectedToolNodeIds in activity metadata for agent discovery
- Synchronized worker types for workflow execution

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Phase 4 of ENG-132:
- Added nodeIds filter to ToolRegistryService.getToolsForRun
- Updated McpGatewayService to support tool scoping by nodeId
- Included allowedNodeIds in session token and metadata
- Updated InternalMcpController to allow scoped token generation

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Phase 3 of ENG-132:
- Updated ExecutionContextMetadata to include connectedToolNodeIds and organizationId
- Modified runComponentActivity to inject metadata into the execution context
- Ensured organizationId is available for agent tool discovery

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Phase 5 of ENG-132:
- Added McpGatewayClient support to AI agent component
- Implemented runtime tool discovery via MCP Gateway
- Scoped tool discovery using connectedToolNodeIds
- Integrated discovered tools with agent reasoning loop
- Added session token generation helper

Linear-issue: ENG-132
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
- Add ApiKeysModule import to McpModule to fix DI issues
- Cache gateway servers/transports by runId + allowedNodeIds for agent isolation
- Implement buildMcpToolSchema to convert JSON Schema to Zod format
- Fix MCP tool content handling (extract text from array results)
- Add proper imports for StreamableHTTPClientTransport and Client

Tests now pass:
- Agent can run with no tools
- Multiple agents have isolated tool sets based on graph connections

This enables workflow graphs to connect tool-mode nodes directly to agents,
with the agent automatically discovering and using only its connected tools.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
- Explicitly type tool execution to return Promise<string>
- Add comprehensive fallback conversions for tool result content
- Handle all formats: arrays, strings, objects, primitives
- Update test to use more reliable httpbin.org endpoint

Tool discovery is working correctly (tests 1 & 3 pass).
Test 2 fails due to tool execution issues, not discovery.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
- Create DebugLogger utility for structured JSON logging to /tmp/shipsec-debug/
- Separate heartbeat logs to dedicated file (not printed to console)
- Add view-debug-logs.ts script for easy log viewing/filtering
- Convert agent gateway functions to use DebugLogger
- Remove verbose console heartbeat logs (15-second polling logs)
- Add getRecentLogs, getLogsByContext, getLogsByLevel utilities

Benefits:
- Cleaner console output (no heartbeat spam)
- All debug context centralized in one place
- Easy filtering by context, level, or search terms
- Structured JSON format for programmatic access

Debug logs now available at: /tmp/shipsec-debug/worker.log
Usage: bun scripts/view-debug-logs.ts [filter] [line-count]

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
- Log tool invocation arguments to debug-logger
- Log MCP result type and content before conversion
- Log final tool execution result with preview
- Log errors with stack traces for debugging

Root cause identified in Test 2: MCP protocol timeout on external endpoint
The tool is called successfully, gateway discovery works,
but the MCP callTool() times out waiting for the HTTP endpoint response.
This is NOT a tool discovery or integration issue - it's endpoint latency.

Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
Signed-off-by: betterclever <paliwal.pranjal83@gmail.com>
@betterclever betterclever force-pushed the eng-132/tool-mode-orchestration branch from 0e50bc2 to d3f56bf Compare January 24, 2026 14:24
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