MCP Tools Module

The MCP tools module provides integration between MCP clustering tools and the RAG chat system. It converts MCP tool definitions to OpenAI function calling format and handles tool execution.

Overview

This module enables the LLM to automatically decide when to use clustering analysis tools to answer questions about conference topics, trends, and developments during RAG chat sessions.

Quick Start

from abstracts_explorer.mcp_tools import (
    get_mcp_tools_schema,
    execute_mcp_tool,
    format_tool_result_for_llm,
)

# Get tool schemas for OpenAI function calling
schemas = get_mcp_tools_schema()

# Execute a tool
result = execute_mcp_tool(
    "get_conference_topics",
    {"n_clusters": 8}
)

# Format the result for LLM consumption
formatted = format_tool_result_for_llm("get_conference_topics", result)

API Reference

MCP Tools Integration for RAG Chat

This module provides integration between MCP clustering tools and the RAG chat system. It converts MCP tool definitions to OpenAI function calling format and handles tool execution.

The integration allows the LLM to automatically decide when to use clustering tools to answer questions about conference topics, trends, and developments.

exception abstracts_explorer.mcp_tools.MCPToolsError[source]

Bases: Exception

Exception raised for MCP tools-related errors.

abstracts_explorer.mcp_tools.execute_mcp_tool(tool_name, arguments)[source]

Execute an MCP tool with the given arguments.

Arguments are normalized before dispatch to handle common LLM output quirks (e.g. "year" instead of "years", list values for scalar string fields). After normalization, any keyword arguments that are not accepted by the target function are silently dropped with a WARNING log entry so that tools never raise TypeError for unexpected keys.

Parameters:
  • tool_name (str) – Name of the tool to execute

  • arguments (dict) – Arguments to pass to the tool

Returns:

Tool execution result (JSON string)

Return type:

str

Raises:

MCPToolsError – If tool execution fails or tool is unknown

abstracts_explorer.mcp_tools.get_mcp_tools_schema(conferences=None, years=None)[source]

Get the MCP tools schema for OpenAI function calling.

When conferences or years are provided (typically queried from the database), they are injected as enum constraints into every tool property that accepts conference or year values. This lets the LLM pick from the exact values stored in the database instead of guessing.

Parameters:
  • conferences (list of str, optional) – Available conference names (e.g. ["NeurIPS", "ICLR"]). Injected as enum into conference-related properties.

  • years (list of int, optional) – Available years (e.g. [2024, 2025]). Injected as enum into year-related properties.

Returns:

List of tool definitions in OpenAI format

Return type:

list

abstracts_explorer.mcp_tools.format_tool_result_for_llm(tool_name, result)[source]

Format tool execution result for LLM consumption.

This function extracts the most relevant information from tool results and formats it in a way that’s easy for the LLM to process.

Parameters:
  • tool_name (str) – Name of the tool that was executed

  • result (str) – Raw tool result (JSON string)

Returns:

Formatted result suitable for LLM processing

Return type:

str