mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 02:05:37 +08:00
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
25 lines
738 B
Ruby
Vendored
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
|
|
#
|