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:
-
packages/vscode/src/integrations/mcp/mcp-connection.ts:- In the
connectmethod, callawait client.instructions?.()to get the instructions. - Store the instructions in the FSM's context.
- Expose the instructions in the connection's status.
- In the
-
packages/vscode/src/integrations/mcp/mcp-hub.ts:- The
buildStatusmethod inMcpHubshould aggregate the instructions from all active connections.
- The
-
packages/livekit/src/chat/middlewares/tool-call-middleware.ts:- The
defaultTemplatefunction should be updated to accept aninstructionsstring and include it in the system prompt. - The
transformParamsfunction should be updated to pass the aggregated instructions to thedefaultTemplate.
- The
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