Skip to content

refactor(agent): nest tool-set and MCP under agent subpaths - #102

Merged
LukasParke merged 14 commits into
mainfrom
agent-subpath-packages
Aug 12, 2026
Merged

refactor(agent): nest tool-set and MCP under agent subpaths#102
LukasParke merged 14 commits into
mainfrom
agent-subpath-packages

Conversation

@LukasParke

@LukasParke LukasParke commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Moves the tool-set implementation into the canonical @openrouter/agent/tool-set subpath and removes the unpublished standalone @openrouter/agent-tool-set package.
  • Moves the full MCP implementation into @openrouter/agent/mcp, with nested /create-mcp-tools, /types, /schema, and /cache exports.
  • Keeps @modelcontextprotocol/sdk as an optional peer of @openrouter/agent, so base agent installs do not pull MCP dependencies.
  • Converts the published @openrouter/mcp package into a thin compatibility facade over the canonical agent subpaths.

GitHub native stack #103: position 2 of 2, above PR #31. GitHub tracks the ordered stack with main as its ultimate base; this PR targets toolkits and contains only 61cca6a and d6b0253 above the parent.

API example

import { callModel, OpenRouter } from '@openrouter/agent';
import { createMCPTools } from '@openrouter/agent/mcp';
import { createToolSet } from '@openrouter/agent/tool-set';

const mcp = await createMCPTools({ url: 'https://mcp.example.com/mcp' });
const tools = createToolSet({ tools: mcp.tools }).resolve();
const result = callModel(new OpenRouter(), {
  model: 'openai/gpt-4o-mini',
  input: 'Use the remote tools.',
  ...tools.callModel,
});

Consumers of /mcp install the optional peer alongside agent:

pnpm add @openrouter/agent @modelcontextprotocol/sdk

Existing @openrouter/mcp root and nested imports continue to work.

Package size / tree shaking

  • @openrouter/agent remains sideEffects: false.
  • The root and /tool-set entries do not statically import MCP modules.
  • A base packed-agent consumer imported root + /tool-set without installing the MCP SDK.
  • Packed size: agent ~293 KB compressed / 1.26 MB unpacked; compatibility facade ~4 KB compressed.

Verification

  • pnpm build
  • pnpm lint
  • pnpm typecheck
  • pnpm test
  • pnpm changeset status
  • Agent + facade tarball inspection
  • Temporary base consumer: root + /tool-set, no MCP SDK installed
  • Temporary MCP consumer: /mcp with optional peer installed
  • Compatibility consumer: @openrouter/mcp root + all legacy nested exports

🤖 Generated with Claude Code

Package-boundary hardening

  • Loads @modelcontextprotocol/sdk lazily and reports an actionable MCPMissingPeerDependencyError only when an MCP connection actually needs a missing peer.
  • Marks @openrouter/mcp and its nested paths as migration facades while preserving every existing import.
  • Documents the complete public subpath surface and adds explicit Sentrux boundaries preventing core agent modules from importing MCP.
  • Adds pnpm verify:packages, which packs both packages, validates every export target and tarball allowlist, installs them into a clean consumer, checks optional-peer isolation, and rejects duplicate/version-skewed agent resolution.
  • Fixes the dynamic FilterToolsByIds<readonly Tool[]> fallback so widened tool IDs do not collapse to never[].

Verification

  • pnpm build
  • pnpm lint
  • pnpm typecheck
  • pnpm test — 779 agent tests and 17 facade tests
  • pnpm verify:packages
  • sentrux gate
  • git diff --check

Open in Devin Review

devin-ai-integration[bot]

This comment was marked as resolved.

perry-the-pr-reviewer[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@LukasParke
LukasParke force-pushed the agent-subpath-packages branch from d6b0253 to ba48ee0 Compare August 7, 2026 19:41
devin-ai-integration[bot]

This comment was marked as resolved.

perry-the-pr-reviewer[bot]

This comment was marked as resolved.

@LukasParke
LukasParke force-pushed the agent-subpath-packages branch from ba48ee0 to 12b986f Compare August 11, 2026 18:25
devin-ai-integration[bot]

This comment was marked as resolved.

@LukasParke
LukasParke force-pushed the agent-subpath-packages branch 2 times, most recently from f60711e to e09f4ec Compare August 11, 2026 19:01
devin-ai-integration[bot]

This comment was marked as resolved.

@LukasParke
LukasParke force-pushed the agent-subpath-packages branch from e09f4ec to 7d0a49d Compare August 11, 2026 20:23
devin-ai-integration[bot]

This comment was marked as resolved.

@LukasParke
LukasParke force-pushed the agent-subpath-packages branch 2 times, most recently from 6a7476e to afc7443 Compare August 11, 2026 21:39
devin-ai-integration[bot]

This comment was marked as resolved.

Base automatically changed from toolkits to main August 12, 2026 02:17
LukasParke and others added 11 commits August 11, 2026 21:17
Move the tool-set and MCP implementations into @openrouter/agent subpath exports while retaining @openrouter/mcp as a compatibility facade. Keep the MCP SDK optional so base agent installs stay lean.

Co-Authored-By: Claude <noreply@anthropic.com>
Load the optional MCP SDK only when a connection is requested and surface an actionable missing-peer error without pulling MCP into root imports. Mark the legacy MCP package as a migration facade and document the complete subpath surface.

Add packed-install, export-map, dependency-version, resolution-condition, and architecture boundary checks. Also preserve widened ToolSet elements in dynamic FilterToolsByIds arrays and activate the maintained declaration fixtures.

Co-Authored-By: Claude <noreply@anthropic.com>
Preserve current main's async-agent behavior while moving ToolSet and the MCP v2 client implementation under agent subpaths. Keep the MCP client as a lazily loaded optional peer, retain protocol negotiation behavior, and relocate implementation tests to the canonical package.

Co-Authored-By: Claude <noreply@anthropic.com>
@LukasParke
LukasParke force-pushed the agent-subpath-packages branch from d94b07b to e39dbd1 Compare August 12, 2026 02:17
@LukasParke
LukasParke merged commit 787cbf8 into main Aug 12, 2026
6 of 7 checks passed
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.

1 participant