Module: McpUiServer
- Defined in:
- lib/mcp_ui_server.rb,
lib/mcp_ui_server/version.rb
Overview
The McpUiServer module provides helper methods for creating UI resources compatible with the Model Context Protocol UI (mcp-ui) client.
Defined Under Namespace
Classes: Error
Constant Summary collapse
- MIME_TYPE_HTML =
MIME type constants
'text/html'- MIME_TYPE_URI_LIST =
'text/uri-list'- MIME_TYPE_REMOTE_DOM =
'application/vnd.mcp-ui.remote-dom+javascript; framework=%s'- CONTENT_TYPE_RAW_HTML =
Content type constants
:raw_html- CONTENT_TYPE_EXTERNAL_URL =
:external_url- CONTENT_TYPE_REMOTE_DOM =
:remote_dom- PROTOCOL_CONTENT_TYPES =
Protocol mapping (snake_case to camelCase for protocol consistency)
{ raw_html: 'rawHtml', external_url: 'externalUrl', remote_dom: 'remoteDom' }.freeze
- REQUIRED_CONTENT_KEYS =
Required content keys for each content type
{ CONTENT_TYPE_RAW_HTML => :htmlString, CONTENT_TYPE_EXTERNAL_URL => :iframeUrl, CONTENT_TYPE_REMOTE_DOM => :script }.freeze
- UI_URI_SCHEME =
URI scheme constant
'ui://'- VERSION =
'0.1.0'
Class Method Summary collapse
-
.create_ui_resource(uri:, content:, encoding: :text) ⇒ Hash
Creates a UIResource hash structure for an MCP response.
Class Method Details
.create_ui_resource(uri:, content:, encoding: :text) ⇒ Hash
Creates a UIResource hash structure for an MCP response. This structure can then be serialized to JSON by your web framework.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/mcp_ui_server.rb', line 54 def self.create_ui_resource(uri:, content:, encoding: :text) validate_uri_scheme(uri) resource = { uri: uri } content_value = process_content(content, resource) process_encoding(encoding, resource, content_value) { type: 'resource', resource: resource } end |