Module: LanguageOperator::Dsl
- Defined in:
- lib/language_operator/dsl.rb,
lib/language_operator/dsl/http.rb,
lib/language_operator/dsl/shell.rb,
lib/language_operator/dsl/config.rb,
lib/language_operator/dsl/schema.rb,
lib/language_operator/dsl/adapter.rb,
lib/language_operator/dsl/context.rb,
lib/language_operator/dsl/helpers.rb,
lib/language_operator/dsl/registry.rb,
lib/language_operator/dsl/agent_context.rb,
lib/language_operator/dsl/main_definition.rb,
lib/language_operator/dsl/task_definition.rb,
lib/language_operator/dsl/tool_definition.rb,
lib/language_operator/dsl/agent_definition.rb,
lib/language_operator/dsl/execution_context.rb,
lib/language_operator/dsl/webhook_definition.rb,
lib/language_operator/dsl/parameter_definition.rb,
lib/language_operator/dsl/mcp_server_definition.rb,
lib/language_operator/dsl/webhook_authentication.rb,
lib/language_operator/dsl/chat_endpoint_definition.rb
Overview
DSL for defining MCP tools and autonomous agents
Provides a clean, Ruby-like DSL for defining tools that can be served via the Model Context Protocol (MCP) and agents that can execute autonomously.
Defined Under Namespace
Modules: Helpers, Shell Classes: Adapter, AgentContext, AgentDefinition, AgentRegistry, ChatEndpointDefinition, Config, ConstraintBuilder, Context, ExecutionContext, HTTP, MainDefinition, McpServerDefinition, ParameterDefinition, Registry, Schema, TaskDefinition, ToolDefinition, WebhookAuthentication, WebhookDefinition
Class Method Summary collapse
-
.agent_registry ⇒ AgentRegistry
Global registry for agents.
-
.clear! ⇒ void
Clear all defined tools.
-
.clear_agents! ⇒ void
Clear all defined agents.
-
.create_server(server_name: 'langop-tools', server_context: {}) ⇒ MCP::Server
Create an MCP server from the defined tools.
-
.define { ... } ⇒ Registry
Define tools using the DSL.
-
.define_agents { ... } ⇒ AgentRegistry
Define agents using the DSL.
-
.load_agent_file(file_path) ⇒ AgentRegistry
Load agents from a file.
-
.load_file(file_path) ⇒ Registry
Load tools from a file.
-
.registry ⇒ Registry
Global registry for tools.
Class Method Details
.agent_registry ⇒ AgentRegistry
Global registry for agents
59 60 61 |
# File 'lib/language_operator/dsl.rb', line 59 def agent_registry @agent_registry ||= AgentRegistry.new end |
.clear! ⇒ void
This method returns an undefined value.
Clear all defined tools
190 191 192 |
# File 'lib/language_operator/dsl.rb', line 190 def clear! registry.clear end |
.clear_agents! ⇒ void
This method returns an undefined value.
Clear all defined agents
197 198 199 |
# File 'lib/language_operator/dsl.rb', line 197 def clear_agents! agent_registry.clear end |
.create_server(server_name: 'langop-tools', server_context: {}) ⇒ MCP::Server
Create an MCP server from the defined tools
209 210 211 |
# File 'lib/language_operator/dsl.rb', line 209 def create_server(server_name: 'langop-tools', server_context: {}) Adapter.create_mcp_server(registry, server_name: server_name, server_context: server_context) end |
.define { ... } ⇒ Registry
Define tools using the DSL
74 75 76 77 78 |
# File 'lib/language_operator/dsl.rb', line 74 def define(&) context = Context.new(registry) context.instance_eval(&) registry end |
.define_agents { ... } ⇒ AgentRegistry
Define agents using the DSL
91 92 93 94 95 |
# File 'lib/language_operator/dsl.rb', line 91 def define_agents(&) context = AgentContext.new(agent_registry) context.instance_eval(&) agent_registry end |
.load_agent_file(file_path) ⇒ AgentRegistry
Load agents from a file
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/language_operator/dsl.rb', line 153 def load_agent_file(file_path) # Validate file path to prevent path traversal attacks validated_path = validate_file_path!(file_path, context: 'agent definition file loading') # Check if file exists raise FileNotFoundError, Errors.file_not_found(file_path, 'agent definition file') unless File.exist?(validated_path) # Attempt to read the file begin code = File.read(validated_path) rescue Errno::EACCES raise FilePermissionError, Errors.(file_path, 'agent definition file') rescue Errno::EISDIR raise FileNotFoundError, Errors.file_not_found(file_path, 'agent definition file') rescue SystemCallError => e raise FileLoadError, "Error reading agent definition file '#{file_path}': #{e.message}" end context = AgentContext.new(agent_registry) # Execute in sandbox with validation begin executor = Agent::Safety::SafeExecutor.new(context) executor.eval(code, validated_path) rescue SyntaxError => e raise FileSyntaxError, Errors.file_syntax_error(file_path, e., 'agent definition file') rescue StandardError => e # Re-raise with additional context for other execution errors raise FileLoadError, "Error executing agent definition file '#{file_path}': #{e.message}" end agent_registry end |
.load_file(file_path) ⇒ Registry
Load tools from a file
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/language_operator/dsl.rb', line 108 def load_file(file_path) # Validate file path to prevent path traversal attacks validated_path = validate_file_path!(file_path, context: 'tool definition file loading') # Check if file exists raise FileNotFoundError, Errors.file_not_found(file_path, 'tool definition file') unless File.exist?(validated_path) # Attempt to read the file begin code = File.read(validated_path) rescue Errno::EACCES raise FilePermissionError, Errors.(file_path, 'tool definition file') rescue Errno::EISDIR raise FileNotFoundError, Errors.file_not_found(file_path, 'tool definition file') rescue SystemCallError => e raise FileLoadError, "Error reading tool definition file '#{file_path}': #{e.message}" end context = Context.new(registry) # Execute in sandbox with validation begin executor = Agent::Safety::SafeExecutor.new(context) executor.eval(code, validated_path) rescue SyntaxError => e raise FileSyntaxError, Errors.file_syntax_error(file_path, e., 'tool definition file') rescue StandardError => e # Re-raise with additional context for other execution errors raise FileLoadError, "Error executing tool definition file '#{file_path}': #{e.message}" end registry end |
.registry ⇒ Registry
Global registry for tools
52 53 54 |
# File 'lib/language_operator/dsl.rb', line 52 def registry @registry ||= Registry.new end |