Skip to content

feat: add MCP server for AI agent integration#443

Draft
Copilot wants to merge 15 commits intodevelopfrom
copilot/add-mcp-server-functionality
Draft

feat: add MCP server for AI agent integration#443
Copilot wants to merge 15 commits intodevelopfrom
copilot/add-mcp-server-functionality

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

Implements Model Context Protocol (MCP) server to expose YankNote actions to AI agents like Claude Desktop via JSON-RPC over HTTP.

Configuration

  • Config key: mcp.enabled (dot notation for future extensibility: mcp.port, mcp.timeout, etc.)
  • Translation key: mcp-enabled (flat structure to avoid nesting issues)
  • Default: disabled, marked Beta in UI across all locales

Backend

  • Endpoint: /api/mcp/message using @modelcontextprotocol/sdk@1.25.3 with StreamableHTTPServerTransport
  • Accepts parsed request body as third parameter to transport's handleRequest(req, res, parsedBody)
  • Two tools exposed:
    • yn_list_actions: Returns actions where forMcp: true
    • yn_execute_action: Executes action by name with args

Frontend

  • Extended Action type:
    • mcpDescription: AI-friendly parameter docs with inline TypeScript types
    • forMcp: Flag for MCP-specific actions (allows future MCP-only tools)
  • Added executeAction(name, ...args) method that delegates to getActionHandler() internally
  • IPC serialization via JSON.parse(JSON.stringify()) to strip non-serializable properties
  • 9 core actions exposed with descriptive signatures

RPC Architecture

// Backend calls frontend directly without function passing
async function executeAction(actionName: string, args: any[]): Promise<any> {
  return await jsonRPCClient.call.ctx.action.executeAction(actionName, ...args)
}

// Frontend executeAction implementation
export function executeAction(name: string, ...args: any[]): any {
  const handler = getActionHandler(name)
  return handler.apply(null, args)
}

Type Description Format

mcpDescription: 'Find text in repository. Args: [query?:{pattern?:string, caseSensitive?:boolean, wholeWord?:boolean, regExp?:boolean, include?:string, exclude?:string}]. No return.'

Requires Node.js 22+ for MCP SDK compatibility.

Original prompt

需求:给应用增加 MCP 服务器功能

实现参考
0. 在 设置-其他-启动时隐藏主窗口 下方增加一个配置项,用于配置是否开启 MCP 端口,默认不开启

  1. 服务端代码新开一个接口,实现 streamable 方式的 MCP 端口
  2. 服务端调用前端 ctx.action.getRawActions 过滤出 forUser 的 action,作为备选工具调用列表
  3. 给相关的 action 增加一个 string 字段,描述需要的参数类型和注意事项给大模型参考(文字不要太长,避免上下文占用过多)
  4. 为了避免工具膨胀,我们只增加两个 mcp 工具(增加前缀 yn_):获取支持的 action 列表(包括 action 名和描述,描述中增加参数类型参考),执行 action
  5. 执行 action 在服务端调用前端 ctx.action.getActionHandler 实现

其他事项:

  1. 使用 yarn 安装
  2. 编码后执行 yarn run lint 校验代码格式
  3. 需要遵守现有的代码结构
  4. 在云端环境中无法运行 electron,因此写完代码后不要测试直接结束

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link

vercel bot commented Jan 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
yn Ready Ready Preview, Comment Feb 3, 2026 3:24am
yn-api-doc Ready Ready Preview, Comment Feb 3, 2026 3:24am

Copilot AI and others added 2 commits January 26, 2026 04:01
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Copilot AI changed the title [WIP] Add MCP server functionality to the application feat: add MCP server for AI agent integration Jan 26, 2026
Copilot AI requested a review from purocean January 26, 2026 04:11
@purocean
Copy link
Owner

@copilot 实现方式可以进一步简化,前端无需注册,可以直接在electron中调用前端方法,可以参考 app.ts 里面的代码

Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot 实现方式可以进一步简化,前端无需注册,可以直接在electron中调用前端方法,可以参考 app.ts 里面的代码

已简化实现,现在直接使用 jsonRPCClient 调用前端方法,无需前端注册。参考了 app.ts 的模式,在 mcp.ts 中通过 jsonRPCClient.call.ctx.action.getRawActions()jsonRPCClient.call.ctx.action.getActionHandler() 直接调用前端 action 系统。

Changes in commit 8eaa269

@purocean
Copy link
Owner

@copilot 1. mcp部分实现太复杂,没有用到 modelcontextprotocol 的sdk

…forMcp field

Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 26, 2026

@copilot 1. mcp部分实现太复杂,没有用到 modelcontextprotocol 的sdk

已简化 MCP 实现并正确使用 SDK:

  1. 使用 @modelcontextprotocol/sdkServer 类和 StreamableHTTPServerTransport,而不是手动实现 JSON-RPC 协议
  2. 按照 SDK 的标准模式使用 setRequestHandler 处理 ListToolsRequestSchemaCallToolRequestSchema
  3. 添加了 forMcp 字段到 Action 类型,用于后续扩展只暴露给 MCP 的 action
  4. 已为所有带 forUser 的核心 action 添加 forMcp=true 和 MCP 描述

Changes in commit 8106b99

… descriptions

Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Copilot AI changed the title feat: add MCP server for AI agent integration fix: MCP server RPC communication and type serialization Feb 2, 2026
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Copilot AI changed the title fix: MCP server RPC communication and type serialization fix: MCP server RPC communication and serialization Feb 3, 2026
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Co-authored-by: purocean <7115690+purocean@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants