TabbyML / pochi

Home Page:https://docs.getpochi.com

Repository from Github https://github.comTabbyML/pochiRepository from Github https://github.comTabbyML/pochi

feat(mcp): Add support for MCP provided instructions

icycodes opened this issue · comments

Please describe the feature you want

Currently, Pochi's MCP (Model Context Protocol) allows servers to provide a set of tools with descriptions. This is a great feature, but it would be even more powerful if MCP servers could also provide instructions for the model on how to use these tools. This would allow for more complex and nuanced interactions with the tools, and would make it easier to create sophisticated MCP servers.

The MCP TypeScript SDK already supports this via an optional instructions method on the client. See here: https://github.com/modelcontextprotocol/typescript-sdk/blob/main/src/client/index.ts#L202

Additional context

The implementation of this feature would require changes to the following files:

  1. packages/vscode/src/integrations/mcp/mcp-connection.ts:

    • In the connect method, call await client.instructions?.() to get the instructions.
    • Store the instructions in the FSM's context.
    • Expose the instructions in the connection's status.
  2. packages/vscode/src/integrations/mcp/mcp-hub.ts:

    • The buildStatus method in McpHub should aggregate the instructions from all active connections.
  3. packages/livekit/src/chat/middlewares/tool-call-middleware.ts:

    • The defaultTemplate function should be updated to accept an instructions string and include it in the system prompt.
    • The transformParams function should be updated to pass the aggregated instructions to the defaultTemplate.

Here is an example of how the defaultTemplate could be modified:

const defaultTemplate = (tools: string, instructions?: string) =>
  `====\n\nAPI INVOCATIONS\n\nYou are provided with api signatures within <api-list></api-list> XML tags in JSON schema format.\nYou are allowed to call one or more api at a time.\nDo not make assumptions about what values to plug into apis; you must follow the api signature strictly to call apis.\nHere are the available apis:\n<api-list>\n${tools}\n</api-list>\n${instructions ? `\n${instructions}` : ''}\n\n## OUTPUT FORMAT\n...`

This would allow MCP servers to provide detailed instructions on how to use the tools, which would be very helpful for the model.

🤖 Generated with Pochi