Skip to main content
Glama

help

Retrieve detailed assistance for specific commands within the SiYuan Note MCP Server, enabling efficient management of notebook operations and document interactions.

Instructions

获取命令的帮助信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYes命令类型

Implementation Reference

  • The core handler logic for the 'help' tool. Takes a command 'type', fetches help from registry, formats detailed text response including params, returns, examples.
    async ({ type }) => { try { const result = registry.getCommandHelp(type); if (result.isError) { return { content: [ { type: 'text' as const, text: result.content[0].text } ], isError: true }; } const doc = result._meta; if (!doc) { return { content: [ { type: 'text' as const, text: `命令 ${type} 没有帮助信息` } ], isError: true }; } // 构建帮助文本 const helpText = [ `命令: ${type}`, `描述: ${doc.description}`, '', '参数:', ...Object.entries(doc.params).map(([key, value]) => ` ${key}: ${value.type}${value.required ? ' (必需)' : ' (可选)'}\n ${value.description}` ), '', '返回值:', ` 类型: ${doc.returns.type}`, ` 描述: ${doc.returns.description}`, ' 属性:', ...Object.entries(doc.returns.properties).map(([key, desc]) => ` ${key}: ${String(desc)}` ), '', '示例:', ...doc.examples.map(example => [ ` ${example.description}:`, ' 参数:', ` ${JSON.stringify(example.params, null, 2).replace(/\n/g, '\n ')}`, ' 响应:', ` ${JSON.stringify(example.response, null, 2).replace(/\n/g, '\n ')}` ]).flat(), '', doc.apiLink ? `API文档: ${doc.apiLink}` : '' ].filter(Boolean).join('\n'); return { content: [ { type: 'text' as const, text: helpText } ], _meta: { documentation: doc }, isError: false }; } catch (error) { return { content: [ { type: 'text' as const, text: error instanceof Error ? error.message : '获取帮助失败' } ], isError: true }; } }
  • Input schema: 'type' as string (command type).
    { type: z.string().describe('命令类型') },
  • src/server.ts:54-54 (registration)
    Registers the 'help' tool by calling registerHelpTool on the MCP server instance.
    registerHelpTool(server);
  • src/tools/help.ts:6-96 (registration)
    Function that registers the 'help' tool on the server with name, description, schema, and handler.
    export function registerHelpTool(server: McpServer) { server.tool( 'help', '获取命令的帮助信息', { type: z.string().describe('命令类型') }, async ({ type }) => { try { const result = registry.getCommandHelp(type); if (result.isError) { return { content: [ { type: 'text' as const, text: result.content[0].text } ], isError: true }; } const doc = result._meta; if (!doc) { return { content: [ { type: 'text' as const, text: `命令 ${type} 没有帮助信息` } ], isError: true }; } // 构建帮助文本 const helpText = [ `命令: ${type}`, `描述: ${doc.description}`, '', '参数:', ...Object.entries(doc.params).map(([key, value]) => ` ${key}: ${value.type}${value.required ? ' (必需)' : ' (可选)'}\n ${value.description}` ), '', '返回值:', ` 类型: ${doc.returns.type}`, ` 描述: ${doc.returns.description}`, ' 属性:', ...Object.entries(doc.returns.properties).map(([key, desc]) => ` ${key}: ${String(desc)}` ), '', '示例:', ...doc.examples.map(example => [ ` ${example.description}:`, ' 参数:', ` ${JSON.stringify(example.params, null, 2).replace(/\n/g, '\n ')}`, ' 响应:', ` ${JSON.stringify(example.response, null, 2).replace(/\n/g, '\n ')}` ]).flat(), '', doc.apiLink ? `API文档: ${doc.apiLink}` : '' ].filter(Boolean).join('\n'); return { content: [ { type: 'text' as const, text: helpText } ], _meta: { documentation: doc }, isError: false }; } catch (error) { return { content: [ { type: 'text' as const, text: error instanceof Error ? error.message : '获取帮助失败' } ], isError: true }; } } ); }
  • Registry method that retrieves and formats detailed documentation for a specific command, used by the 'help' tool.
    public getCommandHelp(commandName: string): McpResponse<CommandHandler['documentation']> { // 尝试直接查找完整命令名 let command = this.commands.get(commandName); if (!command) { // 如果找不到,尝试解析命名空间 const [namespace, name] = this.parseFullCommandName(commandName); const fullName = this.getFullCommandName(namespace, name); command = this.commands.get(fullName); } if (!command) { return { content: [ { type: 'text', text: `命令 ${commandName} 不存在` } ], isError: true }; } // 获取参数说明 const params: Record<string, { type: string; description: string; required: boolean; }> = {}; try { if (command.params instanceof z.ZodObject) { const shape = command.params._def.shape(); Object.entries(shape).forEach(([key, value]) => { if (value instanceof z.ZodType) { const isOptional = value instanceof z.ZodOptional; params[key] = { type: value._def.typeName || 'unknown', description: value.description || '无说明', required: !isOptional }; } }); } } catch { // 如果无法获取 shape,返回空对象 } const help = command.documentation || { description: command.description, params, returns: { type: 'object', description: '命令执行结果', properties: {} }, examples: [] }; // 格式化帮助信息 const fullName = this.getFullCommandName(command.namespace, command.name); const paramsList = Object.entries(params).map(([name, info]) => ` ${name}: ${info.type}${info.required ? ' (必填)' : ' (可选)'}\n ${info.description}` ).join('\n'); const returnInfo = help.returns; const propertiesList = Object.entries(returnInfo.properties).map(([name, desc]) => ` ${name}: ${desc}` ).join('\n'); const examplesList = help.examples.map(example => `示例:${example.description}\n` + ` 参数:${JSON.stringify(example.params, null, 2)}\n` + ` 响应:${JSON.stringify(example.response, null, 2)}` ).join('\n\n'); const helpText = [ `命令: ${fullName}`, `描述: ${help.description}`, '', '参数:', paramsList || ' 无参数', '', '返回值:', ` 类型: ${returnInfo.type}`, ` 描述: ${returnInfo.description}`, ' 属性:', propertiesList || ' 无属性', '', examplesList ? '示例:\n' + examplesList : '示例: 无示例', '', help.apiLink ? `API文档: ${help.apiLink}` : '' ].filter(Boolean).join('\n'); return { content: [ { type: 'text', text: helpText } ], _meta: help }; }
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/onigeya/siyuan-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server