feat: resources?

This commit is contained in:
2026-03-18 13:25:01 +08:00
parent 8213092bb6
commit 301f499494
3 changed files with 183 additions and 0 deletions
+36
View File
@@ -19,6 +19,11 @@ import {
getSetupDeckDisplayPrompt,
type SetupDeckDisplayOptions
} from '../prompts/setup-deck-display.js';
import {
listResources,
readResource,
type DocResource
} from '../resources/docs.js';
/**
* MCP 服务器命令
@@ -71,6 +76,8 @@ async function mcpServeAction(host: string, options: MCPOptions) {
ListToolsRequestSchema,
ListPromptsRequestSchema,
GetPromptRequestSchema,
ListResourcesRequestSchema,
ReadResourceRequestSchema,
} = await import('@modelcontextprotocol/sdk/types.js');
const server = new Server(
@@ -82,6 +89,7 @@ async function mcpServeAction(host: string, options: MCPOptions) {
capabilities: {
tools: {},
prompts: {},
resources: {},
},
}
);
@@ -411,6 +419,34 @@ async function mcpServeAction(host: string, options: MCPOptions) {
}
});
// 处理 Resources 列表请求
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: listResources().map(r => ({
uri: r.uri,
name: r.name,
title: r.title,
description: r.description,
mimeType: r.mimeType,
})),
};
});
// 处理 Resources 读取请求
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
const { uri } = request.params;
const resource = readResource(uri, process.cwd());
if (!resource) {
throw new Error(`Resource not found: ${uri}`);
}
return {
contents: [resource],
};
});
// 启动服务器
if (host === 'stdio') {
const transport = new StdioServerTransport();