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:
ExceptionException 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 aWARNINGlog entry so that tools never raiseTypeErrorfor unexpected keys.- Parameters:
- Returns:
Tool execution result (JSON string)
- Return type:
- 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
enumconstraints 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:
- Returns:
List of tool definitions in OpenAI format
- Return type: