Coverage for src/mcp_atlassian/confluence/client.py: 100%
12 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-10 01:37 +0900
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-10 01:37 +0900
1"""Base client module for Confluence API interactions."""
3import logging
5from atlassian import Confluence
7from .config import ConfluenceConfig
9# Configure logging
10logger = logging.getLogger("mcp-atlassian")
13class ConfluenceClient:
14 """Base client for Confluence API interactions."""
16 def __init__(self, config: ConfluenceConfig | None = None) -> None:
17 """Initialize the Confluence client with given or environment config.
19 Args:
20 config: Configuration for Confluence client. If None, will load from
21 environment.
23 Raises:
24 ValueError: If configuration is invalid or environment variables are missing
25 """
26 self.config = config or ConfluenceConfig.from_env()
27 self.confluence = Confluence(
28 url=self.config.url,
29 username=self.config.username,
30 password=self.config.api_token, # API token is used as password
31 cloud=True,
32 )
33 # Import here to avoid circular imports
34 from ..preprocessing import TextPreprocessor
36 self.preprocessor = TextPreprocessor(
37 base_url=self.config.url, confluence_client=self.confluence
38 )
40 def _process_html_content(
41 self, html_content: str, space_key: str
42 ) -> tuple[str, str]:
43 """Process HTML content into both HTML and markdown formats.
45 Args:
46 html_content: Raw HTML content from Confluence
47 space_key: The key of the space containing the content
49 Returns:
50 Tuple of (processed_html, processed_markdown)
51 """
52 return self.preprocessor.process_html_content(html_content, space_key)