discourse/plugins/discourse-ai/spec/models/ai_agent_mcp_server_spec.rb
Sam b2d73b346d
FEATURE: Add MCP server integration to AI agents (#38706)
Introduce support for Model Context Protocol (MCP) servers in the
discourse-ai plugin, allowing AI agents to connect to external tool
servers via the MCP standard.

Key additions:
- AiMcpServer model with CRUD admin UI, health tracking, and
  tool caching (hourly refresh via scheduled job)
- MCP client (Streamable HTTP transport) with session management
  and tool invocation
- Full OAuth 2.1 flow support (discovery, dynamic registration,
  authorization code grant, token refresh, and disconnect)
- MCP tool type for AI agents that proxies tool calls to remote
  MCP servers at runtime
- Agent editor updated to show combined tool/token counts from
  both local tools and MCP servers
- Agent import/export includes MCP server associations
- Admin secrets UI updated to surface MCP server usage
- Comprehensive specs for models, controllers, client, tool
  registry, and OAuth flow
2026-03-25 17:32:27 +11:00

23 lines
685 B
Ruby

# frozen_string_literal: true
RSpec.describe AiAgentMcpServer do
fab!(:ai_mcp_server)
before { enable_current_plugin }
it "memoizes serialized tools for count calculations" do
ai_mcp_server
.expects(:tools_for_serialization)
.once
.returns(
[{ name: "search_issues", token_count: 3 }, { name: "create_issue", token_count: 5 }],
)
assignment =
described_class.new(ai_mcp_server: ai_mcp_server, selected_tool_names: ["search_issues"])
expect(assignment.tools_for_serialization).to eq([{ name: "search_issues", token_count: 3 }])
expect(assignment.tool_count).to eq(1)
expect(assignment.token_count).to eq(3)
end
end