Skip to content

Commit bae42cb

Browse files
authored
Merge pull request #18 from code-rabi/benr/enhance-testing-coverage
chore: increase coverage
2 parents 7ce0c17 + 6b822e2 commit bae42cb

10 files changed

Lines changed: 1706 additions & 4 deletions

AGENTS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929

3030
## Error handling cues
3131

32-
- Meta-tools return JSON with `success` and `message` fields. Read `message` to adapt decisions (e.g., policy denial, already active, limits exceeded).
32+
Meta-tool return formats:
33+
- `enable_toolset` and `disable_toolset` return `{ success: boolean, message: string }`
34+
- `list_tools` returns `{ tools: string[], toolsetToTools: Record<string, string[]> }`
35+
- `list_toolsets` returns `{ toolsets: Array<{ key, active, definition, tools }> }`
36+
- `describe_toolset` returns `{ key, active, definition, tools }` or `{ error: string }` if unknown
37+
38+
For `enable_toolset`/`disable_toolset`, read `message` to adapt decisions (e.g., policy denial, already active, limits exceeded).
3339

3440
## HTTP endpoints
3541

CLAUDE.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Toolception is a dynamic MCP (Model Context Protocol) server toolkit for runtime toolset management. It allows grouping tools into toolsets and exposing only what's needed, when it's needed—reducing prompt/tool surface area for LLMs.
8+
9+
## Common Commands
10+
11+
```bash
12+
# Build the library
13+
npm run build
14+
15+
# Run in watch mode during development
16+
npm run dev
17+
18+
# Type check without emitting
19+
npm run typecheck
20+
21+
# Run all tests
22+
npm run test
23+
24+
# Run tests once (no watch)
25+
npm run test:run
26+
27+
# Run tests with coverage
28+
npm run test:coverage
29+
30+
# Run a single test file
31+
npx vitest run tests/toolRegistry.test.ts
32+
33+
# Run smoke tests (start server in one terminal, client in another)
34+
npm run dev:server-demo
35+
npm run dev:client-demo
36+
```
37+
38+
## Architecture
39+
40+
### Core Components
41+
42+
**ServerOrchestrator** (`src/core/ServerOrchestrator.ts`)
43+
- Entry point that wires together all components
44+
- Resolves startup mode (DYNAMIC vs STATIC) from configuration
45+
- Creates ModuleResolver, DynamicToolManager, and ToolRegistry
46+
- Registers meta-tools based on mode
47+
48+
**DynamicToolManager** (`src/core/DynamicToolManager.ts`)
49+
- Manages toolset lifecycle (enable/disable)
50+
- Enforces exposure policies (allowlist, denylist, maxActiveToolsets)
51+
- Registers tools with the MCP server
52+
- Tracks active toolsets and sends change notifications
53+
54+
**ToolRegistry** (`src/core/ToolRegistry.ts`)
55+
- Central registry preventing tool name collisions
56+
- Handles namespacing (e.g., `toolset.toolname`)
57+
- Maps toolsets to their registered tools
58+
59+
**ModuleResolver** (`src/mode/ModuleResolver.ts`)
60+
- Resolves tools from toolset definitions
61+
- Loads module-produced tools via moduleLoaders
62+
- Validates toolset names against catalog
63+
64+
### Server Creation APIs
65+
66+
Two main factory functions in `src/server/`:
67+
- `createMcpServer` - Standard server with DYNAMIC or STATIC modes
68+
- `createPermissionBasedMcpServer` - Per-client toolset access control
69+
70+
### HTTP Transport
71+
72+
**FastifyTransport** (`src/http/FastifyTransport.ts`)
73+
- Fastify-based HTTP transport for MCP protocol
74+
- Handles SSE streams, JSON-RPC requests
75+
- Per-client server instances in DYNAMIC mode
76+
77+
**PermissionAwareFastifyTransport** (`src/http/PermissionAwareFastifyTransport.ts`)
78+
- Extends FastifyTransport with permission checking
79+
- Supports header-based or config-based permissions
80+
81+
### Key Types (`src/types/index.ts`)
82+
83+
- `McpToolDefinition` - Tool with name, description, inputSchema, handler, optional annotations
84+
- `ToolSetDefinition` - Groups tools with name, description, optional modules
85+
- `ToolSetCatalog` - Record of toolset key to definition
86+
- `ExposurePolicy` - Controls maxActiveToolsets, allowlist, denylist, namespacing
87+
- `PermissionConfig` - Header or config-based permission source
88+
89+
### Meta-tools (DYNAMIC mode)
90+
91+
Registered in `src/meta/registerMetaTools.ts`:
92+
- `enable_toolset` / `disable_toolset` - Activate/deactivate toolsets
93+
- `list_toolsets` / `describe_toolset` - Discovery
94+
- `list_tools` - List currently registered tools
95+
96+
## Testing Patterns
97+
98+
Tests use Vitest with in-memory mocks. Key patterns:
99+
- Fake MCP server in `tests/helpers/fakes.ts`
100+
- Unit tests alongside integration tests in `tests/`
101+
- Smoke E2E tests in `tests/smoke-e2e/` for manual server/client testing
102+
103+
## Build System
104+
105+
- Vite for bundling (`vite.config.ts`)
106+
- vite-plugin-dts for TypeScript declarations
107+
- ESM-only output (`"type": "module"`)
108+
- Node.js >= 25.3.0 required

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)