Skip to main content
Glama
bradcstevens

Copilot Studio Agent Direct Line MCP Server

by bradcstevens

end_conversation

Terminate a conversation and release associated resources by providing the conversation ID.

Instructions

End an existing conversation and clean up resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
conversationIdYesConversation ID to terminate

Implementation Reference

  • Main handler for end_conversation tool: validates input, authorizes user, retrieves conversation state, delegates to conversationManager.endConversation, cleans user mapping, audits, and returns success response.
     * Handle end_conversation tool with user context
     */
    private async handleEndConversation(args: Record<string, unknown>, userContext?: UserContext) {
      const { conversationId } = validateToolArgs(EndConversationArgsSchema, 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 already ended`);
        }
    
        // End the conversation
        this.conversationManager.endConversation(conversationId);
    
        // Remove from user mapping
        if (userContext) {
          this.removeUserConversation(userContext.userId, conversationId);
        }
    
        // Audit log
        this.logAudit({
          timestamp: Date.now(),
          userId: userContext?.userId,
          action: 'end_conversation',
          conversationId,
          details: { messageCount: convState.messageHistory.length },
        });
    
        return createSuccessResponse({
          conversationId,
          status: 'ended',
          messageCount: convState.messageHistory.length,
        });
      } catch (error) {
        throw new Error(
          `Failed to end conversation: ${error instanceof Error ? error.message : String(error)}`
        );
      }
  • Zod schema for validating end_conversation tool arguments, requiring a conversationId string.
     * Schema for end_conversation tool arguments
     */
    export const EndConversationArgsSchema = z.object({
      conversationId: z.string().min(1, 'Conversation ID is required'),
    });
    
    export type EndConversationArgs = z.infer<typeof EndConversationArgsSchema>;
  • Tool registration in listTools handler: defines name, description, and inputSchema for end_conversation.
    {
      name: 'end_conversation',
      description: 'End an existing conversation and clean up resources',
      inputSchema: {
        type: 'object',
        properties: {
          conversationId: {
            type: 'string',
            description: 'Conversation ID to terminate',
          },
        },
        required: ['conversationId'],
      },
    },
  • Helper method implementing conversation cleanup: updates metrics, clears timers, removes state from map, and logs.
    endConversation(conversationId: string): void {
      const state = this.conversations.get(conversationId);
      if (!state) return;
    
      const lifetime = Date.now() - state.createdAt;
    
      // Update metrics
      this.metrics.cleanedUp++;
      this.metrics.activeCount = this.conversations.size - 1;
      this.metrics.averageLifetime =
        (this.metrics.averageLifetime * (this.metrics.cleanedUp - 1) + lifetime) /
        this.metrics.cleanedUp;
    
      // Clear timeout
      const timer = this.timeoutTimers.get(conversationId);
      if (timer) {
        clearTimeout(timer);
        this.timeoutTimers.delete(conversationId);
      }
    
      // Remove conversation
      this.conversations.delete(conversationId);
    
      console.error(
        `[ConversationManager] Ended conversation ${conversationId} (lifetime: ${(lifetime / 1000).toFixed(0)}s)`
      );
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.1/5.0
Behavior2/5

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

With no annotations, the description carries the full burden. 'End an existing conversation' implies mutation, and 'clean up resources' hints at side effects, but it does not disclose irreversibility, impact on history, or any other behavioral nuances. The description is vague about what cleanup entails.

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 concise sentence, front-loaded with the action verb 'End'. Every word earns its place, including the useful addition of 'clean up resources' which hints at side effects without unnecessary elaboration.

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?

The tool is simple with one parameter, 100% schema coverage, and no output schema. The description is minimally viable, but it lacks usage guidance and behavioral details about consequences, making it less complete than ideal for a terminating action.

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%: the parameter 'conversationId' is described as 'Conversation ID to terminate'. The description adds no additional semantic meaning beyond the schema, so baseline 3 applies.

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 uses the specific verb 'End' with the resource 'conversation', clearly indicating the action. It distinguishes from siblings like 'send_message' and 'start_conversation' by being the terminating action, though it does not explicitly contrast with them.

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?

No guidance is provided on when to use this tool versus alternatives. It does not mention conditions for ending a conversation or exclusions, relying on the agent to infer usage from the verb 'End' and sibling context.

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