{ uri: string; // Unique identifier for the resource name: string; // Human-readable name description?: string; // Optional description mimeType?: string; // Optional MIME type }
资源模板
对于动态资源,服务器可以公开URI模板,客户端可以使用它来构建有效资源URI:
动态资源模板定义格式
1 2 3 4 5 6
{ uriTemplate: string; // URI template following RFC 6570 name: string; // Human-readable name for this type description?: string; // Optional description mimeType?: string; // Optional MIME type for all matching resources }
读取资源
要读取资源,客户端需要使用资源 URI 发出resources/read请求。
服务器以资源内容列表进行响应:
服务器资源响应定义格式
1 2 3 4 5 6 7 8 9 10 11 12
{ contents:[ { uri: string; // The URI of the resource mimeType?: string; // Optional MIME type
// One of: text?: string; // For text resources blob?: string; // For binary resources (base64 encoded) } ] }
// Response { description:"Analyze Python code for potential improvements", messages:[ { role:"user", content:{ type:"text", text:"Please analyze the following Python code for potential improvements:\n\n```python\ndef calculate_sum(numbers):\n total = 0\n for num in numbers:\n total = total + num\n return total\n\nresult = calculate_sum([1, 2, 3, 4, 5])\nprint(result)\n```" } } ] }
动态提示
提示可以是动态的,包括:
嵌入资源上下文
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
{ "name":"analyze-project", "description":"Analyze project logs and code", "arguments":[ { "name":"timeframe", "description":"Time period to analyze logs", "required":true }, { "name":"fileUri", "description":"URI of code file to review", "required":true } ] }