discourse/plugins/discourse-ai/app/models/ai_mcp_oauth_token.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

25 lines
738 B
Ruby
Vendored

# frozen_string_literal: true
class AiMcpOauthToken < ActiveRecord::Base
belongs_to :ai_mcp_server, inverse_of: :oauth_token
validates :ai_mcp_server_id, uniqueness: true
validates :access_token, length: { maximum: 10_000 }, allow_blank: true
validates :refresh_token, length: { maximum: 10_000 }, allow_blank: true
end
# == Schema Information
#
# Table name: ai_mcp_oauth_tokens
#
# id :bigint not null, primary key
# access_token :text
# refresh_token :text
# created_at :datetime not null
# updated_at :datetime not null
# ai_mcp_server_id :bigint not null
#
# Indexes
#
# index_ai_mcp_oauth_tokens_on_ai_mcp_server_id (ai_mcp_server_id) UNIQUE
#