Skip to main content
Glama

executeCommand

Execute specific commands on the SiYuan Note MCP Server to manage notebooks, manipulate documents, and control content within the note system, enabling efficient data operations.

Instructions

执行指定的命令

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsNo命令参数
typeYes命令类型

Implementation Reference

  • The handler function for the 'executeCommand' MCP tool. It delegates execution to the registry's executeCommand method and formats the response as MCP format.
    async ({ type, params = {} }) => { try { const result = await registry.executeCommand(type, params); return { content: [ { type: 'text' as const, text: result.content[0].text } ], _meta: { result: result._meta || {} }, isError: result.isError }; } catch (error) { return { content: [ { type: 'text' as const, text: error instanceof Error ? error.message : '命令执行失败' } ], isError: true }; }
  • Zod input schema for the executeCommand tool: 'type' (required string, command type), 'params' (optional record of any).
    { type: z.string().describe('命令类型'), params: z.record(z.any()).optional().describe('命令参数') },
  • Registration of the 'executeCommand' tool on the MCP server using server.tool(), including name, description, schema, and handler.
    server.tool( 'executeCommand', '执行指定的命令', { type: z.string().describe('命令类型'), params: z.record(z.any()).optional().describe('命令参数') }, async ({ type, params = {} }) => { try { const result = await registry.executeCommand(type, params); return { content: [ { type: 'text' as const, text: result.content[0].text } ], _meta: { result: result._meta || {} }, isError: result.isError }; } catch (error) { return { content: [ { type: 'text' as const, text: error instanceof Error ? error.message : '命令执行失败' } ], isError: true }; } } );
  • Core dispatch logic in CommandRegistry.executeCommand: resolves command name, parses/validates params, invokes handler, handles errors - called by the tool handler.
    public async executeCommand(commandName: string, params: unknown = {}): Promise<McpResponse> { // 尝试直接查找完整命令名 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 }; } try { const validatedParams = command.params.parse(params); return await command.handler(validatedParams); } catch (error) { if (error instanceof z.ZodError) { const issues = error.issues.map(issue => ` - ${issue.path.join('.')}: ${issue.message}` ).join('\n'); return { content: [ { type: 'text', text: `参数验证失败:\n${issues}` } ], isError: true }; } return { content: [ { type: 'text', text: `命令执行失败:${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • src/server.ts:52-52 (registration)
    Invocation of registerCommandTool which registers the executeCommand tool on the server instance.
    registerCommandTool(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