zulip_get_channel_history
Retrieve recent messages from a Zulip channel and topic to access conversation history for review or analysis.
Instructions
Get recent messages from a channel (stream) and topic
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_name | Yes | The name of the stream | |
| topic | Yes | The topic name | |
| limit | No | Number of messages to retrieve (default 20) | |
| anchor | No | Message ID to start from (default 'newest') | newest |
Implementation Reference
- index.ts:469-485 (handler)MCP CallTool request handler case for 'zulip_get_channel_history'. Validates arguments and calls the ZulipClient.getMessages method to fetch channel history.case "zulip_get_channel_history": { const args = request.params.arguments as unknown as GetChannelHistoryArgs; if (!args.channel_name || !args.topic) { throw new Error( "Missing required arguments: channel_name and topic" ); } const response = await zulipClient.getMessages( args.channel_name, args.topic, args.limit, args.anchor ); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }
- index.ts:156-183 (schema)Defines the Tool metadata, name, description, and input schema for 'zulip_get_channel_history'.const getChannelHistoryTool: Tool = { name: "zulip_get_channel_history", description: "Get recent messages from a channel (stream) and topic", inputSchema: { type: "object", properties: { channel_name: { type: "string", description: "The name of the stream", }, topic: { type: "string", description: "The topic name", }, limit: { type: "number", description: "Number of messages to retrieve (default 20)", default: 20, }, anchor: { type: "string", description: "Message ID to start from (default 'newest')", default: "newest", }, }, required: ["channel_name", "topic"], }, };
- index.ts:306-334 (helper)ZulipClient method implementing the core logic to retrieve messages from a specific stream and topic using narrow parameters.async getMessages(streamName: string, topic: string, limit = 20, anchor = "newest") { try { // First, need to find the stream ID const streamsResponse = await this.getStreams(true, true, true); const stream = streamsResponse.streams.find((s: any) => s.name === streamName); if (!stream) { throw new Error(`Stream "${streamName}" not found`); } // Construct narrow to filter by stream and topic const narrow = [ { operator: "stream", operand: streamName }, { operator: "topic", operand: topic }, ]; const params = { narrow: JSON.stringify(narrow), num_before: Math.floor(limit / 2), num_after: Math.floor(limit / 2), anchor: anchor, }; return await this.client.messages.retrieve(params); } catch (error) { console.error("Error getting messages:", error); throw error; } }
- index.ts:539-547 (registration)Registers 'zulip_get_channel_history' (via getChannelHistoryTool) in the ListTools response.listChannelsTool, postMessageTool, sendDirectMessageTool, addReactionTool, getChannelHistoryTool, getTopicsTool, subscribeToChannelTool, getUsersTool, ],
- index.ts:51-56 (schema)TypeScript interface defining the argument types for the tool handler.interface GetChannelHistoryArgs { channel_name: string; topic: string; limit?: number; anchor?: string; }