当前位置: 首页 > news >正文

[MCP] Simple MCP UI

 MCP UI enables servers to send rich, interactive user interfaces along with their responses, transforming AI chat from text-only interactions into visually engaging experiences. Instead of just returning plain text, your MCP server can now provide HTML content that clients can render as actual UI components.
This capability opens up entirely new possibilities for AI applications. Instead of describing a chart or form, you can actually show one. Instead of listing data in text format, you can present it in a beautiful, interactive interface.
Example:
import { createUIResource } from '@mcp-ui/server'// Create a UI resource with raw HTML
const resource = await createUIResource({uri: 'ui://weather-card/lagos-nigeria',content: {type: 'rawHtml',htmlString: `<div style="padding: 20px; border: 1px solid #ccc; border-radius: 8px; background: linear-gradient(135deg, #74b9ff, #0984e3); color: white;"><h1>Lagos, Nigeria</h1><p>85°F - Partly Cloudy</p><p>Humidity: 78% | Wind: 12 mph</p></div>`,},encoding: 'text',
})
The createUIResource function is the foundation of MCP UI. It takes your HTML content and packages it into a format that MCP clients can understand and render. The uri parameter creates a unique identifier for your UI resource, while the content specifies what type of UI you're providing.

 

Here's how this works in practice. When an AI assistant needs to show weather information, instead of returning plain text like "Lagos, Nigeria: 85°F, Partly Cloudy, Humidity: 78%", it can return a UI resource that renders as an actual visual weather card with proper styling and structure.
The MCP UI specification defines several content types, but we'll start with the simplest: rawHtml. This allows you to send any HTML string that will be rendered directly by the client. This is perfect for static content, simple layouts, and getting started with UI in MCP.
 
From the MCP UI documentation: Raw HTML content is delivered as text/html MIME type and can include any valid HTML markup, making it ideal for simple UI components and static content display.
  • 📜 MCP UI Server Documentation

 

Code:

查看代码
	agent.server.registerTool('view_tag',{title: 'View Tag',description: 'View a tag by ID visually',annotations: {readOnlyHint: true,openWorldHint: false,} satisfies ToolAnnotations,inputSchema: tagIdSchema,},async ({ id }) => {const tag = await agent.db.getTag(id)const html = tag? `<div><h1>${tag.name}</h1><p>${tag.description}</p></div>`: `<div>Tag "${id}" not found</div>`return {content: [await createUIResource({uri: `ui://view-tag/${id}`,content: {type: 'rawHtml',htmlString: html,},encoding: 'text',}),],}},)

 

http://www.jsqmd.com/news/317464/

相关文章:

  • 户外爆品,一站链全球!2026首届“宝品出海”跨境电商嘉年华暨湾区户外科技国际生活节震撼启幕!
  • 塑料垃圾桶价格多少钱,有美工贸性价比高不?
  • 分析大型考研集训基地怎么选,思研考研靠谱吗
  • 盘点湖北中医药大学中医师承深造班,学员真实评价与适用从业者
  • 聊聊智能窑胴体扫描仪品牌推荐与性价比分析
  • 切换node版本--nvm
  • 适合办公室吃的健康零食品牌推荐:独立小包装、低糖高纤维真的很重要
  • 共赴鹏城之约:2026湾区户外科技生活盛会,全景链接全球商机
  • 避坑!长沙小红书服务商实测,刷数据和真种草一眼分清
  • 大话大模型应用(二)--让大模型听话:Prompt EngineeringContext Engineering - 详解
  • AOT编译与JIT编译在性能优化上的具体对比分析,各自适用哪些场景?
  • 精准解码组织微环境:DSP 空间蛋白组技术,赋能疾病研究新维度
  • Java ThreadLocal 源码分析
  • 2026年口碑好的工业温度控制设备公司推荐,常州阿科牧机械靠谱吗
  • Java SPI机制:从原理到实战
  • 国自然热门|中性粒细胞趋化因子作用,一文读懂
  • Java怎么在数据库里配置多个数据源,然后进行动态切换?
  • 总结缙云值得推荐的冷轧钢带公司,排名如何?
  • 推荐窑胴体扫描仪制造商有哪些,铭耀机电价格贵不贵
  • 2026深圳产业园办公室及科技孵化园出租推荐
  • 软银/英伟达/红杉资本/贝佐斯等参投,机器人初创公司Skild AI融资14亿美元,打造通用基础模型
  • 【ES】[其他] ---- 忘记 Elasticsearch 8.0 密钥与账号密码?两步轻松重置与生成?
  • 基差风险管理系统操作日志导出与审计应用
  • 企业风险管理系统派生报表设计与实现
  • 基差风险管理系统冲突预警模块设计与实现
  • 2026年学习桌椅品牌权威推荐榜:预算3-8k配置密度与实木环保颜值深度对比
  • 套期保值管理系统系统监控工具与应用实践
  • QPainterPath判断点是否在路径内
  • 企业套保策略平台合同与交易联动机制
  • 国内外水处理设备哪家好?2026最新厂家推荐,涵盖定制、全自动、专业级全品类