Skip to content

First Class Agent Support and new Toolset feature#135

Open
patvice wants to merge 1 commit intomainfrom
first-class-agent-support
Open

First Class Agent Support and new Toolset feature#135
patvice wants to merge 1 commit intomainfrom
first-class-agent-support

Conversation

@patvice
Copy link
Owner

@patvice patvice commented Mar 1, 2026

Summary

This PR adds a first-class MCP agent/toolset integration so agents can declare which MCP tools to load declaratively and have them automatically wired into ask.

What changed

  • Added a reusable toolset API in RubyLLM::MCP:
    • RubyLLM::MCP.toolset(:name, ...) for declaring reusable MCP tool groups.
    • RubyLLM::MCP.toolsets for introspection/access.
    • Toolset option aliases supported:
      • from_clients / clients / client_names
      • include_tools / include
      • exclude_tools / exclude
  • Added new RubyLLM::MCP::Toolset class:
    • Supports filtering tools by configured MCP clients
    • Supports include/exclude filters
    • De-duplicates tools by name
    • Can materialize resolved tools via #tools / #to_a
  • Added RubyLLM::MCP::Agents concern for RubyLLM::Agent classes:
    • New DSL methods: with_toolsets (with_mcp_tools alias), with_mcps
    • Agent subclasses automatically resolve and attach MCP tools in ask when configured
    • Supports inheritance of toolset/client config
    • Supports combined toolset + direct MCP client resolution with clear configuration errors for unknown names
  • Updated MCP core API and behavior:
    • Added toolset option mapping + apply_toolset_options helper in lib/ruby_llm/mcp.rb
  • Docs/site updates:
    • Added Agents guide link to advanced docs (docs/guides/index.md)
    • Added copy-markdown button and supporting JS/CSS/theme behavior in docs assets (docs/assets/js/copy-markdown.js, docs/_includes/head_custom.html, docs/_sass/custom/custom.scss, docs/_config.yml)

Intended usage example

# config initializer or bootstrapping code
RubyLLM::MCP.toolset(:support, clients: %i[filesystem], include_tools: %w[read_file], exclude: %w[delete_file])

# or block style
RubyLLM::MCP.toolset(:agent_messages) do |ts|
  ts.from_clients :agent_stdio
  ts.include_tools :list_messages
end

class ResearchAgent < RubyLLM::Agent
  include RubyLLM::MCP::Agents

  model "gpt-4.1"
  with_toolsets :support
  # with_mcps :agent_stdio # optional direct MCP client wiring
  # with_mcp_tools :support # alias retained for convenience
end

agent = ResearchAgent.new
agent.ask("Can you check the latest messages and summarize?")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant