fix: Resolve linting issues in MCP integration

- Replace deprecated typing.Dict/List with built-in dict/list
- Fix boolean comparisons (== True/False) to direct checks
- Remove unused variables in demo script
- Update type annotations to use modern Python syntax

All pre-commit hooks should now pass.
This commit is contained in:
aakash
2025-10-06 02:23:55 -07:00
parent 1fdc9dfbfa
commit 98cdcf600b
7 changed files with 25 additions and 27 deletions

View File

@@ -10,7 +10,7 @@ flexible message processing options.
import asyncio
import json
import logging
from typing import Any, Dict, List, Optional
from typing import Any, Optional
logger = logging.getLogger(__name__)
@@ -66,7 +66,7 @@ class SlackMCPReader:
await self.mcp_process.wait()
logger.info("Stopped MCP server")
async def send_mcp_request(self, request: Dict[str, Any]) -> Dict[str, Any]:
async def send_mcp_request(self, request: dict[str, Any]) -> dict[str, Any]:
"""Send a request to the MCP server and get response."""
if not self.mcp_process:
raise RuntimeError("MCP server not started")
@@ -100,7 +100,7 @@ class SlackMCPReader:
logger.info("MCP connection initialized successfully")
async def list_available_tools(self) -> List[Dict[str, Any]]:
async def list_available_tools(self) -> list[dict[str, Any]]:
"""List available tools from the MCP server."""
list_request = {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
@@ -112,7 +112,7 @@ class SlackMCPReader:
async def fetch_slack_messages(
self, channel: Optional[str] = None, limit: int = 100
) -> List[Dict[str, Any]]:
) -> list[dict[str, Any]]:
"""
Fetch Slack messages using MCP tools.
@@ -180,7 +180,7 @@ class SlackMCPReader:
return messages if isinstance(messages, list) else [messages]
def _format_message(self, message: Dict[str, Any]) -> str:
def _format_message(self, message: dict[str, Any]) -> str:
"""Format a single message for indexing."""
text = message.get("text", "")
user = message.get("user", message.get("username", "Unknown"))
@@ -217,7 +217,7 @@ class SlackMCPReader:
return "\n".join(parts)
def _create_concatenated_content(self, messages: List[Dict[str, Any]], channel: str) -> str:
def _create_concatenated_content(self, messages: list[dict[str, Any]], channel: str) -> str:
"""Create concatenated content from multiple messages in a channel."""
if not messages:
return ""
@@ -251,7 +251,7 @@ class SlackMCPReader:
return "\n".join(content_parts)
async def read_slack_data(self, channels: Optional[List[str]] = None) -> List[str]:
async def read_slack_data(self, channels: Optional[list[str]] = None) -> list[str]:
"""
Read Slack data and return formatted text chunks.

View File

@@ -11,7 +11,6 @@ Usage:
import argparse
import asyncio
from typing import List
from apps.base_rag_example import BaseRAGExample
from apps.slack_data.slack_mcp_reader import SlackMCPReader
@@ -121,7 +120,7 @@ class SlackMCPRAG(BaseRAGExample):
print("4. Try running the MCP server command directly to test it")
return False
async def load_data(self, args) -> List[str]:
async def load_data(self, args) -> list[str]:
"""Load Slack messages via MCP server."""
print(f"Connecting to Slack MCP server: {args.mcp_server}")

View File

