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.

Examples:

Define a tool

LanguageOperator::Dsl.define do
  tool "greet" do
    description "Greet a user by name"

    parameter :name do
      type :string
      required true
      description "Name to greet"
    end

    execute do |params|
      "Hello, #{params['name']}!"
    end
  end
end

Access tools

registry = LanguageOperator::Dsl.registry
tool = registry.get("greet")
result = tool.call({"name" => "Alice"})

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

Class Method Details

.agent_registryAgentRegistry

Global registry for agents

Returns:



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

Examples:

server = LanguageOperator::Dsl.create_server(server_name: "my-tools")

Parameters:

  • server_name (String) (defaults to: 'langop-tools')

    Name of the MCP server

  • server_context (Hash) (defaults to: {})

    Additional context for the server

Returns:

  • (MCP::Server)

    The MCP server instance



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

Examples:

LanguageOperator::Dsl.define do
  tool "example" do
    # ...
  end
end

Yields:

  • Block containing tool definitions

Returns:

  • (Registry)

    The global registry with defined tools



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

Examples:

LanguageOperator::Dsl.define_agents do
  agent "news-summarizer" do
    # ...
  end
end

Yields:

  • Block containing agent definitions

Returns:



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

Examples:

LanguageOperator::Dsl.load_agent_file("agents/news-summarizer.rb")

Parameters:

  • file_path (String)

    Path to the agent definition file

Returns:

Raises:



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_permission_denied(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.message, '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

Examples:

LanguageOperator::Dsl.load_file("mcp/tools.rb")

Parameters:

  • file_path (String)

    Path to the tool definition file

Returns:

  • (Registry)

    The global registry with loaded tools

Raises:



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_permission_denied(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.message, '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

.registryRegistry

Global registry for tools

Returns:

  • (Registry)

    The global tool registry



52
53
54
# File 'lib/language_operator/dsl.rb', line 52

def registry
  @registry ||= Registry.new
end