Skip to content

Commit dd7193c

Browse files
Document mcp_publish_tool function signatures (closes #21)
- README: Show both overloads with named parameters, note all params are VARCHAR (not JSON type), add example with optional parameter - Reference docs: Add VARCHAR warning admonition, document optional parameter NULL substitution behavior Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9cf5483 commit dd7193c

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,36 @@ SELECT mcp_call_tool('server', 'analyze', '{"dataset": "sales"}');
9595

9696
## Publishing Custom Tools
9797

98+
```sql
99+
-- 5-arg form (JSON output, the default)
100+
PRAGMA mcp_publish_tool(name, description, sql_template, properties_json, required_json);
101+
102+
-- 6-arg form (explicit output format: 'json', 'markdown', or 'csv')
103+
PRAGMA mcp_publish_tool(name, description, sql_template, properties_json, required_json, format);
104+
```
105+
106+
> **All parameters are VARCHAR.** Pass JSON as string literals, not `json_object(...)` or `JSON` type expressions.
107+
108+
**Example:**
109+
98110
```sql
99111
PRAGMA mcp_publish_tool(
100-
'search_products',
101-
'Search products by name',
102-
'SELECT * FROM products WHERE name ILIKE ''%'' || $query || ''%''',
103-
'{"query": {"type": "string", "description": "Search term"}}',
104-
'["query"]',
105-
'markdown'
112+
'search_products', -- name
113+
'Search products by name with optional category filter', -- description
114+
'SELECT * FROM products
115+
WHERE name ILIKE ''%'' || $query || ''%''
116+
AND ($category IS NULL OR category = $category)', -- sql_template ($param placeholders)
117+
'{
118+
"query": {"type": "string", "description": "Search term"},
119+
"category": {"type": "string", "description": "Category filter"}
120+
}', -- properties_json (JSON Schema)
121+
'["query"]', -- required_json (category is optional)
122+
'markdown' -- format
106123
);
107124
```
108125

126+
Optional parameters omitted by callers are substituted as SQL `NULL`. See the [Custom Tools Guide](https://duckdb-mcp.readthedocs.io/guides/custom-tools/) for full details.
127+
109128
## PRAGMA vs SELECT
110129

111130
All server management and publishing functions are available in two forms:

docs/reference/server.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,17 @@ SELECT mcp_publish_tool('name', 'description', 'sql_template', 'properties', 're
270270
| `required` | VARCHAR | JSON array of required parameter names |
271271
| `format` | VARCHAR | Output format: `json`, `csv`, `markdown` (default: `json`) |
272272

273+
!!! warning "All parameters are VARCHAR"
274+
Pass JSON as **string literals**, not `json_object(...)` or `JSON` type expressions. Using `json_object()` produces a `JSON` type which won't match the function signature.
275+
273276
**Parameter Substitution:**
274277

275-
Parameters in the SQL template use `$name` syntax:
278+
Parameters in the SQL template use `$name` syntax. Optional parameters (not listed in `required`) are substituted as SQL `NULL` when omitted or passed as JSON `null`:
276279

277280
```sql
278-
'SELECT * FROM products WHERE category = $category AND price < $max_price'
281+
'SELECT * FROM products
282+
WHERE category = $category
283+
AND ($max_price IS NULL OR price < $max_price)'
279284
```
280285

281286
**Examples:**

0 commit comments

Comments
 (0)