This project implements a first-class MCP (Model Context Protocol) client for OpenClaw, consisting of a Plugin (tool extension), Skill (SKILL.md), and Slash Command (via skill command-dispatch). It enables OpenClaw agents to connect to remote MCP servers over Streamable HTTP with full OAuth 2.1 authentication.
SPEC.md— Full technical specification (transport, auth, architecture)DEVELOPMENT_PLAN.md— Task breakdown with dependencies and phasingSECURITY_AUDIT.md— (Phase 3) Security review findings
- Language: TypeScript (strict mode)
- Runtime: Node.js >= 22
- Test framework: Vitest
- Schema validation: @sinclair/typebox
- Package manager: pnpm
src/
index.ts — Plugin entry point (ToolPlugin interface)
config-schema.ts — TypeBox configuration schema
types.ts — JSON-RPC 2.0 + MCP type definitions
jsonrpc.ts — JSON-RPC encode/decode/validate utilities
manager/
mcp-manager.ts — Multi-server connection lifecycle
tool-registry.ts — Dynamic tool registration with namespacing
transport/
streamable-http.ts — MCP Streamable HTTP transport (POST/GET/DELETE + SSE)
sse-parser.ts — Server-Sent Events stream parser
stdio.ts — stdio transport (subprocess management)
legacy-sse.ts — Backwards-compat HTTP+SSE (2024-11-05 spec)
auth/
auth-manager.ts — OAuth 2.1 orchestrator
discovery.ts — Protected Resource + Auth Server metadata discovery
pkce.ts — PKCE S256 code challenge generation
client-registration.ts — Client ID Metadata Docs / Dynamic Client Registration
token-store.ts — Encrypted token persistence
callback-server.ts — Local HTTP server for OAuth redirects
commands/
mcp-manage.ts — /mcp subcommand handler (servers, tools, auth, etc.)
skills/
mcp/
SKILL.md — Agent-facing skill definition
test/
fixtures/
mock-mcp-server.ts — Test MCP server (Streamable HTTP)
mock-auth-server.ts — Test OAuth 2.1 authorization server
transport/
sse-parser.test.ts
streamable-http.test.ts
stdio.test.ts
legacy-sse.test.ts
auth/
pkce.test.ts
discovery.test.ts
client-registration.test.ts
token-store.test.ts
auth-manager.test.ts
manager/
mcp-manager.test.ts
e2e/
phase1.test.ts
phase2.test.ts
stress.test.ts
- Use
import typefor type-only imports - All public functions MUST have JSDoc with
@paramand@returns - Prefer
async/awaitover raw Promises - Use
AsyncIterable/AsyncGeneratorfor streaming data - Error handling: throw typed errors (extend
MCPErrorbase class) - No
anytypes — useunknownand narrow - Prefer
constassertions and literal types - Test files mirror source structure:
src/foo/bar.ts→test/foo/bar.test.ts
- Implements source code in
src/ - Creates the skill definition in
skills/mcp/SKILL.md - Focuses on correctness, performance, and spec compliance
- References
SPEC.mdfor all protocol decisions - MUST NOT write test files (that's qa's job)
- After completing a task, message qa to inform them code is ready for testing
- Follow the task dependency graph in DEVELOPMENT_PLAN.md
- Writes all test files in
test/ - Creates mock servers in
test/fixtures/ - Reviews dev's code for bugs, security issues, and spec violations
- Runs
npm testafter writing tests to verify they pass - MUST NOT write source code in
src/(that's dev's job) - After finding bugs, message dev with specific file:line references
- If tests fail due to implementation bugs, create a new task for dev to fix
- Dev and QA own separate directories — no cross-editing
- Dev writes
src/, QA writestest/ - When dev finishes a component, they message qa: "Task X.Y complete, ready for tests"
- When qa finds a bug, they message dev: "Bug in src/foo.ts:42 — describe issue"
- Both agents read SPEC.md for protocol behavior questions
- Tasks follow the dependency graph — don't start a task until its dependencies are done
# All tests
npm test
# Specific test file
npx vitest run test/transport/sse-parser.test.ts
# Watch mode
npx vitest watch
# Coverage
npx vitest run --coverage- Transport spec: MCP 2025-03-26 Streamable HTTP
- Auth spec: MCP draft — OAuth 2.1
- JSON-RPC: 2.0 (UTF-8 encoded, newline-delimited for stdio)
- Session header:
Mcp-Session-Id - SSE resumability:
Last-Event-IDheader - PKCE: S256 mandatory
- Resource indicators: RFC 8707
resourceparameter mandatory - Protected Resource Metadata: RFC 9728
- Auth Server Metadata: RFC 8414 + OIDC Discovery fallback