Skip to content

Commit 9b712fc

Browse files
committed
Add docs for flexible args
1 parent 5048a54 commit 9b712fc

1 file changed

Lines changed: 144 additions & 5 deletions

File tree

docs/mcp/custom-tools.md

Lines changed: 144 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,14 @@ The `schema` property allows you to define the expected arguments for a tool usi
363363

364364
### Schema Configuration Properties
365365

366-
| Property | Type | Required | Description |
367-
|--------------|--------|----------|----------------------------------|
368-
| `type` | string | Yes | Schema type (typically `object`) |
369-
| `properties` | object | No | Properties definition |
370-
| `required` | array | No | List of required properties |
366+
| Property | Type | Required | Description |
367+
|---------------------|---------|----------|--------------------------------------------------------------|
368+
| `type` | string | Yes | Schema type (typically `object`) |
369+
| `properties` | object | No | Properties definition |
370+
| `required` | array | No | List of required properties |
371+
| `flexibleArg` | string | No | Name of a container argument for dynamic parameters |
372+
| `blockedProperties` | array | No | List of argument names that are forbidden |
373+
| `allowAny` | boolean | No | Allow any additional properties (for compatible MCP clients) |
371374

372375
### Property Configuration
373376

@@ -395,6 +398,142 @@ schema:
395398
required: [ name ]
396399
```
397400

401+
### Flexible Arguments
402+
403+
The `flexibleArg` feature allows AI to pass arbitrary parameters through a container argument. This is particularly
404+
useful when:
405+
406+
- MCP clients filter arguments strictly by the schema's `properties`
407+
- You need dynamic argument support without knowing all parameters in advance
408+
- You want to create truly flexible tools where AI decides what parameters to use
409+
410+
#### How It Works
411+
412+
1. Define a container property (e.g., `args`) with `type: object`
413+
2. Set `flexibleArg` to the container property name
414+
3. AI passes parameters inside the container object
415+
4. CTX unpacks the container, making all nested properties available as template variables
416+
417+
#### Flexible Arguments Example
418+
419+
```yaml
420+
tools:
421+
- id: bash
422+
description: 'Execute any bash command'
423+
type: run
424+
schema:
425+
flexibleArg: args
426+
blockedProperties:
427+
- password
428+
- secret
429+
- token
430+
- apiKey
431+
properties:
432+
args:
433+
type: object
434+
description: 'Object with cmd: {"cmd": "ls -la /tmp"}'
435+
commands:
436+
- cmd: bash
437+
args:
438+
- "-c"
439+
- "{{cmd}}"
440+
```
441+
442+
**AI Input:**
443+
444+
```json
445+
{
446+
"args": {
447+
"cmd": "date +%Y-%m-%d"
448+
}
449+
}
450+
```
451+
452+
**Result:** The `{{cmd}}` variable is replaced with `date +%Y-%m-%d` and executed.
453+
454+
#### Blocked Properties (Security)
455+
456+
The `blockedProperties` option prevents sensitive argument names from being used. If AI attempts to pass a blocked
457+
argument, the tool execution fails with a clear error message.
458+
459+
```yaml
460+
schema:
461+
flexibleArg: args
462+
blockedProperties:
463+
- password
464+
- secret
465+
- token
466+
- apiKey
467+
- credentials
468+
```
469+
470+
**Blocked Argument Example:**
471+
472+
```json
473+
{
474+
"args": {
475+
"cmd": "echo test",
476+
"password": "secret123"
477+
}
478+
}
479+
```
480+
481+
**Error:**
482+
`Argument "password" is blocked and cannot be used. Blocked arguments: password, secret, token, apiKey, credentials`
483+
484+
#### Multiple Dynamic Variables
485+
486+
You can use multiple variables from the unpacked container:
487+
488+
```yaml
489+
tools:
490+
- id: flexible-echo
491+
description: 'Echo with flexible arguments'
492+
type: run
493+
schema:
494+
flexibleArg: args
495+
properties:
496+
args:
497+
type: object
498+
description: 'Any arguments: {"message": "Hello", "name": "World"}'
499+
commands:
500+
- cmd: echo
501+
args:
502+
- "Message: {{message}}, Name: {{name}}"
503+
```
504+
505+
**AI Input:**
506+
507+
```json
508+
{
509+
"args": {
510+
"message": "Hello",
511+
"name": "World"
512+
}
513+
}
514+
```
515+
516+
**Output:** `Message: Hello, Name: World`
517+
518+
#### Allow Any Properties
519+
520+
For MCP clients that support `additionalProperties` in JSON Schema, you can use `allowAny`:
521+
522+
```yaml
523+
schema:
524+
allowAny: true
525+
blockedProperties:
526+
- password
527+
- secret
528+
properties:
529+
query:
530+
type: string
531+
description: "Search query"
532+
```
533+
534+
This sets `additionalProperties: true` in the JSON Schema, allowing any additional properties beyond those defined in
535+
`properties`.
536+
398537
## Advanced Features
399538

400539
### Template Variables

0 commit comments

Comments
 (0)