refactor(mcp): plugin registry + AgentMarkPlugin contract - #22
Merged
Conversation
Replace the monolithic switch-based dispatcher with a plugin registry so external packs (Microsoft Workflows, Insurance, etc.) can register MCP tools using the same API as built-in capabilities. First-party features (web, pdf, desktop, meta) are extracted into plugin factories that the default dispatcher composes automatically. The public functional API (`dispatch`, `createDispatcherState`, `disposeAll`, `DispatcherState`, `ALL_TOOLS`, `createMcpServer`) is preserved as a thin shim over the new `Dispatcher` class. No test changes were required; all 317 prior tests + 9 new plugin-contract tests pass. New public exports (from '@thinkfleet/agentmark' or its '/mcp' subpath): - `AgentMarkPlugin`, `ToolHandler`, `DispatchResult` — plugin types - `Dispatcher` — the registry/router class - `createWebPlugin`, `createPdfPlugin`, `createDesktopPlugin`, `createMetaPlugin` — factories so packs can compose their own server Server now accepts `plugins?: AgentMarkPlugin[]` to override the default set; tools are sourced from the registry rather than a static array. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AgentMarkPlugincontract andDispatcherregistry class.dispatcher.ts/tool-defs.ts/server.tsbecome thin shims over the registry; legacy functional API (dispatch,createDispatcherState,disposeAll,ALL_TOOLS) is preserved unchanged.createMcpServer({ plugins?: AgentMarkPlugin[] })now accepts a custom plugin set.Why
Foundation for the Microsoft Workflows Pack (and Insurance, etc.) — external packs need a first-class registration API, not a special-cased extra
casein the dispatcher switch. Going with the registry refactor rather than a bolt-on so future packs are first-class.What stayed identical
Test plan
pnpm buildcleanpnpm test— 326 pass, 10 skip (same skip set as main)agentmark-mcpfrom a fresh Claude Code session on Windows VM, runagentmark_desktop_list_targets, confirm same window enumeration as before refactorNew public API
From
@thinkfleet/agentmark(or the/mcpsubpath):AgentMarkPlugin,ToolHandler,DispatchResult— author surfaceDispatcher— registry/router classcreateWebPlugin,createPdfPlugin,createDesktopPlugin,createMetaPlugin— first-party factoriesExample pack:
```ts
import { type AgentMarkPlugin } from '@thinkfleet/agentmark'
export function createMicrosoftPlugin(opts): AgentMarkPlugin {
return {
name: 'microsoft',
tools: [/* MS-specific tool defs /],
handlers: { / keyed by tool name / },
dispose: async () => { / cleanup */ },
}
}
```
🤖 Generated with Claude Code