robot_lab 0.0.1
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.
- checksums.yaml +7 -0
- data/.envrc +1 -0
- data/.github/workflows/deploy-github-pages.yml +52 -0
- data/.github/workflows/deploy-yard-docs.yml +52 -0
- data/CHANGELOG.md +55 -0
- data/COMMITS.md +196 -0
- data/LICENSE.txt +21 -0
- data/README.md +332 -0
- data/Rakefile +67 -0
- data/docs/api/adapters/anthropic.md +121 -0
- data/docs/api/adapters/gemini.md +133 -0
- data/docs/api/adapters/index.md +104 -0
- data/docs/api/adapters/openai.md +134 -0
- data/docs/api/core/index.md +113 -0
- data/docs/api/core/memory.md +314 -0
- data/docs/api/core/network.md +291 -0
- data/docs/api/core/robot.md +273 -0
- data/docs/api/core/state.md +273 -0
- data/docs/api/core/tool.md +353 -0
- data/docs/api/history/active-record-adapter.md +195 -0
- data/docs/api/history/config.md +191 -0
- data/docs/api/history/index.md +132 -0
- data/docs/api/history/thread-manager.md +144 -0
- data/docs/api/index.md +82 -0
- data/docs/api/mcp/client.md +221 -0
- data/docs/api/mcp/index.md +111 -0
- data/docs/api/mcp/server.md +225 -0
- data/docs/api/mcp/transports.md +264 -0
- data/docs/api/messages/index.md +67 -0
- data/docs/api/messages/text-message.md +102 -0
- data/docs/api/messages/tool-call-message.md +144 -0
- data/docs/api/messages/tool-result-message.md +154 -0
- data/docs/api/messages/user-message.md +171 -0
- data/docs/api/streaming/context.md +174 -0
- data/docs/api/streaming/events.md +237 -0
- data/docs/api/streaming/index.md +108 -0
- data/docs/architecture/core-concepts.md +243 -0
- data/docs/architecture/index.md +138 -0
- data/docs/architecture/message-flow.md +320 -0
- data/docs/architecture/network-orchestration.md +216 -0
- data/docs/architecture/robot-execution.md +243 -0
- data/docs/architecture/state-management.md +323 -0
- data/docs/assets/css/custom.css +56 -0
- data/docs/assets/images/robot_lab.jpg +0 -0
- data/docs/concepts.md +216 -0
- data/docs/examples/basic-chat.md +193 -0
- data/docs/examples/index.md +129 -0
- data/docs/examples/mcp-server.md +290 -0
- data/docs/examples/multi-robot-network.md +312 -0
- data/docs/examples/rails-application.md +420 -0
- data/docs/examples/tool-usage.md +310 -0
- data/docs/getting-started/configuration.md +230 -0
- data/docs/getting-started/index.md +56 -0
- data/docs/getting-started/installation.md +179 -0
- data/docs/getting-started/quick-start.md +203 -0
- data/docs/guides/building-robots.md +376 -0
- data/docs/guides/creating-networks.md +366 -0
- data/docs/guides/history.md +359 -0
- data/docs/guides/index.md +68 -0
- data/docs/guides/mcp-integration.md +356 -0
- data/docs/guides/memory.md +309 -0
- data/docs/guides/rails-integration.md +432 -0
- data/docs/guides/streaming.md +314 -0
- data/docs/guides/using-tools.md +394 -0
- data/docs/index.md +160 -0
- data/examples/01_simple_robot.rb +38 -0
- data/examples/02_tools.rb +106 -0
- data/examples/03_network.rb +103 -0
- data/examples/04_mcp.rb +219 -0
- data/examples/05_streaming.rb +124 -0
- data/examples/06_prompt_templates.rb +324 -0
- data/examples/07_network_memory.rb +329 -0
- data/examples/prompts/assistant/system.txt.erb +2 -0
- data/examples/prompts/assistant/user.txt.erb +1 -0
- data/examples/prompts/billing/system.txt.erb +7 -0
- data/examples/prompts/billing/user.txt.erb +1 -0
- data/examples/prompts/classifier/system.txt.erb +4 -0
- data/examples/prompts/classifier/user.txt.erb +1 -0
- data/examples/prompts/entity_extractor/system.txt.erb +11 -0
- data/examples/prompts/entity_extractor/user.txt.erb +3 -0
- data/examples/prompts/escalation/system.txt.erb +35 -0
- data/examples/prompts/escalation/user.txt.erb +34 -0
- data/examples/prompts/general/system.txt.erb +4 -0
- data/examples/prompts/general/user.txt.erb +1 -0
- data/examples/prompts/github_assistant/system.txt.erb +6 -0
- data/examples/prompts/github_assistant/user.txt.erb +1 -0
- data/examples/prompts/helper/system.txt.erb +1 -0
- data/examples/prompts/helper/user.txt.erb +1 -0
- data/examples/prompts/keyword_extractor/system.txt.erb +8 -0
- data/examples/prompts/keyword_extractor/user.txt.erb +3 -0
- data/examples/prompts/order_support/system.txt.erb +27 -0
- data/examples/prompts/order_support/user.txt.erb +22 -0
- data/examples/prompts/product_support/system.txt.erb +30 -0
- data/examples/prompts/product_support/user.txt.erb +32 -0
- data/examples/prompts/sentiment_analyzer/system.txt.erb +9 -0
- data/examples/prompts/sentiment_analyzer/user.txt.erb +3 -0
- data/examples/prompts/synthesizer/system.txt.erb +14 -0
- data/examples/prompts/synthesizer/user.txt.erb +15 -0
- data/examples/prompts/technical/system.txt.erb +7 -0
- data/examples/prompts/technical/user.txt.erb +1 -0
- data/examples/prompts/triage/system.txt.erb +16 -0
- data/examples/prompts/triage/user.txt.erb +17 -0
- data/lib/generators/robot_lab/install_generator.rb +78 -0
- data/lib/generators/robot_lab/robot_generator.rb +55 -0
- data/lib/generators/robot_lab/templates/initializer.rb.tt +41 -0
- data/lib/generators/robot_lab/templates/migration.rb.tt +32 -0
- data/lib/generators/robot_lab/templates/result_model.rb.tt +52 -0
- data/lib/generators/robot_lab/templates/robot.rb.tt +46 -0
- data/lib/generators/robot_lab/templates/robot_test.rb.tt +32 -0
- data/lib/generators/robot_lab/templates/routing_robot.rb.tt +53 -0
- data/lib/generators/robot_lab/templates/thread_model.rb.tt +40 -0
- data/lib/robot_lab/adapters/anthropic.rb +163 -0
- data/lib/robot_lab/adapters/base.rb +85 -0
- data/lib/robot_lab/adapters/gemini.rb +193 -0
- data/lib/robot_lab/adapters/openai.rb +159 -0
- data/lib/robot_lab/adapters/registry.rb +81 -0
- data/lib/robot_lab/configuration.rb +143 -0
- data/lib/robot_lab/error.rb +32 -0
- data/lib/robot_lab/errors.rb +70 -0
- data/lib/robot_lab/history/active_record_adapter.rb +146 -0
- data/lib/robot_lab/history/config.rb +115 -0
- data/lib/robot_lab/history/thread_manager.rb +93 -0
- data/lib/robot_lab/mcp/client.rb +210 -0
- data/lib/robot_lab/mcp/server.rb +84 -0
- data/lib/robot_lab/mcp/transports/base.rb +56 -0
- data/lib/robot_lab/mcp/transports/sse.rb +117 -0
- data/lib/robot_lab/mcp/transports/stdio.rb +133 -0
- data/lib/robot_lab/mcp/transports/streamable_http.rb +139 -0
- data/lib/robot_lab/mcp/transports/websocket.rb +108 -0
- data/lib/robot_lab/memory.rb +882 -0
- data/lib/robot_lab/memory_change.rb +123 -0
- data/lib/robot_lab/message.rb +357 -0
- data/lib/robot_lab/network.rb +350 -0
- data/lib/robot_lab/rails/engine.rb +29 -0
- data/lib/robot_lab/rails/railtie.rb +42 -0
- data/lib/robot_lab/robot.rb +560 -0
- data/lib/robot_lab/robot_result.rb +205 -0
- data/lib/robot_lab/robotic_model.rb +324 -0
- data/lib/robot_lab/state_proxy.rb +188 -0
- data/lib/robot_lab/streaming/context.rb +144 -0
- data/lib/robot_lab/streaming/events.rb +95 -0
- data/lib/robot_lab/streaming/sequence_counter.rb +48 -0
- data/lib/robot_lab/task.rb +117 -0
- data/lib/robot_lab/tool.rb +223 -0
- data/lib/robot_lab/tool_config.rb +112 -0
- data/lib/robot_lab/tool_manifest.rb +234 -0
- data/lib/robot_lab/user_message.rb +118 -0
- data/lib/robot_lab/version.rb +5 -0
- data/lib/robot_lab/waiter.rb +73 -0
- data/lib/robot_lab.rb +195 -0
- data/mkdocs.yml +214 -0
- data/sig/robot_lab.rbs +4 -0
- metadata +442 -0
data/docs/api/index.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# API Reference
|
|
2
|
+
|
|
3
|
+
Complete API documentation for RobotLab.
|
|
4
|
+
|
|
5
|
+
## Core Classes
|
|
6
|
+
|
|
7
|
+
The fundamental building blocks of RobotLab:
|
|
8
|
+
|
|
9
|
+
| Class | Description |
|
|
10
|
+
|-------|-------------|
|
|
11
|
+
| [Robot](core/robot.md) | LLM-powered agent with personality and tools |
|
|
12
|
+
| [Network](core/network.md) | Orchestrates multiple robots |
|
|
13
|
+
| [State](core/state.md) | Manages conversation and workflow data |
|
|
14
|
+
| [Tool](core/tool.md) | Custom function robots can call |
|
|
15
|
+
| [Memory](core/memory.md) | Shared key-value store |
|
|
16
|
+
|
|
17
|
+
## Messages
|
|
18
|
+
|
|
19
|
+
Message types for LLM communication:
|
|
20
|
+
|
|
21
|
+
| Class | Description |
|
|
22
|
+
|-------|-------------|
|
|
23
|
+
| [UserMessage](messages/user-message.md) | User input with metadata |
|
|
24
|
+
| [TextMessage](messages/text-message.md) | Assistant text response |
|
|
25
|
+
| [ToolCallMessage](messages/tool-call-message.md) | Tool execution request |
|
|
26
|
+
| [ToolResultMessage](messages/tool-result-message.md) | Tool execution result |
|
|
27
|
+
|
|
28
|
+
## Adapters
|
|
29
|
+
|
|
30
|
+
Provider-specific message conversion:
|
|
31
|
+
|
|
32
|
+
| Class | Description |
|
|
33
|
+
|-------|-------------|
|
|
34
|
+
| [Anthropic](adapters/anthropic.md) | Claude models adapter |
|
|
35
|
+
| [OpenAI](adapters/openai.md) | GPT models adapter |
|
|
36
|
+
| [Gemini](adapters/gemini.md) | Google Gemini adapter |
|
|
37
|
+
|
|
38
|
+
## MCP (Model Context Protocol)
|
|
39
|
+
|
|
40
|
+
Connect to external tool servers:
|
|
41
|
+
|
|
42
|
+
| Class | Description |
|
|
43
|
+
|-------|-------------|
|
|
44
|
+
| [Client](mcp/client.md) | MCP server connection |
|
|
45
|
+
| [Server](mcp/server.md) | Server configuration |
|
|
46
|
+
| [Transports](mcp/transports.md) | Connection transports |
|
|
47
|
+
|
|
48
|
+
## Streaming
|
|
49
|
+
|
|
50
|
+
Real-time response streaming:
|
|
51
|
+
|
|
52
|
+
| Class | Description |
|
|
53
|
+
|-------|-------------|
|
|
54
|
+
| [Context](streaming/context.md) | Streaming context |
|
|
55
|
+
| [Events](streaming/events.md) | Event utilities |
|
|
56
|
+
|
|
57
|
+
## History
|
|
58
|
+
|
|
59
|
+
Conversation persistence:
|
|
60
|
+
|
|
61
|
+
| Class | Description |
|
|
62
|
+
|-------|-------------|
|
|
63
|
+
| [Config](history/config.md) | History configuration |
|
|
64
|
+
| [ThreadManager](history/thread-manager.md) | Thread lifecycle |
|
|
65
|
+
| [ActiveRecordAdapter](history/active-record-adapter.md) | Rails adapter |
|
|
66
|
+
|
|
67
|
+
## Module Methods
|
|
68
|
+
|
|
69
|
+
### RobotLab
|
|
70
|
+
|
|
71
|
+
```ruby
|
|
72
|
+
# Configuration
|
|
73
|
+
RobotLab.configuration
|
|
74
|
+
RobotLab.configure { |config| ... }
|
|
75
|
+
|
|
76
|
+
# Building
|
|
77
|
+
RobotLab.build { ... }
|
|
78
|
+
RobotLab.create_network { ... }
|
|
79
|
+
RobotLab.create_state(...)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
See individual class documentation for detailed method references.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# MCP Client
|
|
2
|
+
|
|
3
|
+
Connects to MCP servers and discovers tools.
|
|
4
|
+
|
|
5
|
+
## Class: `RobotLab::MCP::Client`
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
client = RobotLab::MCP::Client.new(
|
|
9
|
+
name: "filesystem",
|
|
10
|
+
transport: { type: "stdio", command: "mcp-server-filesystem" }
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
client.connect
|
|
14
|
+
tools = client.list_tools
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Constructor
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
Client.new(name:, transport:)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Parameters:**
|
|
24
|
+
|
|
25
|
+
| Name | Type | Description |
|
|
26
|
+
|------|------|-------------|
|
|
27
|
+
| `name` | `String` | Server identifier |
|
|
28
|
+
| `transport` | `Hash` | Transport configuration |
|
|
29
|
+
|
|
30
|
+
## Attributes
|
|
31
|
+
|
|
32
|
+
### name
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
client.name # => String
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Server identifier.
|
|
39
|
+
|
|
40
|
+
### transport
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
client.transport # => Transport
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The underlying transport connection.
|
|
47
|
+
|
|
48
|
+
### connected?
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
client.connected? # => Boolean
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Whether the client is connected.
|
|
55
|
+
|
|
56
|
+
## Methods
|
|
57
|
+
|
|
58
|
+
### connect
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
client.connect
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Establish connection to the MCP server.
|
|
65
|
+
|
|
66
|
+
### disconnect
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
client.disconnect
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Close the connection.
|
|
73
|
+
|
|
74
|
+
### list_tools
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
client.list_tools # => Array<Tool>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Discover available tools from the server.
|
|
81
|
+
|
|
82
|
+
### call_tool
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
result = client.call_tool(name, params)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Execute a tool on the server.
|
|
89
|
+
|
|
90
|
+
**Parameters:**
|
|
91
|
+
|
|
92
|
+
| Name | Type | Description |
|
|
93
|
+
|------|------|-------------|
|
|
94
|
+
| `name` | `String` | Tool name |
|
|
95
|
+
| `params` | `Hash` | Tool parameters |
|
|
96
|
+
|
|
97
|
+
### list_resources
|
|
98
|
+
|
|
99
|
+
```ruby
|
|
100
|
+
client.list_resources # => Array<Resource>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
List available resources (if supported).
|
|
104
|
+
|
|
105
|
+
### read_resource
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
client.read_resource(uri) # => Resource
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Read a resource by URI.
|
|
112
|
+
|
|
113
|
+
## Transport Configuration
|
|
114
|
+
|
|
115
|
+
### Stdio
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
client = Client.new(
|
|
119
|
+
name: "local",
|
|
120
|
+
transport: {
|
|
121
|
+
type: "stdio",
|
|
122
|
+
command: "npx",
|
|
123
|
+
args: ["@modelcontextprotocol/server-filesystem", "/path"]
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### WebSocket
|
|
129
|
+
|
|
130
|
+
```ruby
|
|
131
|
+
client = Client.new(
|
|
132
|
+
name: "remote",
|
|
133
|
+
transport: {
|
|
134
|
+
type: "websocket",
|
|
135
|
+
url: "wss://mcp.example.com/ws"
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### SSE
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
client = Client.new(
|
|
144
|
+
name: "streaming",
|
|
145
|
+
transport: {
|
|
146
|
+
type: "sse",
|
|
147
|
+
url: "https://mcp.example.com/sse"
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### HTTP
|
|
153
|
+
|
|
154
|
+
```ruby
|
|
155
|
+
client = Client.new(
|
|
156
|
+
name: "http",
|
|
157
|
+
transport: {
|
|
158
|
+
type: "http",
|
|
159
|
+
url: "https://mcp.example.com/mcp"
|
|
160
|
+
}
|
|
161
|
+
)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Examples
|
|
165
|
+
|
|
166
|
+
### Basic Usage
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
client = Client.new(
|
|
170
|
+
name: "github",
|
|
171
|
+
transport: { type: "stdio", command: "mcp-server-github" }
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
client.connect
|
|
175
|
+
|
|
176
|
+
# List available tools
|
|
177
|
+
tools = client.list_tools
|
|
178
|
+
tools.each { |t| puts "#{t.name}: #{t.description}" }
|
|
179
|
+
|
|
180
|
+
# Call a tool
|
|
181
|
+
result = client.call_tool("search_repositories", { query: "ruby mcp" })
|
|
182
|
+
puts result
|
|
183
|
+
|
|
184
|
+
client.disconnect
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### In Robot
|
|
188
|
+
|
|
189
|
+
```ruby
|
|
190
|
+
robot = RobotLab.build do
|
|
191
|
+
name "assistant"
|
|
192
|
+
|
|
193
|
+
mcp [
|
|
194
|
+
{ name: "fs", transport: { type: "stdio", command: "mcp-fs" } }
|
|
195
|
+
]
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
# MCP tools are automatically available
|
|
199
|
+
robot.tools.each { |t| puts t.name }
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Error Handling
|
|
203
|
+
|
|
204
|
+
```ruby
|
|
205
|
+
begin
|
|
206
|
+
client.connect
|
|
207
|
+
result = client.call_tool("unknown_tool", {})
|
|
208
|
+
rescue RobotLab::MCP::ConnectionError => e
|
|
209
|
+
puts "Failed to connect: #{e.message}"
|
|
210
|
+
rescue RobotLab::MCP::ToolError => e
|
|
211
|
+
puts "Tool error: #{e.message}"
|
|
212
|
+
ensure
|
|
213
|
+
client.disconnect
|
|
214
|
+
end
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## See Also
|
|
218
|
+
|
|
219
|
+
- [MCP Overview](index.md)
|
|
220
|
+
- [Transports](transports.md)
|
|
221
|
+
- [MCP Server](server.md)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# MCP (Model Context Protocol)
|
|
2
|
+
|
|
3
|
+
Integration with MCP servers for extended tool capabilities.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
MCP allows robots to connect to external tool servers, extending their capabilities without modifying robot code.
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
robot = RobotLab.build do
|
|
11
|
+
name "developer"
|
|
12
|
+
template "You help with coding tasks."
|
|
13
|
+
|
|
14
|
+
mcp [
|
|
15
|
+
{
|
|
16
|
+
name: "filesystem",
|
|
17
|
+
transport: { type: "stdio", command: "npx @modelcontextprotocol/server-filesystem" }
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
end
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Components
|
|
24
|
+
|
|
25
|
+
| Component | Description |
|
|
26
|
+
|-----------|-------------|
|
|
27
|
+
| [Client](client.md) | Connects to MCP servers |
|
|
28
|
+
| [Server](server.md) | Exposes tools via MCP |
|
|
29
|
+
| [Transports](transports.md) | Communication methods |
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
### Using MCP Tools
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
network = RobotLab.create_network do
|
|
37
|
+
name "with_mcp"
|
|
38
|
+
|
|
39
|
+
mcp [
|
|
40
|
+
{ name: "github", transport: { type: "stdio", command: "mcp-server-github" } }
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
add_robot RobotLab.build {
|
|
44
|
+
name "assistant"
|
|
45
|
+
template "You help with GitHub tasks."
|
|
46
|
+
mcp :inherit # Use network's MCP servers
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Creating an MCP Server
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
server = RobotLab::MCP::Server.new(name: "my_tools")
|
|
55
|
+
|
|
56
|
+
server.add_tool(
|
|
57
|
+
name: "get_user",
|
|
58
|
+
description: "Get user by ID",
|
|
59
|
+
parameters: { id: { type: "string", required: true } },
|
|
60
|
+
handler: ->(id:) { User.find(id).to_h }
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
server.start(transport: :stdio)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Transport Types
|
|
67
|
+
|
|
68
|
+
| Type | Use Case |
|
|
69
|
+
|------|----------|
|
|
70
|
+
| `stdio` | Local command execution |
|
|
71
|
+
| `websocket` | Real-time bidirectional |
|
|
72
|
+
| `sse` | Server-sent events |
|
|
73
|
+
| `http` | HTTP request/response |
|
|
74
|
+
|
|
75
|
+
## Configuration Levels
|
|
76
|
+
|
|
77
|
+
### Network Level
|
|
78
|
+
|
|
79
|
+
```ruby
|
|
80
|
+
network = RobotLab.create_network do
|
|
81
|
+
mcp [
|
|
82
|
+
{ name: "server1", transport: { type: "stdio", command: "..." } }
|
|
83
|
+
]
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Robot Level
|
|
88
|
+
|
|
89
|
+
```ruby
|
|
90
|
+
robot = RobotLab.build do
|
|
91
|
+
mcp :inherit # Use network's servers
|
|
92
|
+
# or
|
|
93
|
+
mcp :none # No MCP servers
|
|
94
|
+
# or
|
|
95
|
+
mcp [...] # Specific servers
|
|
96
|
+
end
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Tool Filtering
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
robot = RobotLab.build do
|
|
103
|
+
mcp :inherit
|
|
104
|
+
tools %w[read_file write_file] # Only allow these tools
|
|
105
|
+
end
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## See Also
|
|
109
|
+
|
|
110
|
+
- [MCP Integration Guide](../../guides/mcp-integration.md)
|
|
111
|
+
- [Tool](../core/tool.md)
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# MCP Server
|
|
2
|
+
|
|
3
|
+
Expose tools via Model Context Protocol.
|
|
4
|
+
|
|
5
|
+
## Class: `RobotLab::MCP::Server`
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
server = RobotLab::MCP::Server.new(name: "my_tools")
|
|
9
|
+
|
|
10
|
+
server.add_tool(
|
|
11
|
+
name: "get_time",
|
|
12
|
+
description: "Get current time",
|
|
13
|
+
handler: ->(**_) { Time.now.iso8601 }
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
server.start(transport: :stdio)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Constructor
|
|
20
|
+
|
|
21
|
+
```ruby
|
|
22
|
+
Server.new(name:, version: "1.0.0")
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Parameters:**
|
|
26
|
+
|
|
27
|
+
| Name | Type | Description |
|
|
28
|
+
|------|------|-------------|
|
|
29
|
+
| `name` | `String` | Server name |
|
|
30
|
+
| `version` | `String` | Server version |
|
|
31
|
+
|
|
32
|
+
## Attributes
|
|
33
|
+
|
|
34
|
+
### name
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
server.name # => String
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Server identifier.
|
|
41
|
+
|
|
42
|
+
### version
|
|
43
|
+
|
|
44
|
+
```ruby
|
|
45
|
+
server.version # => String
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Server version.
|
|
49
|
+
|
|
50
|
+
### tools
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
server.tools # => Array<Tool>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Registered tools.
|
|
57
|
+
|
|
58
|
+
## Methods
|
|
59
|
+
|
|
60
|
+
### add_tool
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
server.add_tool(
|
|
64
|
+
name:,
|
|
65
|
+
description:,
|
|
66
|
+
parameters: {},
|
|
67
|
+
handler:
|
|
68
|
+
)
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Register a tool with the server.
|
|
72
|
+
|
|
73
|
+
**Parameters:**
|
|
74
|
+
|
|
75
|
+
| Name | Type | Description |
|
|
76
|
+
|------|------|-------------|
|
|
77
|
+
| `name` | `String` | Tool name |
|
|
78
|
+
| `description` | `String` | Tool description |
|
|
79
|
+
| `parameters` | `Hash` | Parameter schema |
|
|
80
|
+
| `handler` | `Proc` | Execution function |
|
|
81
|
+
|
|
82
|
+
### remove_tool
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
server.remove_tool(name)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Unregister a tool.
|
|
89
|
+
|
|
90
|
+
### start
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
server.start(transport: :stdio, **options)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Start the server.
|
|
97
|
+
|
|
98
|
+
**Transport Options:**
|
|
99
|
+
|
|
100
|
+
| Transport | Options |
|
|
101
|
+
|-----------|---------|
|
|
102
|
+
| `:stdio` | None |
|
|
103
|
+
| `:websocket` | `port:`, `host:` |
|
|
104
|
+
| `:sse` | `port:`, `host:`, `path:` |
|
|
105
|
+
| `:http` | `port:`, `host:`, `path:` |
|
|
106
|
+
|
|
107
|
+
### stop
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
server.stop
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Stop the server.
|
|
114
|
+
|
|
115
|
+
## Examples
|
|
116
|
+
|
|
117
|
+
### Basic Server
|
|
118
|
+
|
|
119
|
+
```ruby
|
|
120
|
+
server = RobotLab::MCP::Server.new(name: "utilities")
|
|
121
|
+
|
|
122
|
+
server.add_tool(
|
|
123
|
+
name: "echo",
|
|
124
|
+
description: "Echo back the input",
|
|
125
|
+
parameters: {
|
|
126
|
+
message: { type: "string", required: true }
|
|
127
|
+
},
|
|
128
|
+
handler: ->(message:) { message }
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
server.start(transport: :stdio)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Database Tools Server
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
server = RobotLab::MCP::Server.new(name: "database")
|
|
138
|
+
|
|
139
|
+
server.add_tool(
|
|
140
|
+
name: "query_users",
|
|
141
|
+
description: "Query users by criteria",
|
|
142
|
+
parameters: {
|
|
143
|
+
status: { type: "string", enum: ["active", "inactive"] },
|
|
144
|
+
limit: { type: "integer", default: 10 }
|
|
145
|
+
},
|
|
146
|
+
handler: ->(status: nil, limit: 10) {
|
|
147
|
+
scope = User.all
|
|
148
|
+
scope = scope.where(status: status) if status
|
|
149
|
+
scope.limit(limit).map(&:to_h)
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
server.add_tool(
|
|
154
|
+
name: "get_user",
|
|
155
|
+
description: "Get user by ID",
|
|
156
|
+
parameters: {
|
|
157
|
+
id: { type: "string", required: true }
|
|
158
|
+
},
|
|
159
|
+
handler: ->(id:) {
|
|
160
|
+
user = User.find_by(id: id)
|
|
161
|
+
user ? user.to_h : { error: "Not found" }
|
|
162
|
+
}
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
server.start(transport: :websocket, port: 8080)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### From Robot Tools
|
|
169
|
+
|
|
170
|
+
```ruby
|
|
171
|
+
# Convert existing robot tools to MCP server
|
|
172
|
+
robot = RobotLab.build do
|
|
173
|
+
name "assistant"
|
|
174
|
+
|
|
175
|
+
tool :calculate do
|
|
176
|
+
description "Perform calculation"
|
|
177
|
+
parameter :expression, type: :string, required: true
|
|
178
|
+
handler { |expression:, **_| eval(expression) }
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
server = RobotLab::MCP::Server.from_robot(robot)
|
|
183
|
+
server.start(transport: :stdio)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### HTTP Server
|
|
187
|
+
|
|
188
|
+
```ruby
|
|
189
|
+
server = RobotLab::MCP::Server.new(name: "api_tools")
|
|
190
|
+
|
|
191
|
+
server.add_tool(
|
|
192
|
+
name: "fetch_data",
|
|
193
|
+
description: "Fetch data from API",
|
|
194
|
+
parameters: {
|
|
195
|
+
endpoint: { type: "string", required: true }
|
|
196
|
+
},
|
|
197
|
+
handler: ->(endpoint:) {
|
|
198
|
+
response = HTTP.get("https://api.example.com/#{endpoint}")
|
|
199
|
+
JSON.parse(response.body)
|
|
200
|
+
}
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
server.start(transport: :http, port: 3001, path: "/mcp")
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### With Resources
|
|
207
|
+
|
|
208
|
+
```ruby
|
|
209
|
+
server = RobotLab::MCP::Server.new(name: "files")
|
|
210
|
+
|
|
211
|
+
server.add_resource(
|
|
212
|
+
uri: "file://config",
|
|
213
|
+
name: "Configuration",
|
|
214
|
+
description: "Application configuration",
|
|
215
|
+
handler: -> { File.read("config.yml") }
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
server.start(transport: :stdio)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## See Also
|
|
222
|
+
|
|
223
|
+
- [MCP Overview](index.md)
|
|
224
|
+
- [MCP Client](client.md)
|
|
225
|
+
- [Transports](transports.md)
|