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/core/tools-api.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,11 @@ The LLxprt Code core (`packages/core`) features a robust system for defining, re
15
15
-`execute()`: The core method that performs the tool's action and returns a `ToolResult`.
16
16
17
17
-**`ToolResult` (`tools.ts`):** An interface defining the structure of a tool's execution outcome:
18
-
-`llmContent`: The factual string content to be included in the history sent back to the LLM for context.
18
+
-`llmContent`: The factual content to be included in the history sent back to the LLM for context. This can be a simple string or a `PartListUnion` (an array of `Part` objects and strings) for rich content.
19
19
-`returnDisplay`: A user-friendly string (often Markdown) or a special object (like `FileDiff`) for display in the CLI.
20
20
21
+
-**Returning Rich Content:** Tools are not limited to returning simple text. The `llmContent` can be a `PartListUnion`, which is an array that can contain a mix of `Part` objects (for images, audio, etc.) and `string`s. This allows a single tool execution to return multiple pieces of rich content.
22
+
21
23
-**Tool Registry (`tool-registry.ts`):** A class (`ToolRegistry`) responsible for:
22
24
-**Registering Tools:** Holding a collection of all available built-in tools (e.g., `ReadFileTool`, `ShellTool`).
23
25
-**Discovering Tools:** It can also discover tools dynamically:
Copy file name to clipboardExpand all lines: docs/tools/mcp-server.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -571,6 +571,56 @@ The MCP integration tracks several states:
571
571
572
572
This comprehensive integration makes MCP servers a powerful way to extend the LLxprt Code's capabilities while maintaining security, reliability, and ease of use.
573
573
574
+
## Returning Rich Content from Tools
575
+
576
+
MCP tools are not limited to returning simple text. You can return rich, multi-part content, including text, images, audio, and other binary data in a single tool response. This allows you to build powerful tools that can provide diverse information to the model in a single turn.
577
+
578
+
All data returned from the tool is processed and sent to the model as context for its next generation, enabling it to reason about or summarize the provided information.
579
+
580
+
### How It Works
581
+
582
+
To return rich content, your tool's response must adhere to the MCP specification for a [`CallToolResult`](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool-result). The `content` field of the result should be an array of `ContentBlock` objects. The Gemini CLI will correctly process this array, separating text from binary data and packaging it for the model.
583
+
584
+
You can mix and match different content block types in the `content` array. The supported block types include:
585
+
586
+
-`text`
587
+
-`image`
588
+
-`audio`
589
+
-`resource` (embedded content)
590
+
-`resource_link`
591
+
592
+
### Example: Returning Text and an Image
593
+
594
+
Here is an example of a valid JSON response from an MCP tool that returns both a text description and an image:
595
+
596
+
```json
597
+
{
598
+
"content": [
599
+
{
600
+
"type": "text",
601
+
"text": "Here is the logo you requested."
602
+
},
603
+
{
604
+
"type": "image",
605
+
"data": "BASE64_ENCODED_IMAGE_DATA_HERE",
606
+
"mimeType": "image/png"
607
+
},
608
+
{
609
+
"type": "text",
610
+
"text": "The logo was created in 2025."
611
+
}
612
+
]
613
+
}
614
+
```
615
+
616
+
When the Gemini CLI receives this response, it will:
617
+
618
+
1. Extract all the text and combine it into a single `functionResponse` part for the model.
619
+
2. Present the image data as a separate `inlineData` part.
620
+
3. Provide a clean, user-friendly summary in the CLI, indicating that both text and an image were received.
621
+
622
+
This enables you to build sophisticated tools that can provide rich, multi-modal context to the Gemini model.
623
+
574
624
## MCP Prompts as Slash Commands
575
625
576
626
In addition to tools, MCP servers can expose predefined prompts that can be executed as slash commands within the LLxprt Code. This allows you to create shortcuts for common or complex queries that can be easily invoked by name.
0 commit comments