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:
@@ -10,7 +10,7 @@ flexible message processing options.
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class SlackMCPReader:
|
|||||||
await self.mcp_process.wait()
|
await self.mcp_process.wait()
|
||||||
logger.info("Stopped MCP server")
|
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."""
|
"""Send a request to the MCP server and get response."""
|
||||||
if not self.mcp_process:
|
if not self.mcp_process:
|
||||||
raise RuntimeError("MCP server not started")
|
raise RuntimeError("MCP server not started")
|
||||||
@@ -100,7 +100,7 @@ class SlackMCPReader:
|
|||||||
|
|
||||||
logger.info("MCP connection initialized successfully")
|
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 available tools from the MCP server."""
|
||||||
list_request = {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
|
list_request = {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ class SlackMCPReader:
|
|||||||
|
|
||||||
async def fetch_slack_messages(
|
async def fetch_slack_messages(
|
||||||
self, channel: Optional[str] = None, limit: int = 100
|
self, channel: Optional[str] = None, limit: int = 100
|
||||||
) -> List[Dict[str, Any]]:
|
) -> list[dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Fetch Slack messages using MCP tools.
|
Fetch Slack messages using MCP tools.
|
||||||
|
|
||||||
@@ -180,7 +180,7 @@ class SlackMCPReader:
|
|||||||
|
|
||||||
return messages if isinstance(messages, list) else [messages]
|
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."""
|
"""Format a single message for indexing."""
|
||||||
text = message.get("text", "")
|
text = message.get("text", "")
|
||||||
user = message.get("user", message.get("username", "Unknown"))
|
user = message.get("user", message.get("username", "Unknown"))
|
||||||
@@ -217,7 +217,7 @@ class SlackMCPReader:
|
|||||||
|
|
||||||
return "\n".join(parts)
|
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."""
|
"""Create concatenated content from multiple messages in a channel."""
|
||||||
if not messages:
|
if not messages:
|
||||||
return ""
|
return ""
|
||||||
@@ -251,7 +251,7 @@ class SlackMCPReader:
|
|||||||
|
|
||||||
return "\n".join(content_parts)
|
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.
|
Read Slack data and return formatted text chunks.
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ Usage:
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from apps.base_rag_example import BaseRAGExample
|
from apps.base_rag_example import BaseRAGExample
|
||||||
from apps.slack_data.slack_mcp_reader import SlackMCPReader
|
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")
|
print("4. Try running the MCP server command directly to test it")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def load_data(self, args) -> List[str]:
|
async def load_data(self, args) -> list[str]:
|
||||||
"""Load Slack messages via MCP server."""
|
"""Load Slack messages via MCP server."""
|
||||||
print(f"Connecting to Slack MCP server: {args.mcp_server}")
|
print(f"Connecting to Slack MCP server: {args.mcp_server}")
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ flexible bookmark processing options.
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class TwitterMCPReader:
|
|||||||
await self.mcp_process.wait()
|
await self.mcp_process.wait()
|
||||||
logger.info("Stopped MCP server")
|
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."""
|
"""Send a request to the MCP server and get response."""
|
||||||
if not self.mcp_process:
|
if not self.mcp_process:
|
||||||
raise RuntimeError("MCP server not started")
|
raise RuntimeError("MCP server not started")
|
||||||
@@ -103,7 +103,7 @@ class TwitterMCPReader:
|
|||||||
|
|
||||||
logger.info("MCP connection initialized successfully")
|
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 available tools from the MCP server."""
|
||||||
list_request = {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
|
list_request = {"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {}}
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class TwitterMCPReader:
|
|||||||
|
|
||||||
return response.get("result", {}).get("tools", [])
|
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.
|
Fetch Twitter bookmarks using MCP tools.
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ class TwitterMCPReader:
|
|||||||
|
|
||||||
return bookmarks if isinstance(bookmarks, list) else [bookmarks]
|
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."""
|
"""Format a single bookmark for indexing."""
|
||||||
# Extract tweet information
|
# Extract tweet information
|
||||||
text = bookmark.get("text", bookmark.get("content", ""))
|
text = bookmark.get("text", bookmark.get("content", ""))
|
||||||
@@ -242,7 +242,7 @@ class TwitterMCPReader:
|
|||||||
|
|
||||||
return "\n".join(parts)
|
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.
|
Read Twitter bookmark data and return formatted text chunks.
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ Usage:
|
|||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from apps.base_rag_example import BaseRAGExample
|
from apps.base_rag_example import BaseRAGExample
|
||||||
from apps.twitter_data.twitter_mcp_reader import TwitterMCPReader
|
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")
|
print("5. Try running the MCP server command directly to test it")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def load_data(self, args) -> List[str]:
|
async def load_data(self, args) -> list[str]:
|
||||||
"""Load Twitter bookmarks via MCP server."""
|
"""Load Twitter bookmarks via MCP server."""
|
||||||
print(f"Connecting to Twitter MCP server: {args.mcp_server}")
|
print(f"Connecting to Twitter MCP server: {args.mcp_server}")
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ async def demo_slack_mcp():
|
|||||||
|
|
||||||
# This would typically use a real MCP server command
|
# This would typically use a real MCP server command
|
||||||
# For demo purposes, we show what the command would look like
|
# 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
|
# Simulate command line arguments for testing
|
||||||
class MockArgs:
|
class MockArgs:
|
||||||
@@ -71,7 +71,7 @@ async def demo_twitter_mcp():
|
|||||||
|
|
||||||
print("\n1. Testing Twitter MCP server connection...")
|
print("\n1. Testing Twitter MCP server connection...")
|
||||||
|
|
||||||
twitter_app = TwitterMCPRAG()
|
# twitter_app = TwitterMCPRAG() # Would be used for actual testing
|
||||||
|
|
||||||
class MockArgs:
|
class MockArgs:
|
||||||
mcp_server = "twitter-mcp-server"
|
mcp_server = "twitter-mcp-server"
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def test_slack_reader_initialization():
|
|||||||
# Test basic initialization
|
# Test basic initialization
|
||||||
reader = SlackMCPReader("slack-mcp-server")
|
reader = SlackMCPReader("slack-mcp-server")
|
||||||
assert reader.mcp_server_command == "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
|
assert reader.max_messages_per_conversation == 100
|
||||||
|
|
||||||
# Test with custom parameters
|
# Test with custom parameters
|
||||||
@@ -37,7 +37,7 @@ def test_slack_reader_initialization():
|
|||||||
max_messages_per_conversation=50
|
max_messages_per_conversation=50
|
||||||
)
|
)
|
||||||
assert reader.workspace_name == "test-workspace"
|
assert reader.workspace_name == "test-workspace"
|
||||||
assert reader.concatenate_conversations == False
|
assert not reader.concatenate_conversations
|
||||||
assert reader.max_messages_per_conversation == 50
|
assert reader.max_messages_per_conversation == 50
|
||||||
|
|
||||||
print("✅ SlackMCPReader initialization tests passed")
|
print("✅ SlackMCPReader initialization tests passed")
|
||||||
@@ -50,8 +50,8 @@ def test_twitter_reader_initialization():
|
|||||||
# Test basic initialization
|
# Test basic initialization
|
||||||
reader = TwitterMCPReader("twitter-mcp-server")
|
reader = TwitterMCPReader("twitter-mcp-server")
|
||||||
assert reader.mcp_server_command == "twitter-mcp-server"
|
assert reader.mcp_server_command == "twitter-mcp-server"
|
||||||
assert reader.include_tweet_content == True
|
assert reader.include_tweet_content
|
||||||
assert reader.include_metadata == True
|
assert reader.include_metadata
|
||||||
assert reader.max_bookmarks == 1000
|
assert reader.max_bookmarks == 1000
|
||||||
|
|
||||||
# Test with custom parameters
|
# Test with custom parameters
|
||||||
@@ -63,8 +63,8 @@ def test_twitter_reader_initialization():
|
|||||||
max_bookmarks=500
|
max_bookmarks=500
|
||||||
)
|
)
|
||||||
assert reader.username == "testuser"
|
assert reader.username == "testuser"
|
||||||
assert reader.include_tweet_content == False
|
assert not reader.include_tweet_content
|
||||||
assert reader.include_metadata == False
|
assert not reader.include_metadata
|
||||||
assert reader.max_bookmarks == 500
|
assert reader.max_bookmarks == 500
|
||||||
|
|
||||||
print("✅ TwitterMCPReader initialization tests passed")
|
print("✅ TwitterMCPReader initialization tests passed")
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def test_slack_reader_basic():
|
|||||||
|
|
||||||
reader = SlackMCPReader("slack-mcp-server")
|
reader = SlackMCPReader("slack-mcp-server")
|
||||||
assert reader.mcp_server_command == "slack-mcp-server"
|
assert reader.mcp_server_command == "slack-mcp-server"
|
||||||
assert reader.concatenate_conversations == True
|
assert reader.concatenate_conversations
|
||||||
|
|
||||||
# Test message formatting
|
# Test message formatting
|
||||||
message = {
|
message = {
|
||||||
@@ -61,7 +61,7 @@ def test_twitter_reader_basic():
|
|||||||
|
|
||||||
reader = TwitterMCPReader("twitter-mcp-server")
|
reader = TwitterMCPReader("twitter-mcp-server")
|
||||||
assert reader.mcp_server_command == "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
|
assert reader.max_bookmarks == 1000
|
||||||
|
|
||||||
# Test bookmark formatting
|
# Test bookmark formatting
|
||||||
|
|||||||
Reference in New Issue
Block a user