Skip to main content
Glama
bradcstevens

Copilot Studio Agent Direct Line MCP Server

by bradcstevens

get_conversation_history

Retrieve message history for a specific conversation to review previous interactions and maintain context.

Instructions

Retrieve message history for a conversation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversationIdYesConversation ID
limitNoMaximum number of messages to return

Implementation Reference

  • The primary handler function for the 'get_conversation_history' tool. Validates input using the schema, checks user permissions, retrieves conversation state from the manager, slices history if limit provided, formats messages, logs audit, and returns structured response.
    private async handleGetConversationHistory(
      args: Record<string, unknown>,
      userContext?: UserContext
    ) {
      const { conversationId, limit } = validateToolArgs(GetConversationHistoryArgsSchema, args);
    
      // Validate permissions if user context exists
      if (userContext) {
        this.validateUserConversationAccess(userContext.userId, conversationId);
      }
    
      try {
        const convState = this.conversationManager.getConversation(conversationId);
        if (!convState) {
          throw new Error(`Conversation ${conversationId} not found or expired`);
        }
    
        let history = convState.messageHistory;
    
        if (limit && limit > 0) {
          history = history.slice(-limit);
        }
    
        const formattedHistory = history.map((activity) => ({
          id: activity.id,
          type: activity.type,
          timestamp: activity.timestamp,
          from: activity.from,
          text: activity.text,
          attachments: activity.attachments,
        }));
    
        // Audit log
        this.logAudit({
          timestamp: Date.now(),
          userId: userContext?.userId,
          action: 'get_conversation_history',
          conversationId,
          details: { messageCount: formattedHistory.length },
        });
    
        return createSuccessResponse({
          conversationId,
          messageCount: formattedHistory.length,
          totalMessages: convState.messageHistory.length,
          messages: formattedHistory,
        });
      } catch (error) {
        throw new Error(
          `Failed to get conversation history: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Zod schema defining input arguments for the tool: required conversationId string and optional positive integer limit. Used for validation in the handler.
    /**
     * Schema for get_conversation_history tool arguments
     */
    export const GetConversationHistoryArgsSchema = z.object({
      conversationId: z.string().min(1, 'Conversation ID is required'),
      limit: z.number().int().positive().optional(),
    });
    
    export type GetConversationHistoryArgs = z.infer<typeof GetConversationHistoryArgsSchema>;
  • Tool registration in the ListToolsRequestSchema handler for stdio transport, providing name, description, and JSON input schema.
    {
      name: 'get_conversation_history',
      description: 'Retrieve message history for a conversation',
      inputSchema: {
        type: 'object',
        properties: {
          conversationId: {
            type: 'string',
            description: 'Conversation ID',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of messages to return',
          },
        },
        required: ['conversationId'],
      },
    },
  • Tool registration in the HTTP 'tools/list' handler, providing name, description, and JSON input schema.
    {
      name: 'get_conversation_history',
      description: 'Retrieve message history for a conversation',
      inputSchema: {
        type: 'object',
        properties: {
          conversationId: {
            type: 'string',
            description: 'Conversation ID',
          },
          limit: {
            type: 'number',
            description: 'Maximum number of messages to return',
          },
        },
        required: ['conversationId'],
      },
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Retrieve' implies a read-only operation, it doesn't specify whether this requires authentication, has rate limits, returns paginated results, or includes metadata like timestamps. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior and constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste: 'Retrieve message history for a conversation'. It is appropriately sized for a simple retrieval tool and front-loads the core purpose without unnecessary elaboration. Every word earns its place by clearly conveying the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (2 parameters, no output schema, no annotations), the description is minimally adequate but has clear gaps. It states what the tool does but lacks behavioral details (e.g., authentication needs, return format) and usage guidelines. Without annotations or an output schema, the description should provide more context to fully inform the agent, but it meets the bare minimum for a basic retrieval operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('conversationId' and 'limit') with basic descriptions. The description adds no additional meaning beyond what the schema provides, such as explaining what a 'conversationId' represents or how 'limit' affects ordering. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but also doesn't detract.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Retrieve message history for a conversation', which includes a specific verb ('Retrieve') and resource ('message history for a conversation'). It distinguishes itself from siblings like 'send_message' or 'start_conversation' by focusing on historical data retrieval rather than interaction or initiation. However, it doesn't explicitly differentiate from hypothetical similar retrieval tools that might exist in other contexts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing a valid conversation ID), exclusions (e.g., not for real-time messages), or compare it to sibling tools like 'end_conversation' or 'send_message'. The agent must infer usage from the tool name and description alone without explicit context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/bradcstevens/copilot-studio-agent-direct-line-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server