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

[MCP] Prompt

Sometimes there are common workflows for people using your MCP server you want to make easier for users. You may not want your users to have to write the same prompt all the time for that workflow (not everyone is a "prompt engineer").
The Model Context Protocol (MCP) has a specification for prompts as a way for servers to expose reusable, structured instructions to language models and clients. Prompts are more than just static text—they can be parameterized and invoked by users to guide model behavior in a consistent, transparent way.
With prompts, servers can offer a menu of available instructions (like "summarize my journal entries from last week," "write alt text for this image" or "review this code"), each with a clear description and customizable arguments. This enables richer, more user-driven interactions, where clients can select and fill in prompts as needed.
 
import { invariant } from '@epic-web/invariant'
import { completable } from '@modelcontextprotocol/sdk/server/completable.js'
import { z } from 'zod'
import { type EpicMeMCP } from './index.ts'export async function initializePrompts(agent: EpicMeMCP) {agent.server.registerPrompt('suggest_tags',{title: 'Suggest Tags',description: 'Suggest tags for a journal entry',argsSchema: {entryId: completable(z.string().describe('The ID of the journal entry to suggest tags for'),async (value) => {const entries = await agent.db.getEntries()return entries.map((entry) => entry.id.toString()).filter((id) => id.includes(value))},),},},async ({ entryId }) => {invariant(entryId, 'entryId is required')const entryIdNum = Number(entryId)invariant(!Number.isNaN(entryIdNum), 'entryId must be a valid number')const entry = await agent.db.getEntry(entryIdNum)invariant(entry, `entry with the ID "${entryId}" not found`)const tags = await agent.db.listTags()return {messages: [{role: 'user',content: {type: 'text',text: `
Below is my EpicMe journal entry with ID "${entryId}" and the tags I have available.Please suggest some tags to add to it. Feel free to suggest new tags I don't have yet.For each tag I approve, if it does not yet exist, create it with the EpicMe "create_tag" tool. Then add approved tags to the entry with the EpicMe "add_tag_to_entry" tool.`.trim(),},},{role: 'user',content: {type: 'resource',resource: {uri: 'epicme://tags',mimeType: 'application/json',text: JSON.stringify(tags),},},},{role: 'user',content: {type: 'resource',resource: {uri: `epicme://entries/${entryId}`,mimeType: 'application/json',text: JSON.stringify(entry),},},},],}},)
}

 

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

相关文章:

  • 从复杂到有序:汽车制造企业多元数据库管理走向自治智能的实践观察
  • 写论文软件哪个好?实测科普!宏智树 AI 凭 “学术真功夫” 成毕业刚需
  • 2026年硅胶模具厂家深度选型指南:食品级与医用级需求下的三大方案解析 - 博客万
  • 【实战项目】 基于springboot的前后端分离学生健康体检管理系统
  • 当 Agent 进入系统阶段,AI 产品开始真正分化
  • 2026年知名的公务车品牌厂家推荐及行业发展解析 - 品牌排行榜
  • 【实战项目】 数字孪生在水利调度中的应用
  • 2026Q1唐山口碑财税公司推荐榜:正规备案为基 - 品牌智鉴榜
  • 【RPA】拼多多商家后台取数口径
  • 【实战项目】 基于单片机激光打靶语音播报系统的设计与实现
  • 2026年盛世笔特国际文化创意产业集团有限公司排名,市场份额情况究竟如何? - 工业品牌热点
  • 9 款 AI 写论文哪个好?实测封神!宏智树 AI 凭硬核实力稳坐头把交椅
  • 【实战项目】 基于DSP新型电能质量监测装置的研究
  • Spring Boot之@Transactional注解实践
  • 2026年聚乙二醇6000粉末厂家权威推荐榜:聚乙二醇6000粉末、聚乙二醇8000、聚乙二醇8000粉末、聚乙二醇10000粉末选择指南 - 优质品牌商家
  • 想入行网络安全?这份零基础入门指南,帮你避开90%的常见学习误区。
  • 【实战项目】 基于Flutter的新闻资讯APP开发
  • 2026年水性联线高光光油厂家选哪家?汇华科技用性能与口碑给出答案 - 博客万
  • RAG不是万能的:没有可观测性,你的系统只是在“碰运气”
  • js 并发任务
  • 【实战项目】 边缘计算设备的安全启动
  • EasyGBS算法算力平台:园区全域智能安防监控体系方案设计
  • 2026年诚信的医疗周转箱,周转箱过滤,定制周转箱厂家采购选型指南 - 品牌鉴赏师
  • 寒假做题记录
  • EasyGBS构筑智慧城市智能可视化监控新生态
  • 数据资产地图 × 全行业适用的智能数据治理解决方案
  • 跨越x86与ARM:openEuler全架构算力实战评测 - 指南
  • 家庭公共WiFi安全终极指南:从密码设置到防蹭网的保姆级防护攻略
  • 网络安全审计核心流程全解析:从日志收集到风险报告的关键指标与实践
  • 以数据化能力推动安全治理落地生效的智能引擎