name: mcp-resource-uri-designer description: 设计和实现MCP资源URI方案和模板,包括适当的命名、层次结构和文档。 allowed-tools: Read, Write, Edit, Bash, Glob, Grep
MCP资源URI设计器
为MCP服务器设计和实现资源URI方案。
能力
- 为资源设计URI方案
- 创建URI模板模式
- 生成URI解析工具
- 记录资源层次结构
- 实现内容类型映射
- 创建资源发现机制
使用场景
在以下情况下调用此技能:
- 为MCP资源设计URI方案
- 创建URI模板模式
- 实现资源层次结构
- 记录资源API
输入参数
| 参数 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| domain | 字符串 | 是 | 资源领域(例如:文件、数据库) |
| resources | 数组 | 是 | 资源定义 |
| language | 字符串 | 否 | 实现语言(默认:typescript) |
资源结构
{
"domain": "database",
"resources": [
{
"pattern": "db://{database}/tables/{table}",
"name": "数据库表",
"description": "访问数据库表结构和数据",
"mimeType": "application/json",
"parameters": {
"database": { "description": "数据库名称" },
"table": { "description": "表名称" }
}
}
]
}
生成模式
TypeScript URI处理器
import { Resource, ResourceTemplate } from '@modelcontextprotocol/sdk/types.js';
// URI模板
const URI_TEMPLATES = {
table: 'db://{database}/tables/{table}',
schema: 'db://{database}/schema',
query: 'db://{database}/query/{queryId}',
} as const;
// 解析URI提取参数
export function parseResourceUri(uri: string): {
type: keyof typeof URI_TEMPLATES;
params: Record<string, string>;
} | null {
const patterns = [
{ type: 'table' as const, regex: /^db:\/\/([^/]+)\/tables\/([^/]+)$/ },
{ type: 'schema' as const, regex: /^db:\/\/([^/]+)\/schema$/ },
{ type: 'query' as const, regex: /^db:\/\/([^/]+)\/query\/([^/]+)$/ },
];
for (const { type, regex } of patterns) {
const match = uri.match(regex);
if (match) {
if (type === 'table') {
return { type, params: { database: match[1], table: match[2] } };
} else if (type === 'schema') {
return { type, params: { database: match[1] } };
} else if (type === 'query') {
return { type, params: { database: match[1], queryId: match[2] } };
}
}
}
return null;
}
// 从参数构建URI
export function buildResourceUri(
type: keyof typeof URI_TEMPLATES,
params: Record<string, string>
): string {
let uri = URI_TEMPLATES[type];
for (const [key, value] of Object.entries(params)) {
uri = uri.replace(`{${key}}`, encodeURIComponent(value));
}
return uri;
}
// 列出可用资源模板
export function listResourceTemplates(): ResourceTemplate[] {
return [
{
uriTemplate: URI_TEMPLATES.table,
name: '数据库表',
description: '访问数据库表结构和数据',
mimeType: 'application/json',
},
{
uriTemplate: URI_TEMPLATES.schema,
name: '数据库结构',
description: '完整的数据库结构信息',
mimeType: 'application/json',
},
];
}
URI设计指南
方案选择
file://- 文件系统资源db://- 数据库资源http://,https://- 网络资源git://- Git仓库资源- 特定领域的自定义方案
层次结构模式
db://{database}/tables/{table}
db://{database}/tables/{table}/rows/{rowId}
db://{database}/views/{view}
db://{database}/functions/{function}
file:///{path}
file:///projects/{project}/src/{file}
git://{repo}/branches/{branch}/files/{path}
工作流程
- 分析领域 - 理解资源类型
- 设计方案 - 选择URI方案
- 定义模板 - 创建URI模式
- 生成解析器 - URI解析工具
- 创建构建器 - URI构建助手
- 记录资源 - API文档
目标流程
- mcp-resource-provider
- mcp-server-bootstrap
- mcp-tool-documentation