Files
cleveragents-core/features/builtin_adapter.feature
brent.edwards 34c6972a05
CI / build (push) Successful in 18s
CI / lint (push) Successful in 3m20s
CI / typecheck (push) Successful in 3m56s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m1s
CI / quality (push) Successful in 4m8s
CI / unit_tests (push) Successful in 6m40s
CI / integration_tests (push) Successful in 6m40s
CI / docker (push) Successful in 1m19s
CI / e2e_tests (push) Failing after 17m17s
CI / coverage (push) Failing after 18m20s
CI / benchmark-publish (push) Successful in 31m37s
CI / status-check (push) Failing after 1s
feat(tool): implement BuiltinAdapter class and MCP automatic resource slot creation (#964)
## Summary

Implement `BuiltinAdapter` class and MCP automatic resource slot creation. Two main changes:

### 1. BuiltinAdapter Class (`tool/builtins/adapter.py`)
Formal adapter implementing the tool adapter lifecycle pattern for built-in tools:
- `discover()` — returns all built-in tool descriptors (file, git, subplan tools)
- `register(registry)` — registers all tools in a ToolRegistry, returns registered names
- `activate()`/`deactivate()` — no-ops (built-in tools are always available)
- Wraps existing `ALL_FILE_TOOLS`, `ALL_GIT_TOOLS`, `ALL_SUBPLAN_TOOLS` lists
- Backward compatible — existing registration functions still work

### 2. MCP Resource Slot Inference (`mcp/adapter.py`)
New `infer_resource_slots()` static method on `MCPToolAdapter`:
- Scans MCP tool parameter schemas for file/directory/repo patterns
- Creates `ResourceSlot` objects with appropriate type, access mode, binding mode
- Mapping: `file_path`→file(rw), `directory`→directory(ro), `repo_path`→git-checkout(rw)
- Slots stored in `source_metadata["resource_slots"]` on registered `ToolSpec` objects

### Quality Gates

| Session | Result |
|---|---|
| `nox -s lint` | PASS |
| `nox -s typecheck` | PASS (0 errors) |
| `nox -s unit_tests` | PASS (10,817 scenarios) |
| `nox -s integration_tests` | PASS (6 new tests) |
| `nox -s coverage_report` | 97% (>= 97%) |

Closes #882

Reviewed-on: #964
Co-authored-by: Brent E. Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent E. Edwards <brent.edwards@cleverthis.com>
2026-03-21 05:30:01 +00:00

83 lines
3.7 KiB
Gherkin

Feature: BuiltinAdapter and MCP resource slot inference
As a developer
I want a formal BuiltinAdapter class with lifecycle methods
And MCP resource slot inference from tool parameter schemas
So that built-in tools follow the adapter pattern and MCP tools get automatic resource bindings
# ---- BuiltinAdapter ----
Scenario: BuiltinAdapter.discover returns all built-in tools
Given a builtin adapter
Then the builtin adapter should not be discovered yet
When I call discover on the builtin adapter
Then the builtin adapter should be discovered
And the discovered tools should include all file tools
And the discovered tools should include all git tools
And the discovered tools should include all subplan tools
And the total discovered tool count should be 11
Scenario: BuiltinAdapter.register registers all tools in a ToolRegistry
Given a builtin adapter
And a tool registry
When I call register on the builtin adapter
Then the registry should contain 11 tools
And the registry should contain tool "builtin/file-read"
And the registry should contain tool "builtin/git-status"
And the registry should contain tool "builtin/plan-subplan"
Scenario: BuiltinAdapter.activate and deactivate are no-ops
Given a builtin adapter
When I call activate on the builtin adapter
And I call deactivate on the builtin adapter
Then the builtin adapter lifecycle calls should succeed without error
Scenario: Tools registered through BuiltinAdapter have source builtin
Given a builtin adapter
And a tool registry
When I call register on the builtin adapter
Then all registered tools should have source "builtin"
# ---- MCP Resource Slot Inference ----
Scenario: MCP resource slot inference for file_path parameters
Given an MCP tool input schema with a "file_path" property
When I infer resource slots for the schema
Then the inferred slots should contain a "file" slot
And the "file" slot should have resource_type "file"
And the "file" slot should have access "read_write"
And the "file" slot should have binding "parameter"
Scenario: MCP resource slot inference for directory parameters
Given an MCP tool input schema with a "directory" property
When I infer resource slots for the schema
Then the inferred slots should contain a "directory" slot
And the "directory" slot should have resource_type "directory"
And the "directory" slot should have access "read_only"
And the "directory" slot should have binding "parameter"
Scenario: MCP resource slot inference for repo_path parameters
Given an MCP tool input schema with a "repo_path" property
When I infer resource slots for the schema
Then the inferred slots should contain a "repository" slot
And the "repository" slot should have resource_type "git-checkout"
And the "repository" slot should have access "read_write"
And the "repository" slot should have binding "contextual"
# ---- Boundary / negative cases ----
Scenario: MCP resource slot inference returns empty list for empty schema
Given an MCP tool with an empty input schema
When I infer resource slots for the schema
Then the inferred slots should be empty
Scenario: MCP resource slot inference returns empty list for schema with no properties key
Given an MCP tool with an input schema missing the properties key
When I infer resource slots for the schema
Then the inferred slots should be empty
Scenario: MCP resource slot inference deduplicates when multiple file params present
Given an MCP tool with both "file_path" and "filepath" properties
When I infer resource slots for the schema
Then the inferred slots should contain a "file" slot
And the inferred slot count should be 1