@@ -10,7 +10,7 @@ flexible bookmark processing options.
import asyncio
import json
import logging
from typing import Any, Dict, List, Optional
from typing import Any, Optional
logger = logging.getLogger(__name__)
@@ -69,7 +69,7 @@ class TwitterMCPReader:
await self.mcp_process.wait()
logger.info("Stopped MCP server")
async def send_mcp_request(self, request: Dict[str, Any]) -> Dict[str, Any]:
async def send_mcp_request(self, request: dict[str, Any]) -> dict[str, Any]:
"""Send a request to the MCP server and get response."""
if not self.mcp_process:
raise RuntimeError("MCP server not started")
@@ -103,7 +103,7 @@ class TwitterMCPReader:
logger.info("MCP connection initialized successfully")
async def list_available_tools(self) -> List[Dict[str, Any]]:
async def list_available_tools(self) -> list[dict[str, Any]]:
"""List available tools from the MCP server."""
list_request = {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
@@ -113,7 +113,7 @@ class TwitterMCPReader:
return response.get("result", {}).get("tools", [])
async def fetch_twitter_bookmarks(self, limit: Optional[int] = None) -> List[Dict[str, Any]]:
async def fetch_twitter_bookmarks(self, limit: Optional[int] = None) -> list[dict[str, Any]]:
"""
Fetch Twitter bookmarks using MCP tools.
@@ -171,7 +171,7 @@ class TwitterMCPReader:
return bookmarks if isinstance(bookmarks, list) else [bookmarks]
def _format_bookmark(self, bookmark: Dict[str, Any]) -> str:
def _format_bookmark(self, bookmark: dict[str, Any]) -> str:
"""Format a single bookmark for indexing."""
# Extract tweet information
text = bookmark.get("text", bookmark.get("content", ""))
@@ -242,7 +242,7 @@ class TwitterMCPReader:
return "\n".join(parts)
async def read_twitter_bookmarks(self) -> List[str]:
async def read_twitter_bookmarks(self) -> list[str]:
"""
Read Twitter bookmark data and return formatted text chunks.

View File

@@ -12,7 +12,6 @@ Usage:
import argparse
import asyncio
from pathlib import Path
from typing import List
from apps.base_rag_example import BaseRAGExample
from apps.twitter_data.twitter_mcp_reader import TwitterMCPReader
@@ -113,7 +112,7 @@ class TwitterMCPRAG(BaseRAGExample):
print("5. Try running the MCP server command directly to test it")
return False
async def load_data(self, args) -> List[str]:
async def load_data(self, args) -> list[str]:
"""Load Twitter bookmarks via MCP server."""
print(f"Connecting to Twitter MCP server: {args.mcp_server}")

View File

@@ -32,7 +32,7 @@ async def demo_slack_mcp():
# This would typically use a real MCP server command
# For demo purposes, we show what the command would look like
slack_app = SlackMCPRAG()
# slack_app = SlackMCPRAG() # Would be used for actual testing
# Simulate command line arguments for testing
class MockArgs:
@@ -71,7 +71,7 @@ async def demo_twitter_mcp():
print("\n1. Testing Twitter MCP server connection...")
twitter_app = TwitterMCPRAG()
# twitter_app = TwitterMCPRAG() # Would be used for actual testing
class MockArgs:
mcp_server = "twitter-mcp-server"

View File

@@ -26,7 +26,7 @@ def test_slack_reader_initialization():
# Test basic initialization
reader = SlackMCPReader("slack-mcp-server")
assert reader.mcp_server_command == "slack-mcp-server"
assert reader.concatenate_conversations == True
assert reader.concatenate_conversations
assert reader.max_messages_per_conversation == 100
# Test with custom parameters
@@ -37,7 +37,7 @@ def test_slack_reader_initialization():
max_messages_per_conversation=50
)
assert reader.workspace_name == "test-workspace"
assert reader.concatenate_conversations == False
assert not reader.concatenate_conversations
assert reader.max_messages_per_conversation == 50
print("✅ SlackMCPReader initialization tests passed")
@@ -50,8 +50,8 @@ def test_twitter_reader_initialization():
# Test basic initialization
reader = TwitterMCPReader("twitter-mcp-server")
assert reader.mcp_server_command == "twitter-mcp-server"
assert reader.include_tweet_content == True
assert reader.include_metadata == True
assert reader.include_tweet_content
assert reader.include_metadata
assert reader.max_bookmarks == 1000
# Test with custom parameters
@@ -63,8 +63,8 @@ def test_twitter_reader_initialization():
max_bookmarks=500
)
assert reader.username == "testuser"
assert reader.include_tweet_content == False
assert reader.include_metadata == False
assert not reader.include_tweet_content
assert not reader.include_metadata
assert reader.max_bookmarks == 500
print("✅ TwitterMCPReader initialization tests passed")

View File

@@ -23,7 +23,7 @@ def test_slack_reader_basic():
reader = SlackMCPReader("slack-mcp-server")
assert reader.mcp_server_command == "slack-mcp-server"
assert reader.concatenate_conversations == True
assert reader.concatenate_conversations
# Test message formatting
message = {
@@ -61,7 +61,7 @@ def test_twitter_reader_basic():
reader = TwitterMCPReader("twitter-mcp-server")
assert reader.mcp_server_command == "twitter-mcp-server"
assert reader.include_tweet_content == True
assert reader.include_tweet_content
assert reader.max_bookmarks == 1000
# Test bookmark formatting