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)`
      );
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers limited behavioral insight. It mentions 'clean up resources', hinting at resource management, but lacks details on effects (e.g., irreversible deletion, impact on history), permissions required, or error conditions. This is inadequate for a mutation tool with zero annotation coverage.

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. It front-loads the core action ('End an existing conversation') and adds a secondary function ('clean up resources') concisely. Every word earns its place, making it highly structured and easy to parse.

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

Completeness2/5

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

Given the tool's complexity as a mutation operation with no annotations and no output schema, the description is incomplete. It lacks crucial details like behavioral outcomes (e.g., what 'clean up' entails), error handling, or return values. For a tool that likely alters state, this leaves significant gaps in understanding.

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?

The schema description coverage is 100%, with the single parameter 'conversationId' fully documented in the schema. The description adds no additional meaning beyond the schema, such as format examples or constraints. Baseline 3 is appropriate as the schema handles parameter documentation effectively.

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 action ('End') and resource ('an existing conversation') with an additional function ('clean up resources'). It distinguishes from siblings like 'get_conversation_history' (read) and 'send_message' (send), though not explicitly named. The purpose is specific but could better differentiate from 'start_conversation' (create vs. terminate).

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 explicit guidance on when to use this tool versus alternatives is provided. It implies usage for terminating conversations but doesn't specify prerequisites (e.g., conversation must exist), exclusions (e.g., not for active chats), or direct comparisons to siblings like 'start_conversation'. The context is minimal, leaving usage ambiguous.

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