You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture/tool.md
+95-14Lines changed: 95 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,15 @@
4
4
5
5
TalkPipe integrates with the Model Context Protocol (MCP) to enable LLMs to call custom tools during conversations. Tools are defined using the `TOOL` syntax in ChatterLang scripts, which compiles TalkPipe pipelines into callable functions that LLMs can invoke.
6
6
7
+
## Unified Server Model
8
+
9
+
Both `TOOL` and `MCP_SERVER` use the same server name concept. The `mcp_server` parameter in `TOOL` references a server that can be either:
10
+
-**Local server**: Automatically created when first `TOOL` uses it
11
+
-**External server**: Explicitly defined via `MCP_SERVER`
12
+
7
13
## TOOL Syntax
8
14
9
-
The `TOOL` keyword in ChatterLang allows you to register TalkPipe pipelines as tools that can be used by LLMs. Tools are registered during script compilation and stored in FastMCP server instances.
15
+
The `TOOL` keyword registers TalkPipe pipelines as tools that can be used by LLMs.
-**`description`** (optional): A description of what the tool does, shown to the LLM
22
28
-**`input_param`** (optional): Input parameter specification in format `"name:type:description"` (e.g., `"item:int:Number to double"`)
23
29
-**`param_name`**, **`param_type`**, **`param_desc`** (optional): Individual parameter specifications as an alternative to `input_param`
24
-
-**`mcp_server`** (optional): The name of the MCP server to register the tool with. Defaults to `"mcp"` if not specified
30
+
-**`mcp_server`** (optional): The name of the MCP server to register the tool with. References a server name (local or external). Defaults to `"mcp"` if not specified
31
+
32
+
## MCP_SERVER Syntax
25
33
26
-
### Example
34
+
The `MCP_SERVER` keyword connects to external MCP servers. Once connected, tools from that server are available for use with `llmPrompt`.
35
+
36
+
### Basic Syntax
27
37
28
38
```chatterlang
29
-
TOOL double = "| lambda[expression='item*2']" [input_param="item:int:Number to double", description="Doubles a number", mcp_server="math_tools"];
30
-
TOOL add_ten = "| lambda[expression='item+10']" [input_param="item:int:Number to add 10 to", description="Adds 10 to a number", mcp_server="math_tools"];
-**`url`** (required): The URL or connection string for the external MCP server
45
+
-**`transport`** (optional): Transport type - `"http"`, `"sse"`, or `"stdio"`. Defaults to `"http"`
46
+
-**`auth`** (optional): Authentication type - `"bearer"` or `"oauth"`
47
+
-**`token`** (optional): Bearer token for authentication
48
+
-**`headers`** (optional): Custom HTTP headers as a dictionary
49
+
-**`command`** (optional): For stdio transport - command to execute
50
+
-**`args`** (optional): For stdio transport - command arguments
51
+
-**`cwd`** (optional): For stdio transport - working directory
52
+
-**`env`** (optional): For stdio transport - environment variables
53
+
54
+
The server is stored in `runtime.const_store[server_name]` and can be referenced in `llmPrompt` using `tools=server_name`.
55
+
56
+
## MCP Server Management
34
57
35
-
You can define multiple MCP servers in a single script by specifying different `mcp_server` values. Each server maintains its own set of tools.
58
+
Both local and external MCP servers use the same server name system. The `mcp_server` parameter in `TOOL` references the server name defined by `MCP_SERVER` or created automatically.
59
+
60
+
### Local Servers (Created Automatically)
61
+
62
+
When you define a `TOOL` with a `mcp_server` parameter, a local FastMCP server is automatically created if it doesn't exist:
36
63
37
64
```chatterlang
38
65
TOOL double = "| lambda[expression='item*2']" [input_param="item:int:Number to double", mcp_server="math_tools"];
39
-
TOOL uppercase = "| lambda[expression='item.upper()']" [input_param="item:str:Text to uppercase", mcp_server="text_tools"];
**Note**: You cannot register local `TOOL` definitions on an external `MCP_SERVER`. External servers provide their own tools that are already available. If you try to register a `TOOL` with `mcp_server` pointing to an external server, a warning will be logged and the tool registration will be skipped.
119
+
120
+
### Server Storage
121
+
122
+
All MCP servers (both local and external) are stored in `runtime.const_store[server_name]` and can be referenced directly in the script using the server name identifier.
43
123
44
124
## Using Tools with LLMPrompt
45
125
@@ -60,11 +140,12 @@ The `tools` parameter accepts the MCP server identifier, which is automatically
60
140
61
141
### Compilation Process
62
142
63
-
1.**Parsing**: The `TOOL` definitions are parsed during script compilation, similar to `CONST` definitions
64
-
2.**Grouping**: Tools are grouped by their `mcp_server` parameter
65
-
3.**Server Creation**: FastMCP instances are created for each unique server name
66
-
4.**Tool Registration**: Each tool is registered with its corresponding MCP server using `register_talkpipe_tool()`
67
-
5.**Storage**: MCP server instances are stored in `runtime.const_store[server_name]` for later reference
143
+
1.**Parsing**: The `MCP_SERVER` and `TOOL` definitions are parsed during script compilation, similar to `CONST` definitions
144
+
2.**External Server Connection**: `MCP_SERVER` definitions create FastMCP Client connections to external servers
145
+
3.**Grouping**: Tools are grouped by their `mcp_server` parameter
146
+
4.**Local Server Creation**: For tools referencing servers that don't exist, local FastMCP server instances are created
147
+
5.**Tool Registration**: Each tool is registered with its corresponding MCP server using `register_talkpipe_tool()` (only for local servers)
148
+
6.**Storage**: All MCP server instances (local and external) are stored in `runtime.const_store[server_name]` for later reference
0 commit comments