feat: mcp prompts
This commit is contained in:
@@ -4,6 +4,21 @@ import { readFrontmatter, type ReadFrontmatterParams, type DeckFrontmatter } fro
|
||||
import { writeFrontmatter, type WriteFrontmatterParams } from '../tools/frontmatter/write-frontmatter.js';
|
||||
import { cardCrud, type CardCrudParams, type CardData } from '../tools/card/card-crud.js';
|
||||
import { ensureDeckPreview, type EnsureDeckPreviewParams } from '../tools/ensure-deck-preview.js';
|
||||
import {
|
||||
designCardGame,
|
||||
getDesignCardGamePrompt,
|
||||
type DesignCardGameOptions
|
||||
} from '../prompts/design-card-game.js';
|
||||
import {
|
||||
populateDeck,
|
||||
getPopulateDeckPrompt,
|
||||
type PopulateDeckOptions
|
||||
} from '../prompts/populate-deck.js';
|
||||
import {
|
||||
setupDeckDisplay,
|
||||
getSetupDeckDisplayPrompt,
|
||||
type SetupDeckDisplayOptions
|
||||
} from '../prompts/setup-deck-display.js';
|
||||
|
||||
/**
|
||||
* MCP 服务器命令
|
||||
@@ -54,6 +69,8 @@ async function mcpServeAction(host: string, options: MCPOptions) {
|
||||
const {
|
||||
CallToolRequestSchema,
|
||||
ListToolsRequestSchema,
|
||||
ListPromptsRequestSchema,
|
||||
GetPromptRequestSchema,
|
||||
} = await import('@modelcontextprotocol/sdk/types.js');
|
||||
|
||||
const server = new Server(
|
||||
@@ -64,6 +81,7 @@ async function mcpServeAction(host: string, options: MCPOptions) {
|
||||
{
|
||||
capabilities: {
|
||||
tools: {},
|
||||
prompts: {},
|
||||
},
|
||||
}
|
||||
);
|
||||
@@ -304,6 +322,17 @@ async function mcpServeAction(host: string, options: MCPOptions) {
|
||||
};
|
||||
});
|
||||
|
||||
// 处理 Prompts 列表请求
|
||||
server.setRequestHandler(ListPromptsRequestSchema, async () => {
|
||||
return {
|
||||
prompts: [
|
||||
getDesignCardGamePrompt(),
|
||||
getPopulateDeckPrompt(),
|
||||
getSetupDeckDisplayPrompt(),
|
||||
],
|
||||
};
|
||||
});
|
||||
|
||||
// 处理工具调用请求
|
||||
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
const { name, arguments: args } = request.params;
|
||||
@@ -446,6 +475,47 @@ async function mcpServeAction(host: string, options: MCPOptions) {
|
||||
}
|
||||
});
|
||||
|
||||
// 处理 Prompts 获取请求
|
||||
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
|
||||
const { name, arguments: args } = request.params;
|
||||
|
||||
try {
|
||||
switch (name) {
|
||||
case 'design-card-game': {
|
||||
const options = args as unknown as DesignCardGameOptions;
|
||||
const result = designCardGame(options);
|
||||
return {
|
||||
description: '引导用户设计新的卡牌游戏系统,定义卡牌模板和字段结构',
|
||||
messages: result.messages,
|
||||
};
|
||||
}
|
||||
|
||||
case 'populate-deck': {
|
||||
const options = args as unknown as PopulateDeckOptions;
|
||||
const result = populateDeck(options);
|
||||
return {
|
||||
description: '为已有的卡牌组生成和填充卡牌内容',
|
||||
messages: result.messages,
|
||||
};
|
||||
}
|
||||
|
||||
case 'setup-deck-display': {
|
||||
const options = args as unknown as SetupDeckDisplayOptions;
|
||||
const result = setupDeckDisplay(options);
|
||||
return {
|
||||
description: '引导用户配置卡牌的显示参数(尺寸、布局、样式等)',
|
||||
messages: result.messages,
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`未知 prompt:${name}`);
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
// 启动服务器
|
||||
if (host === 'stdio') {
|
||||
const transport = new StdioServerTransport();
|
||||
|
||||
Reference in New Issue
Block a user