Skip to content

v0.7.0 — MCP server (any AI client can use AgentMark) - #6

Merged
rrader26 merged 1 commit into
feat/v0.6-acroform-supportfrom
feat/v0.7-mcp-server
May 10, 2026
Merged

v0.7.0 — MCP server (any AI client can use AgentMark)#6
rrader26 merged 1 commit into
feat/v0.6-acroform-supportfrom
feat/v0.7-mcp-server

Conversation

@rrader26

Copy link
Copy Markdown
Contributor

Summary

Wraps every public surface — web browser, PDF documents, AcroForm filling, OCR — as a Model Context Protocol server. Any MCP client (Claude Desktop, Cursor, Claude Code, custom agents) can use AgentMark through one configuration entry. No SDK install, no language commitment.

Stacked on top of #5 (v0.6 AcroForm). Merge #2#3#4#5 → this PR.

One-line install for any MCP client

```json
{
"mcpServers": {
"agentmark": {
"command": "npx",
"args": ["-y", "@thinkfleet/agentmark", "agentmark-mcp"]
}
}
}
```

15 tools exposed

Surface Tools
Browser `browser_open` / `browser_close` / `browser_save_session`
Page `page_open` / `page_navigate` / `page_snapshot` / `page_execute` / `page_close`
PDF `pdf_open` (file path OR `data:` URI) / `pdf_close` / `pdf_snapshot` / `pdf_execute` / `pdf_save` (with `flatten?`) / `pdf_reset`
Meta `list_sessions`

Each tool ships with a full JSON Schema for inputs — clients see usage hints, parameter docs, and validation automatically through MCP's `tools/list`.

Architecture

  • `tool-defs.ts` — declarative tool catalog
  • `dispatcher.ts` — pure dispatch function (name + args → result). Stateless except for the session registries it receives. Tested directly without transport.
  • `server.ts` — MCP Server wiring + StdioServerTransport + SIGINT/SIGTERM cleanup.
  • `cli.ts` — `#!/usr/bin/env node` entry; npm installs as `agentmark-mcp` on PATH.

The dispatcher / server split means tests can drive the full protocol without spawning subprocesses.

Stateful session model

Long-lived browsers + pages + opened PDFs held server-side, keyed by opaque IDs returned from `_open` calls. Agents can drive multiple parallel surfaces from one connection. All resources auto-released on shutdown.

Tests (223 total, 18 new for MCP)

  • 14 dispatcher tests — tool registry shape, error semantics (unknown tool / missing args / unknown session / AgentMark error code surfacing), PDF round-trip with real file I/O, reset, data-URI loading, list_sessions, disposeAll.
  • 4 wire-level handshake tests via `InMemoryTransport` — exercises the full MCP protocol (handshake, ListTools, CallTool, error responses) without spawning a subprocess.

Optional peer dependency

`@modelcontextprotocol/sdk` is an optional peer dep. Library callers who don't run the MCP server pay no install cost; SDK users still get the full library.

Test plan

🤖 Generated with Claude Code

Wraps every public surface — web browser, PDF documents, AcroForm
filling, OCR — as a Model Context Protocol server. Any MCP client
(Claude Desktop, Cursor, Claude Code, custom agents) can use AgentMark
through one configuration entry. No SDK install, no language commitment.

Configure in any MCP client:

  {
    "mcpServers": {
      "agentmark": {
        "command": "npx",
        "args": ["-y", "@thinkfleet/agentmark", "agentmark-mcp"]
      }
    }
  }

15 tools exposed
- Browser (3): browser_open / browser_close / browser_save_session
- Page (5):    page_open / page_navigate / page_snapshot / page_execute / page_close
- PDF (6):     pdf_open (file path or data: URI) / pdf_close / pdf_snapshot /
               pdf_execute / pdf_save (with optional flatten) / pdf_reset
- Meta (1):    list_sessions for debugging stuck connections

Architecture
- src/mcp/tool-defs.ts:  declarative tool catalog with full JSON Schema
                         input descriptions
- src/mcp/dispatcher.ts: pure dispatch function — name + args → result.
                         Stateless except for the session registries it
                         receives. Tested directly without transport.
- src/mcp/server.ts:     MCP Server wiring + StdioServerTransport binding +
                         SIGINT/SIGTERM cleanup
- src/mcp/cli.ts:        Bin entry (#!/usr/bin/env node) — what npm
                         installs as `agentmark-mcp` on PATH

Stateful session model
- Long-lived browsers + pages + opened PDF documents are held server-side,
  keyed by short opaque IDs returned from _open calls. Agents can drive
  multiple parallel surfaces from one MCP connection.
- All resources auto-released on disposeAll() — invoked on shutdown
  via SIGINT/SIGTERM and exposed for tests.

Programmatic API
- createMcpServer() / startMcpServer() exported for embedding the
  server in larger applications.
- dispatch() exported for tests / custom transports.

Optional peer dependency
- @modelcontextprotocol/sdk@^1 added as optional peer. Library callers
  who don't run the MCP server pay no install cost.

bin entry
- package.json now has "bin": { "agentmark-mcp": "./dist/src/mcp/cli.js" }
- npm sets executable bit on install; shebang preserved through tsc

Tests (213 unit + 10 real-Chromium = 223 total, was 199)
- 14 dispatcher tests:
    - tool registry shape (uniqueness, naming prefix, schema validity)
    - error semantics (unknown tool, missing args, unknown session ID,
      AgentMark error code prefix surfacing)
    - PDF round trip (open → snapshot → execute → save with file IO)
    - reset clears pending values
    - data-URI PDF source (base64 in-memory loading)
    - list_sessions (empty + populated)
    - disposeAll closes everything
- 4 wire-level handshake tests via InMemoryTransport — exercises the
  full MCP protocol (handshake, ListTools, CallTool, error responses)
  without spawning a subprocess

Distribution unlocked
After npm publish, anyone can configure AgentMark in any MCP client with
the snippet above. The full SDK (web + PDF + OCR + AcroForm fill/save)
becomes available as 15 tools any agent can call.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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