@matimo/core 0.1.0-alpha.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +341 -14
- package/dist/approval/approval-handler.d.ts +5 -1
- package/dist/approval/approval-handler.d.ts.map +1 -1
- package/dist/approval/approval-handler.js +6 -0
- package/dist/approval/approval-handler.js.map +1 -1
- package/dist/core/schema.d.ts +41 -10
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/schema.js +40 -4
- package/dist/core/schema.js.map +1 -1
- package/dist/core/skill-content-parser.d.ts +91 -0
- package/dist/core/skill-content-parser.d.ts.map +1 -0
- package/dist/core/skill-content-parser.js +248 -0
- package/dist/core/skill-content-parser.js.map +1 -0
- package/dist/core/skill-loader.d.ts +46 -0
- package/dist/core/skill-loader.d.ts.map +1 -0
- package/dist/core/skill-loader.js +310 -0
- package/dist/core/skill-loader.js.map +1 -0
- package/dist/core/skill-registry.d.ts +131 -0
- package/dist/core/skill-registry.d.ts.map +1 -0
- package/dist/core/skill-registry.js +316 -0
- package/dist/core/skill-registry.js.map +1 -0
- package/dist/core/tfidf-embedding.d.ts +45 -0
- package/dist/core/tfidf-embedding.d.ts.map +1 -0
- package/dist/core/tfidf-embedding.js +199 -0
- package/dist/core/tfidf-embedding.js.map +1 -0
- package/dist/core/tool-loader.d.ts +3 -1
- package/dist/core/tool-loader.d.ts.map +1 -1
- package/dist/core/tool-loader.js +33 -10
- package/dist/core/tool-loader.js.map +1 -1
- package/dist/core/types.d.ts +203 -6
- package/dist/core/types.d.ts.map +1 -1
- package/dist/encodings/parameter-encoding.d.ts +1 -1
- package/dist/encodings/parameter-encoding.d.ts.map +1 -1
- package/dist/encodings/parameter-encoding.js +9 -4
- package/dist/encodings/parameter-encoding.js.map +1 -1
- package/dist/errors/matimo-error.d.ts +11 -2
- package/dist/errors/matimo-error.d.ts.map +1 -1
- package/dist/errors/matimo-error.js +25 -1
- package/dist/errors/matimo-error.js.map +1 -1
- package/dist/executors/command-executor.d.ts +9 -2
- package/dist/executors/command-executor.d.ts.map +1 -1
- package/dist/executors/command-executor.js +29 -5
- package/dist/executors/command-executor.js.map +1 -1
- package/dist/executors/function-executor.d.ts +10 -3
- package/dist/executors/function-executor.d.ts.map +1 -1
- package/dist/executors/function-executor.js +44 -24
- package/dist/executors/function-executor.js.map +1 -1
- package/dist/executors/http-executor.d.ts +79 -4
- package/dist/executors/http-executor.d.ts.map +1 -1
- package/dist/executors/http-executor.js +232 -28
- package/dist/executors/http-executor.js.map +1 -1
- package/dist/index.d.ts +25 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -1
- package/dist/integrations/langchain.d.ts +55 -0
- package/dist/integrations/langchain.d.ts.map +1 -1
- package/dist/integrations/langchain.js +71 -4
- package/dist/integrations/langchain.js.map +1 -1
- package/dist/logging/logger.d.ts +8 -2
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/logging/logger.js.map +1 -1
- package/dist/logging/winston-logger.d.ts.map +1 -1
- package/dist/logging/winston-logger.js +9 -1
- package/dist/logging/winston-logger.js.map +1 -1
- package/dist/matimo-instance.d.ts +230 -18
- package/dist/matimo-instance.d.ts.map +1 -1
- package/dist/matimo-instance.js +739 -40
- package/dist/matimo-instance.js.map +1 -1
- package/dist/mcp/index.d.ts +18 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +24 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +141 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +754 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/secrets/aws-resolver.d.ts +41 -0
- package/dist/mcp/secrets/aws-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/aws-resolver.js +141 -0
- package/dist/mcp/secrets/aws-resolver.js.map +1 -0
- package/dist/mcp/secrets/dotenv-resolver.d.ts +23 -0
- package/dist/mcp/secrets/dotenv-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/dotenv-resolver.js +94 -0
- package/dist/mcp/secrets/dotenv-resolver.js.map +1 -0
- package/dist/mcp/secrets/env-resolver.d.ts +14 -0
- package/dist/mcp/secrets/env-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/env-resolver.js +27 -0
- package/dist/mcp/secrets/env-resolver.js.map +1 -0
- package/dist/mcp/secrets/index.d.ts +14 -0
- package/dist/mcp/secrets/index.d.ts.map +1 -0
- package/dist/mcp/secrets/index.js +13 -0
- package/dist/mcp/secrets/index.js.map +1 -0
- package/dist/mcp/secrets/resolver-chain.d.ts +34 -0
- package/dist/mcp/secrets/resolver-chain.d.ts.map +1 -0
- package/dist/mcp/secrets/resolver-chain.js +141 -0
- package/dist/mcp/secrets/resolver-chain.js.map +1 -0
- package/dist/mcp/secrets/types.d.ts +73 -0
- package/dist/mcp/secrets/types.d.ts.map +1 -0
- package/dist/mcp/secrets/types.js +8 -0
- package/dist/mcp/secrets/types.js.map +1 -0
- package/dist/mcp/secrets/vault-resolver.d.ts +43 -0
- package/dist/mcp/secrets/vault-resolver.d.ts.map +1 -0
- package/dist/mcp/secrets/vault-resolver.js +127 -0
- package/dist/mcp/secrets/vault-resolver.js.map +1 -0
- package/dist/mcp/tool-converter.d.ts +40 -0
- package/dist/mcp/tool-converter.d.ts.map +1 -0
- package/dist/mcp/tool-converter.js +185 -0
- package/dist/mcp/tool-converter.js.map +1 -0
- package/dist/policy/approval-manifest.d.ts +76 -0
- package/dist/policy/approval-manifest.d.ts.map +1 -0
- package/dist/policy/approval-manifest.js +197 -0
- package/dist/policy/approval-manifest.js.map +1 -0
- package/dist/policy/content-validator.d.ts +19 -0
- package/dist/policy/content-validator.d.ts.map +1 -0
- package/dist/policy/content-validator.js +196 -0
- package/dist/policy/content-validator.js.map +1 -0
- package/dist/policy/default-policy.d.ts +46 -0
- package/dist/policy/default-policy.d.ts.map +1 -0
- package/dist/policy/default-policy.js +241 -0
- package/dist/policy/default-policy.js.map +1 -0
- package/dist/policy/events.d.ts +71 -0
- package/dist/policy/events.d.ts.map +1 -0
- package/dist/policy/events.js +8 -0
- package/dist/policy/events.js.map +1 -0
- package/dist/policy/index.d.ts +13 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +9 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/integrity-tracker.d.ts +62 -0
- package/dist/policy/integrity-tracker.d.ts.map +1 -0
- package/dist/policy/integrity-tracker.js +79 -0
- package/dist/policy/integrity-tracker.js.map +1 -0
- package/dist/policy/policy-loader.d.ts +58 -0
- package/dist/policy/policy-loader.d.ts.map +1 -0
- package/dist/policy/policy-loader.js +156 -0
- package/dist/policy/policy-loader.js.map +1 -0
- package/dist/policy/risk-classifier.d.ts +18 -0
- package/dist/policy/risk-classifier.d.ts.map +1 -0
- package/dist/policy/risk-classifier.js +47 -0
- package/dist/policy/risk-classifier.js.map +1 -0
- package/dist/policy/types.d.ts +131 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +8 -0
- package/dist/policy/types.js.map +1 -0
- package/package.json +22 -6
- package/tools/matimo_approve_tool/definition.yaml +36 -0
- package/tools/matimo_approve_tool/matimo_approve_tool.ts +90 -0
- package/tools/matimo_create_skill/definition.yaml +46 -0
- package/tools/matimo_create_skill/matimo_create_skill.ts +75 -0
- package/tools/matimo_create_tool/definition.yaml +48 -0
- package/tools/matimo_create_tool/matimo_create_tool.ts +137 -0
- package/tools/matimo_get_skill/definition.yaml +60 -0
- package/tools/matimo_get_skill/matimo_get_skill.ts +182 -0
- package/tools/matimo_get_tool/definition.yaml +36 -0
- package/tools/matimo_get_tool/matimo_get_tool.ts +56 -0
- package/tools/matimo_get_tool_status/definition.yaml +42 -0
- package/tools/matimo_get_tool_status/matimo_get_tool_status.ts +101 -0
- package/tools/matimo_list_skills/definition.yaml +52 -0
- package/tools/matimo_list_skills/matimo_list_skills.ts +138 -0
- package/tools/matimo_list_user_tools/definition.yaml +32 -0
- package/tools/matimo_list_user_tools/matimo_list_user_tools.ts +74 -0
- package/tools/matimo_reload_tools/definition.yaml +35 -0
- package/tools/matimo_reload_tools/matimo_reload_tools.ts +29 -0
- package/tools/matimo_search_tools/definition.yaml +32 -0
- package/tools/matimo_search_tools/matimo_search_tools.ts +82 -0
- package/tools/matimo_validate_skill/definition.yaml +43 -0
- package/tools/matimo_validate_skill/matimo_validate_skill.ts +137 -0
- package/tools/matimo_validate_tool/definition.yaml +34 -0
- package/tools/matimo_validate_tool/matimo_validate_tool.ts +168 -0
- package/tools/read/read.ts +0 -2
- package/tools/shared/skill-validation.ts +335 -0
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ Install the unified package (includes core exports):
|
|
|
11
11
|
npm install matimo
|
|
12
12
|
pnpm add matimo
|
|
13
13
|
# or install scoped core package directly
|
|
14
|
-
npm
|
|
14
|
+
npm install @matimo/core
|
|
15
15
|
pnpm add @matimo/core
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -20,10 +20,15 @@ pnpm add @matimo/core
|
|
|
20
20
|
`@matimo/core` contains:
|
|
21
21
|
|
|
22
22
|
- `MatimoInstance` — initialization, discovery, registry, and execution API
|
|
23
|
-
- Executors (
|
|
23
|
+
- **Executors** — Command (shell), HTTP (REST with object/array embedding), Function (JS/TS)
|
|
24
|
+
- **Policy Engine** — content validation, risk classification, RBAC, integrity tracking
|
|
25
|
+
- **Meta-Tools** — 9 built-in tools for tool lifecycle management (create, validate, approve, reload, list, skill)
|
|
26
|
+
- **Approval System** — human-in-the-loop approval with interactive, auto-approve, and MCP patterns
|
|
27
|
+
- **MCP Server** — Model Context Protocol server with HTTP and stdio transports
|
|
24
28
|
- Decorator utilities (`@tool`, `setGlobalMatimoInstance`)
|
|
25
29
|
- Zod-based schema validation for YAML tool definitions
|
|
26
|
-
-
|
|
30
|
+
- **Structured error handling** — `MatimoError` with error chaining via optional `cause` field
|
|
31
|
+
- OAuth2 authentication support (provider integrations in separate packages)
|
|
27
32
|
|
|
28
33
|
This package is intended to be imported by applications, CLIs, and provider packages.
|
|
29
34
|
|
|
@@ -42,6 +47,31 @@ console.log('Loaded', matimo.listTools().length, 'tools');
|
|
|
42
47
|
await matimo.execute('calculator', { operation: 'add', a: 1, b: 2 });
|
|
43
48
|
```
|
|
44
49
|
|
|
50
|
+
## 🛠 Included Core Tools
|
|
51
|
+
|
|
52
|
+
`@matimo/core` includes 15 built-in tools:
|
|
53
|
+
|
|
54
|
+
### Utility Tools
|
|
55
|
+
- **`execute`** — Run shell commands with output capture, timeout, and working directory control
|
|
56
|
+
- **`read`** — Read files with line range support and encoding detection
|
|
57
|
+
- **`edit`** — Edit/replace content in files with backup
|
|
58
|
+
- **`search`** — Search files with grep patterns and context
|
|
59
|
+
- **`web`** — Fetch and parse web content
|
|
60
|
+
- **`calculator`** — Basic arithmetic operations
|
|
61
|
+
|
|
62
|
+
### Meta-Tools (Tool Lifecycle Management)
|
|
63
|
+
- **`matimo_validate_tool`** — Validate YAML against schema + policy rules, returns risk level
|
|
64
|
+
- **`matimo_create_tool`** — Write a new tool to disk with safety enforcement (forces draft + requires_approval)
|
|
65
|
+
- **`matimo_approve_tool`** — Promote a draft tool with HMAC-signed approval manifest
|
|
66
|
+
- **`matimo_reload_tools`** — Hot-reload all tools into the live registry without restart
|
|
67
|
+
- **`matimo_list_user_tools`** — List tools in a directory with risk classification and status
|
|
68
|
+
- **`matimo_create_skill`** — Create SKILL.md files with validated YAML frontmatter
|
|
69
|
+
- **`matimo_list_skills`** — List skills in a directory with name, description, and path
|
|
70
|
+
- **`matimo_get_skill`** — Read a skill's full content by name for agent context
|
|
71
|
+
- **`matimo_validate_skill`** — Validate a skill against the Agent Skills specification
|
|
72
|
+
|
|
73
|
+
All core tools use **function-based execution** (not shell commands) for better performance and reliability.
|
|
74
|
+
|
|
45
75
|
## 🧩 Usage Patterns
|
|
46
76
|
|
|
47
77
|
- Factory pattern: `MatimoInstance.init()` + `matimo.execute()`
|
|
@@ -50,15 +80,307 @@ await matimo.execute('calculator', { operation: 'add', a: 1, b: 2 });
|
|
|
50
80
|
|
|
51
81
|
See the full SDK docs: [docs/api-reference/SDK.md](../../docs/api-reference/SDK.md)
|
|
52
82
|
|
|
53
|
-
##
|
|
83
|
+
## ⚙️ Executors
|
|
84
|
+
|
|
85
|
+
`@matimo/core` provides three execution engines:
|
|
86
|
+
|
|
87
|
+
### FunctionExecutor (Recommended for Core Tools)
|
|
88
|
+
Executes TypeScript/JavaScript functions with type-safe parameters:
|
|
89
|
+
- ✅ **Direct execution** — No subprocess overhead
|
|
90
|
+
- ✅ **Better performance** — Direct async function calls
|
|
91
|
+
- ✅ **Type safety** — Proper TypeScript integration
|
|
92
|
+
- ✅ **Error handling** — Native exception handling
|
|
93
|
+
|
|
94
|
+
**Core tools** (`execute`, `read`, `edit`, `search`, `web`, `calculator`) all use function-based execution:
|
|
95
|
+
```yaml
|
|
96
|
+
# Tool YAML:
|
|
97
|
+
execution:
|
|
98
|
+
type: function
|
|
99
|
+
code: './execute.ts' # Relative path to implementation
|
|
100
|
+
|
|
101
|
+
# File: execute.ts
|
|
102
|
+
export default async function execute(params: {
|
|
103
|
+
command: string
|
|
104
|
+
args?: string[]
|
|
105
|
+
cwd?: string
|
|
106
|
+
timeout?: number
|
|
107
|
+
}): Promise<{ success: boolean; stdout: string; stderr: string; exitCode: number }> {
|
|
108
|
+
// Implementation here
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### HttpExecutor
|
|
113
|
+
Makes HTTP requests with automatic parameter embedding and response validation:
|
|
114
|
+
```yaml
|
|
115
|
+
# Tool YAML:
|
|
116
|
+
execution:
|
|
117
|
+
type: http
|
|
118
|
+
method: POST
|
|
119
|
+
url: https://api.example.com/data
|
|
120
|
+
headers:
|
|
121
|
+
Authorization: 'Bearer {AUTH_TOKEN}'
|
|
122
|
+
body:
|
|
123
|
+
text: '{text}'
|
|
124
|
+
metadata: '{metadata}' # Objects/arrays automatically JSON-encoded
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Key features:**
|
|
128
|
+
- ✅ **Parameter embedding** — Objects and arrays automatically JSON-encoded in request body
|
|
129
|
+
- ✅ **Response validation** — Validates output against `output_schema` using Zod
|
|
130
|
+
- ✅ **Error normalization** — Converts Axios/HTTP errors to structured `MatimoError`
|
|
131
|
+
- ✅ **Structured error details** — Original error preserved via `error.cause` field
|
|
132
|
+
|
|
133
|
+
### CommandExecutor (Legacy Shell Execution)
|
|
134
|
+
Spawns shell processes for external commands:
|
|
135
|
+
```typescript
|
|
136
|
+
// Tool YAML:
|
|
137
|
+
execution:
|
|
138
|
+
type: command
|
|
139
|
+
command: node
|
|
140
|
+
args: ["script.js", "{param1}"]
|
|
141
|
+
|
|
142
|
+
// Spawns: node script.js value1
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**Use when:**
|
|
146
|
+
- Executing external shell commands or legacy scripts
|
|
147
|
+
- Running tools from other packages that expect shell execution
|
|
148
|
+
- Most core Matimo tools now use function-based execution instead
|
|
149
|
+
|
|
150
|
+
## 🚨 Error Handling
|
|
151
|
+
|
|
152
|
+
All executors throw `MatimoError` (never generic `Error`) with structured context:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { MatimoError, ErrorCode } from '@matimo/core';
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
await matimo.execute('my-tool', params);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
if (error instanceof MatimoError) {
|
|
161
|
+
console.error(`Error: ${error.message}`);
|
|
162
|
+
console.error(`Code: ${error.code}`);
|
|
163
|
+
console.error(`Details:`, error.details);
|
|
164
|
+
|
|
165
|
+
// Access original exception (if available)
|
|
166
|
+
if (error.cause) {
|
|
167
|
+
console.error(`Original error:`, error.cause);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
54
172
|
|
|
55
|
-
|
|
173
|
+
**Error codes:**
|
|
174
|
+
- `INVALID_SCHEMA` — Tool definition or parameters invalid
|
|
175
|
+
- `EXECUTION_FAILED` — Tool execution failed (network, timeout, etc.)
|
|
176
|
+
- `AUTH_FAILED` — Authentication/authorization error
|
|
177
|
+
- `TOOL_NOT_FOUND` — Tool not found in registry
|
|
178
|
+
|
|
179
|
+
**Error chaining:**
|
|
180
|
+
The optional `cause` field preserves the original error for debugging:
|
|
181
|
+
```typescript
|
|
182
|
+
throw new MatimoError('HTTP request failed', ErrorCode.EXECUTION_FAILED, {
|
|
183
|
+
toolName: 'slack_send',
|
|
184
|
+
statusCode: 500,
|
|
185
|
+
details: { originalError: axiosError }
|
|
186
|
+
});
|
|
187
|
+
// Access via: error.cause or error.details.originalError
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 🔐 Authentication & Security
|
|
191
|
+
|
|
192
|
+
Tools declare authentication requirements in YAML. `@matimo/core` supports:
|
|
193
|
+
|
|
194
|
+
- **API keys** (header/query injection)
|
|
195
|
+
- **Bearer/basic tokens** (automatic injection)
|
|
196
|
+
- **OAuth2** (provider configurations via OAuth2Handler)
|
|
197
|
+
|
|
198
|
+
Credentials are loaded from environment variables by convention:
|
|
199
|
+
```bash
|
|
200
|
+
export SLACK_BOT_TOKEN=xoxb-...
|
|
201
|
+
export GMAIL_ACCESS_TOKEN=ya29-...
|
|
202
|
+
export NOTION_API_KEY=ntn_...
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Security notes:**
|
|
206
|
+
- ✅ Secrets never logged (error messages exclude credential values)
|
|
207
|
+
- ✅ OAuth tokens refreshed automatically when expired
|
|
208
|
+
- ✅ HTTP Executor validates all authentication before making requests
|
|
209
|
+
- ✅ Missing credentials throw `MatimoError(AUTH_FAILED)` with helpful guidance
|
|
210
|
+
|
|
211
|
+
## 🛡 Policy Engine
|
|
212
|
+
|
|
213
|
+
The policy engine provides defense-in-depth security for AI agent tool usage. Policy is defined at deploy time and `Object.freeze()`'d at runtime — agents cannot modify it.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
import { MatimoInstance } from 'matimo';
|
|
217
|
+
import type { PolicyConfig } from 'matimo';
|
|
218
|
+
|
|
219
|
+
const policyConfig: PolicyConfig = {
|
|
220
|
+
allowedDomains: ['api.github.com', 'api.slack.com'],
|
|
221
|
+
allowedHttpMethods: ['GET', 'POST'],
|
|
222
|
+
allowCommandTools: false,
|
|
223
|
+
allowFunctionTools: false,
|
|
224
|
+
protectedNamespaces: ['matimo_'],
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const matimo = await MatimoInstance.init({
|
|
228
|
+
toolPaths: ['./tools', './agent-tools'],
|
|
229
|
+
untrustedPaths: ['./agent-tools'],
|
|
230
|
+
policyConfig,
|
|
231
|
+
});
|
|
232
|
+
```
|
|
56
233
|
|
|
57
|
-
|
|
58
|
-
- Bearer/basic tokens
|
|
59
|
-
- OAuth2 (provider integrations handled in provider packages)
|
|
234
|
+
### Content Validator (9 Rules)
|
|
60
235
|
|
|
61
|
-
|
|
236
|
+
| Rule | Severity | What It Checks |
|
|
237
|
+
|------|----------|----------------|
|
|
238
|
+
| `no-function-execution` | critical | Blocks arbitrary code execution |
|
|
239
|
+
| `no-command-execution` | critical | Blocks shell injection |
|
|
240
|
+
| `no-ssrf` | critical | Blocks internal IPs/metadata endpoints |
|
|
241
|
+
| `unauthorized-credential` | high | Blocks unapproved credentials |
|
|
242
|
+
| `reserved-namespace` | high | Blocks hijacking of `matimo_` prefix |
|
|
243
|
+
| `forced-approval` | medium | Enforces `requires_approval: true` |
|
|
244
|
+
| `blocked-http-method` | high | Blocks disallowed HTTP methods |
|
|
245
|
+
| `blocked-domain` | high | Blocks disallowed domains |
|
|
246
|
+
| `forced-draft-status` | medium | Enforces `status: draft` on new tools |
|
|
247
|
+
|
|
248
|
+
### Risk Classification
|
|
249
|
+
|
|
250
|
+
| Risk Level | Criteria |
|
|
251
|
+
|-----------|----------|
|
|
252
|
+
| **critical** | `execution.type: function` |
|
|
253
|
+
| **high** | `execution.type: command`, HTTP `DELETE`, `requires_approval: true` |
|
|
254
|
+
| **medium** | HTTP `POST`, `PUT`, `PATCH` |
|
|
255
|
+
| **low** | HTTP `GET`, `HEAD`, `OPTIONS` |
|
|
256
|
+
|
|
257
|
+
See the full guide: [docs/tool-development/POLICY_AND_LIFECYCLE.md](../../docs/tool-development/POLICY_AND_LIFECYCLE.md)
|
|
258
|
+
|
|
259
|
+
## 🔄 Tool Lifecycle (Create → Approve → Reload → Use)
|
|
260
|
+
|
|
261
|
+
Agents can create tools at runtime with full policy enforcement:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
// 1. Create — writes YAML to disk (forces draft + requires_approval)
|
|
265
|
+
await matimo.execute('matimo_create_tool', {
|
|
266
|
+
name: 'city_lookup',
|
|
267
|
+
target_dir: './agent-tools',
|
|
268
|
+
yaml_content: `
|
|
269
|
+
name: city_lookup
|
|
270
|
+
version: '1.0.0'
|
|
271
|
+
description: Look up user information including city and address details
|
|
272
|
+
parameters:
|
|
273
|
+
id: { type: string, required: true }
|
|
274
|
+
execution:
|
|
275
|
+
type: http
|
|
276
|
+
method: GET
|
|
277
|
+
url: 'https://jsonplaceholder.typicode.com/users/{id}'
|
|
278
|
+
`,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// 2. Approve — re-validates, signs HMAC, updates status to approved
|
|
282
|
+
await matimo.execute('matimo_approve_tool', {
|
|
283
|
+
name: 'city_lookup',
|
|
284
|
+
tool_dir: './agent-tools',
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// 3. Reload — clears registry, re-reads YAML, re-validates untrusted tools
|
|
288
|
+
await matimo.execute('matimo_reload_tools', {});
|
|
289
|
+
|
|
290
|
+
// 4. Use — tool is now in the live registry
|
|
291
|
+
const result = await matimo.execute('city_lookup', { id: '1' });
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
This lifecycle works identically across SDK, LangChain, and MCP interfaces.
|
|
295
|
+
|
|
296
|
+
See the full reference: [docs/tool-development/META_TOOLS.md](../../docs/tool-development/META_TOOLS.md)
|
|
297
|
+
|
|
298
|
+
## ✅ Approval System
|
|
299
|
+
|
|
300
|
+
Tools with `requires_approval: true` require human confirmation before execution:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import { getGlobalApprovalHandler } from 'matimo';
|
|
304
|
+
|
|
305
|
+
// Interactive terminal approval
|
|
306
|
+
getGlobalApprovalHandler().setApprovalCallback(async (request) => {
|
|
307
|
+
console.log(`Tool: ${request.toolName}`);
|
|
308
|
+
console.log(`Params: ${JSON.stringify(request.params)}`);
|
|
309
|
+
// return true to approve, false to reject
|
|
310
|
+
return await promptUser('Approve? (y/n)');
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
// Auto-approve (CI/CD only)
|
|
314
|
+
process.env.MATIMO_AUTO_APPROVE = 'true';
|
|
315
|
+
|
|
316
|
+
// Pre-approved patterns
|
|
317
|
+
process.env.MATIMO_APPROVED_PATTERNS = 'calculator,weather_*';
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**MCP approval:** MCP clients pass `_matimo_approved: true` in arguments for tools that require approval.
|
|
321
|
+
|
|
322
|
+
See: [docs/APPROVAL-SYSTEM.md](../../docs/APPROVAL-SYSTEM.md)
|
|
323
|
+
|
|
324
|
+
## 🌐 MCP Server
|
|
325
|
+
|
|
326
|
+
Serve Matimo tools via the Model Context Protocol:
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
import { MCPServer } from 'matimo';
|
|
330
|
+
|
|
331
|
+
const server = new MCPServer({
|
|
332
|
+
transport: 'http',
|
|
333
|
+
port: 3000,
|
|
334
|
+
toolPaths: ['./tools'],
|
|
335
|
+
policyConfig: { allowCommandTools: false },
|
|
336
|
+
mcpToken: process.env.MCP_TOKEN,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
await server.start();
|
|
340
|
+
// Tools available at POST http://localhost:3000/mcp
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**Supports:**
|
|
344
|
+
- HTTP and stdio transports
|
|
345
|
+
- Bearer token authentication
|
|
346
|
+
- Tool lifecycle via meta-tools (create, approve, reload)
|
|
347
|
+
- Automatic `notifications/tools/list_changed` on reload
|
|
348
|
+
|
|
349
|
+
See: [docs/MCP.md](../../docs/MCP.md)
|
|
350
|
+
|
|
351
|
+
## ✅ Validation & Output Schema
|
|
352
|
+
|
|
353
|
+
All tool execution includes automatic validation:
|
|
354
|
+
|
|
355
|
+
**Input Validation:**
|
|
356
|
+
- Tool YAML definitions validated against Zod schema on load
|
|
357
|
+
- Parameters validated against tool's declared `parameters` schema
|
|
358
|
+
- Invalid parameters throw `MatimoError(INVALID_SCHEMA)`
|
|
359
|
+
|
|
360
|
+
**Output Validation:**
|
|
361
|
+
- HTTP executor validates response against tool's `output_schema`
|
|
362
|
+
- Function executor validates return value against `output_schema` (for HTTP tools)
|
|
363
|
+
- Invalid responses/returns throw `MatimoError(EXECUTION_FAILED)`
|
|
364
|
+
- Zod provides detailed validation error messages
|
|
365
|
+
|
|
366
|
+
**Example (core `execute` tool):**
|
|
367
|
+
```yaml
|
|
368
|
+
# Definition: packages/core/tools/execute/definition.yaml
|
|
369
|
+
execution:
|
|
370
|
+
type: function
|
|
371
|
+
code: './execute.ts'
|
|
372
|
+
|
|
373
|
+
output_schema:
|
|
374
|
+
type: object
|
|
375
|
+
properties:
|
|
376
|
+
success: { type: boolean }
|
|
377
|
+
exitCode: { type: number }
|
|
378
|
+
stdout: { type: string }
|
|
379
|
+
stderr: { type: string }
|
|
380
|
+
required: [success, exitCode, stdout, stderr]
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
Invalid parameters or responses trigger validation errors with structured details.
|
|
62
384
|
|
|
63
385
|
## 🧪 Testing & Development
|
|
64
386
|
|
|
@@ -74,12 +396,17 @@ To build:
|
|
|
74
396
|
pnpm --filter "@matimo/core" build
|
|
75
397
|
```
|
|
76
398
|
|
|
77
|
-
## 📚
|
|
78
|
-
|
|
79
|
-
See the project CONTRIBUTING guide and `docs/tool-development/ADDING_TOOLS.md` for adding provider packages and tools.
|
|
399
|
+
## 📚 Documentation
|
|
80
400
|
|
|
81
|
-
-
|
|
82
|
-
-
|
|
401
|
+
- [Quick Start](../../docs/getting-started/QUICK_START.md)
|
|
402
|
+
- [API Reference](../../docs/api-reference/SDK.md)
|
|
403
|
+
- [Policy & Lifecycle Guide](../../docs/tool-development/POLICY_AND_LIFECYCLE.md)
|
|
404
|
+
- [Meta-Tools Reference](../../docs/tool-development/META_TOOLS.md)
|
|
405
|
+
- [Approval System](../../docs/APPROVAL-SYSTEM.md)
|
|
406
|
+
- [MCP Server](../../docs/MCP.md)
|
|
407
|
+
- [Tool Specification](../../docs/tool-development/TOOL_SPECIFICATION.md)
|
|
408
|
+
- [Adding Tools](../../docs/tool-development/ADDING_TOOLS.md)
|
|
409
|
+
- [Contributing](https://github.com/tallclub/matimo/blob/main/CONTRIBUTING.md)
|
|
83
410
|
|
|
84
411
|
---
|
|
85
412
|
|
|
@@ -42,7 +42,11 @@ export declare class ApprovalHandler {
|
|
|
42
42
|
/**
|
|
43
43
|
* Set approval callback for interactive/custom approval
|
|
44
44
|
*/
|
|
45
|
-
setApprovalCallback(callback: ApprovalCallback): void;
|
|
45
|
+
setApprovalCallback(callback: ApprovalCallback | null): void;
|
|
46
|
+
/**
|
|
47
|
+
* Get the current approval callback (for save/restore patterns)
|
|
48
|
+
*/
|
|
49
|
+
getApprovalCallback(): ApprovalCallback | null;
|
|
46
50
|
/**
|
|
47
51
|
* Check if a tool requires approval based on YAML definition or supplied content.
|
|
48
52
|
* @param requiresApproval In Yaml - From tool definition `requires_approval` field
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-handler.d.ts","sourceRoot":"","sources":["../../src/approval/approval-handler.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,W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I;IAI5D;;OAEG;IACH,mBAAmB,IAAI,gBAAgB,GAAG,IAAI;IAI9C;;;;;;;;OAQG;IACH,gBAAgB,CAAC,sBAAsB,EAAE,OAAO,GAAG,SAAS,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO;IAexF;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAgBxC;;;OAGG;IACG,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IA2B9D;;OAEG;IACH,OAAO,CAAC,cAAc;CAavB;AAKD;;GAEG;AACH,wBAAgB,wBAAwB,IAAI,eAAe,CAK1D"}
|
|
@@ -122,6 +122,12 @@ export class ApprovalHandler {
|
|
|
122
122
|
setApprovalCallback(callback) {
|
|
123
123
|
this.approvalCallback = callback;
|
|
124
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Get the current approval callback (for save/restore patterns)
|
|
127
|
+
*/
|
|
128
|
+
getApprovalCallback() {
|
|
129
|
+
return this.approvalCallback;
|
|
130
|
+
}
|
|
125
131
|
/**
|
|
126
132
|
* Check if a tool requires approval based on YAML definition or supplied content.
|
|
127
133
|
* @param requiresApproval In Yaml - From tool definition `requires_approval` field
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-handler.js","sourceRoot":"","sources":["../../src/approval/approval-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAiBhE;;;;;;;;;GASG;AACH,MAAM,OAAO,eAAe;IAM1B;QALQ,gBAAW,GAAY,KAAK,CAAC;QAC7B,qBAAgB,GAAgB,IAAI,GAAG,EAAE,CAAC;QAC1C,qBAAgB,GAA4B,IAAI,CAAC;QACjD,wBAAmB,GAAa,EAAE,CAAC;QAGzC,oDAAoD;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MAAM,CAAC,CAAC;QACtE,MAAM,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,YAAY,GAAG,EAAE,GAAG,CAAC,CAAC;QACnD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;CACF;AAED,kBAAkB;AAClB,IAAI,qBAAqB,GAA2B,IAAI,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,qBAAqB,GAAG,IAAI,eAAe,EAAE,CAAC;IAChD,CAAC;IACD,OAAO,qBAAqB,CAAC;AAC/B,CAAC"}
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -20,11 +20,12 @@ export declare const ParameterSchema: z.ZodObject<{
|
|
|
20
20
|
export type Parameter = z.infer<typeof ParameterSchema>;
|
|
21
21
|
export declare const AuthConfigSchema: z.ZodObject<{
|
|
22
22
|
type: z.ZodOptional<z.ZodEnum<{
|
|
23
|
+
custom: "custom";
|
|
24
|
+
none: "none";
|
|
23
25
|
api_key: "api_key";
|
|
24
|
-
oauth2: "oauth2";
|
|
25
26
|
basic: "basic";
|
|
26
27
|
bearer: "bearer";
|
|
27
|
-
|
|
28
|
+
oauth2: "oauth2";
|
|
28
29
|
}>>;
|
|
29
30
|
location: z.ZodOptional<z.ZodEnum<{
|
|
30
31
|
body: "body";
|
|
@@ -34,6 +35,8 @@ export declare const AuthConfigSchema: z.ZodObject<{
|
|
|
34
35
|
name: z.ZodOptional<z.ZodString>;
|
|
35
36
|
provider: z.ZodOptional<z.ZodString>;
|
|
36
37
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
38
|
+
username_env: z.ZodOptional<z.ZodString>;
|
|
39
|
+
password_env: z.ZodOptional<z.ZodString>;
|
|
37
40
|
}, z.core.$strip>;
|
|
38
41
|
export type AuthConfig = z.infer<typeof AuthConfigSchema>;
|
|
39
42
|
export declare const ExecutionConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
@@ -70,8 +73,14 @@ export declare const ExecutionConfigSchema: z.ZodDiscriminatedUnion<[z.ZodObject
|
|
|
70
73
|
}, z.core.$strip>], "type">;
|
|
71
74
|
export type ExecutionConfig = z.infer<typeof ExecutionConfigSchema>;
|
|
72
75
|
export declare const OutputSchemaSchema: z.ZodObject<{
|
|
73
|
-
type: z.ZodOptional<z.
|
|
74
|
-
|
|
76
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
77
|
+
string: "string";
|
|
78
|
+
number: "number";
|
|
79
|
+
boolean: "boolean";
|
|
80
|
+
object: "object";
|
|
81
|
+
array: "array";
|
|
82
|
+
}>, z.ZodString]>>;
|
|
83
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
75
84
|
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
85
|
description: z.ZodOptional<z.ZodString>;
|
|
77
86
|
}, z.core.$strip>;
|
|
@@ -79,8 +88,9 @@ export type OutputSchema = z.infer<typeof OutputSchemaSchema>;
|
|
|
79
88
|
export declare const ErrorHandlingSchema: z.ZodObject<{
|
|
80
89
|
retry: z.ZodOptional<z.ZodNumber>;
|
|
81
90
|
backoff_type: z.ZodOptional<z.ZodEnum<{
|
|
82
|
-
|
|
91
|
+
fixed: "fixed";
|
|
83
92
|
linear: "linear";
|
|
93
|
+
exponential: "exponential";
|
|
84
94
|
}>>;
|
|
85
95
|
initial_delay_ms: z.ZodOptional<z.ZodNumber>;
|
|
86
96
|
max_delay_ms: z.ZodOptional<z.ZodNumber>;
|
|
@@ -145,11 +155,12 @@ export declare const ToolDefinitionSchema: z.ZodObject<{
|
|
|
145
155
|
}, z.core.$strip>], "type">;
|
|
146
156
|
authentication: z.ZodOptional<z.ZodObject<{
|
|
147
157
|
type: z.ZodOptional<z.ZodEnum<{
|
|
158
|
+
custom: "custom";
|
|
159
|
+
none: "none";
|
|
148
160
|
api_key: "api_key";
|
|
149
|
-
oauth2: "oauth2";
|
|
150
161
|
basic: "basic";
|
|
151
162
|
bearer: "bearer";
|
|
152
|
-
|
|
163
|
+
oauth2: "oauth2";
|
|
153
164
|
}>>;
|
|
154
165
|
location: z.ZodOptional<z.ZodEnum<{
|
|
155
166
|
body: "body";
|
|
@@ -159,18 +170,27 @@ export declare const ToolDefinitionSchema: z.ZodObject<{
|
|
|
159
170
|
name: z.ZodOptional<z.ZodString>;
|
|
160
171
|
provider: z.ZodOptional<z.ZodString>;
|
|
161
172
|
required: z.ZodOptional<z.ZodBoolean>;
|
|
173
|
+
username_env: z.ZodOptional<z.ZodString>;
|
|
174
|
+
password_env: z.ZodOptional<z.ZodString>;
|
|
162
175
|
}, z.core.$strip>>;
|
|
163
176
|
output_schema: z.ZodOptional<z.ZodObject<{
|
|
164
|
-
type: z.ZodOptional<z.
|
|
165
|
-
|
|
177
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
178
|
+
string: "string";
|
|
179
|
+
number: "number";
|
|
180
|
+
boolean: "boolean";
|
|
181
|
+
object: "object";
|
|
182
|
+
array: "array";
|
|
183
|
+
}>, z.ZodString]>>;
|
|
184
|
+
properties: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>>;
|
|
166
185
|
required: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
167
186
|
description: z.ZodOptional<z.ZodString>;
|
|
168
187
|
}, z.core.$strip>>;
|
|
169
188
|
error_handling: z.ZodOptional<z.ZodObject<{
|
|
170
189
|
retry: z.ZodOptional<z.ZodNumber>;
|
|
171
190
|
backoff_type: z.ZodOptional<z.ZodEnum<{
|
|
172
|
-
|
|
191
|
+
fixed: "fixed";
|
|
173
192
|
linear: "linear";
|
|
193
|
+
exponential: "exponential";
|
|
174
194
|
}>>;
|
|
175
195
|
initial_delay_ms: z.ZodOptional<z.ZodNumber>;
|
|
176
196
|
max_delay_ms: z.ZodOptional<z.ZodNumber>;
|
|
@@ -182,6 +202,12 @@ export declare const ToolDefinitionSchema: z.ZodObject<{
|
|
|
182
202
|
quota_per_hour: z.ZodOptional<z.ZodNumber>;
|
|
183
203
|
}, z.core.$strip>>;
|
|
184
204
|
requires_approval: z.ZodOptional<z.ZodBoolean>;
|
|
205
|
+
risk: z.ZodOptional<z.ZodEnum<{
|
|
206
|
+
low: "low";
|
|
207
|
+
medium: "medium";
|
|
208
|
+
high: "high";
|
|
209
|
+
critical: "critical";
|
|
210
|
+
}>>;
|
|
185
211
|
examples: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
186
212
|
name: z.ZodString;
|
|
187
213
|
params: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
@@ -190,6 +216,11 @@ export declare const ToolDefinitionSchema: z.ZodObject<{
|
|
|
190
216
|
deprecated: z.ZodOptional<z.ZodBoolean>;
|
|
191
217
|
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
192
218
|
deprecation_message: z.ZodOptional<z.ZodString>;
|
|
219
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
220
|
+
deprecated: "deprecated";
|
|
221
|
+
draft: "draft";
|
|
222
|
+
approved: "approved";
|
|
223
|
+
}>>;
|
|
193
224
|
}, z.core.$strip>;
|
|
194
225
|
export type ToolDefinition = z.infer<typeof ToolDefinitionSchema> & {
|
|
195
226
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AAGH,eAAO,MAAM,eAAe;;;;;;;;;;;;;iBAO1B,CAAC;AAEH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK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M,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,GAAG;IAClE;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAKF,eAAO,MAAM,qBAAqB;;;;iBAIhC,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAGpE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;iBAanC,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,OAAO,GAAG,cAAc,CAkBpE;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,OAAO,GAAG,kBAAkB,CAsBhF"}
|
package/dist/core/schema.js
CHANGED
|
@@ -15,11 +15,23 @@ export const ParameterSchema = z.object({
|
|
|
15
15
|
});
|
|
16
16
|
// Authentication configuration
|
|
17
17
|
export const AuthConfigSchema = z.object({
|
|
18
|
-
type: z.enum(['api_key', 'basic', 'bearer', 'oauth2', 'custom']).optional(),
|
|
18
|
+
type: z.enum(['none', 'api_key', 'basic', 'bearer', 'oauth2', 'custom']).optional(),
|
|
19
19
|
location: z.enum(['header', 'query', 'body']).optional(),
|
|
20
20
|
name: z.string().optional(),
|
|
21
21
|
provider: z.string().optional(),
|
|
22
22
|
required: z.boolean().optional(),
|
|
23
|
+
/**
|
|
24
|
+
* For type: basic — name of the environment variable holding the HTTP Basic Auth username.
|
|
25
|
+
* HttpExecutor will read this env var and the password_env var, base64-encode them as
|
|
26
|
+
* "username:password", and inject `Authorization: Basic <encoded>` automatically.
|
|
27
|
+
* This eliminates the need for developers to pre-compute a base64 credential string.
|
|
28
|
+
*/
|
|
29
|
+
username_env: z.string().optional(),
|
|
30
|
+
/**
|
|
31
|
+
* For type: basic — name of the environment variable holding the HTTP Basic Auth password.
|
|
32
|
+
* Used together with username_env to build the Authorization header automatically.
|
|
33
|
+
*/
|
|
34
|
+
password_env: z.string().optional(),
|
|
23
35
|
});
|
|
24
36
|
// Execution configuration (command, HTTP, or function)
|
|
25
37
|
export const ExecutionConfigSchema = z.discriminatedUnion('type', [
|
|
@@ -55,16 +67,38 @@ export const ExecutionConfigSchema = z.discriminatedUnion('type', [
|
|
|
55
67
|
}),
|
|
56
68
|
]);
|
|
57
69
|
// Output schema for validation
|
|
70
|
+
// Aligned with TypeScript interface: type should be one of the known types (or unknown string for extensibility)
|
|
71
|
+
// Recursive property schema — validates that each property value in output_schema.properties
|
|
72
|
+
// is a valid schema object (not a raw primitive).
|
|
73
|
+
const OutputPropertySchema = z.lazy(() => z.object({
|
|
74
|
+
type: z
|
|
75
|
+
.union([
|
|
76
|
+
z.enum(['string', 'number', 'integer', 'boolean', 'array', 'object', 'null']),
|
|
77
|
+
z.string(),
|
|
78
|
+
z.array(z.string()), // Allow nullable arrays: [string, "null"]
|
|
79
|
+
])
|
|
80
|
+
.optional(),
|
|
81
|
+
description: z.string().optional(),
|
|
82
|
+
properties: z.record(z.string(), OutputPropertySchema).optional(),
|
|
83
|
+
items: OutputPropertySchema.optional(),
|
|
84
|
+
required: z.array(z.string()).optional(),
|
|
85
|
+
enum: z.array(z.unknown()).optional(),
|
|
86
|
+
}));
|
|
58
87
|
export const OutputSchemaSchema = z.object({
|
|
59
|
-
type: z
|
|
60
|
-
|
|
88
|
+
type: z
|
|
89
|
+
.union([
|
|
90
|
+
z.enum(['string', 'number', 'boolean', 'array', 'object']),
|
|
91
|
+
z.string(), // Allow other custom types for extensibility
|
|
92
|
+
])
|
|
93
|
+
.optional(),
|
|
94
|
+
properties: z.record(z.string(), OutputPropertySchema).optional(),
|
|
61
95
|
required: z.array(z.string()).optional(),
|
|
62
96
|
description: z.string().optional(),
|
|
63
97
|
});
|
|
64
98
|
// Error handling configuration
|
|
65
99
|
export const ErrorHandlingSchema = z.object({
|
|
66
100
|
retry: z.number().optional(),
|
|
67
|
-
backoff_type: z.enum(['linear', 'exponential']).optional(),
|
|
101
|
+
backoff_type: z.enum(['linear', 'exponential', 'fixed']).optional(),
|
|
68
102
|
initial_delay_ms: z.number().optional(),
|
|
69
103
|
max_delay_ms: z.number().optional(),
|
|
70
104
|
});
|
|
@@ -87,6 +121,7 @@ export const ToolDefinitionSchema = z.object({
|
|
|
87
121
|
error_handling: ErrorHandlingSchema.optional(),
|
|
88
122
|
rate_limiting: RateLimitingSchema.optional(),
|
|
89
123
|
requires_approval: z.boolean().optional(),
|
|
124
|
+
risk: z.enum(['low', 'medium', 'high', 'critical']).optional(),
|
|
90
125
|
examples: z
|
|
91
126
|
.array(z.object({
|
|
92
127
|
name: z.string(),
|
|
@@ -97,6 +132,7 @@ export const ToolDefinitionSchema = z.object({
|
|
|
97
132
|
deprecated: z.boolean().optional(),
|
|
98
133
|
tags: z.array(z.string()).optional(),
|
|
99
134
|
deprecation_message: z.string().optional(),
|
|
135
|
+
status: z.enum(['draft', 'approved', 'deprecated']).optional(),
|
|
100
136
|
// _definitionPath: z.string().optional(), // Internal use for tracking source file path
|
|
101
137
|
});
|
|
102
138
|
// export type ToolDefinition = z.infer<typeof ToolDefinitionSchema>;
|