suse-documentation-mcp-server 0.2.0__py3-none-any.whl → 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,101 @@
1
+ import requests
2
+ import re
3
+ import os
4
+ from dotenv import load_dotenv
5
+ from typing import Any
6
+ from mcp.server.fastmcp import FastMCP
7
+ from pydantic import BaseModel, Field
8
+
9
+ load_dotenv()
10
+
11
+ base_url = os.getenv("OI_API_BASE", "") + "/api/v1/retrieval/process/web"
12
+ authorization_token = os.getenv("OI_API_TOKEN", "")
13
+
14
+ # Initialize FastMCP server
15
+ mcp = FastMCP("suse-documentation")
16
+
17
+ def clean_content(content):
18
+ # Remove excessive blank lines
19
+ cleaned_content = re.sub(r'\n\s*\n+', '\n\n', content.strip())
20
+ # Replace multiple spaces with a single space
21
+ cleaned_content = re.sub(r'[ \t]+', ' ', cleaned_content)
22
+ return cleaned_content
23
+
24
+ def get_web_search_results_from_oi(query):
25
+ headers = {
26
+ 'Content-Type': 'application/json',
27
+ 'Authorization': f'Bearer {authorization_token}'
28
+ }
29
+
30
+ # Step 1: Get web search results (list of URLs)
31
+ search_payload = {
32
+ "query": query,
33
+ "collection_name": "your_collection_name"
34
+ }
35
+
36
+ search_response = requests.post(f"{base_url}/search", headers=headers, json=search_payload)
37
+ if search_response.status_code != 200:
38
+ raise Exception(f"Search API call failed: {search_response.status_code} - {search_response.text}")
39
+
40
+ search_data = search_response.json()
41
+
42
+ if not search_data.get("status"):
43
+ raise Exception(f"Search API response indicates failure: {search_data}")
44
+
45
+ filenames = search_data.get("filenames", [])
46
+ if not filenames:
47
+ return "No filenames found in the search response."
48
+
49
+ combined_response = ""
50
+
51
+ # Step 2: Loop through URLs to get page content
52
+ for filename in filenames:
53
+ process_payload = {
54
+ "url": filename,
55
+ "collection_name": search_data["collection_name"]
56
+ }
57
+
58
+ process_response = requests.post(base_url, headers=headers, json=process_payload)
59
+ if process_response.status_code != 200:
60
+ print(f"Failed to process URL {filename}: {process_response.status_code} - {process_response.text}")
61
+ continue
62
+
63
+ process_data = process_response.json()
64
+ if not process_data.get("status"):
65
+ print(f"Processing failed for URL {filename}: {process_data}")
66
+ continue
67
+
68
+ content = process_data.get("file", {}).get("data", {}).get("content", "No content available")
69
+
70
+ # Append to get combined response
71
+ cleaned_content = clean_content(content)
72
+ combined_response += f"Source: {filename}\n\nContent:\n{cleaned_content}\n\n"
73
+
74
+ return combined_response
75
+
76
+ class WebSearchToolInput(BaseModel):
77
+ """Input schema for WebSearchTool."""
78
+ query: str = Field(..., description="search query")
79
+ @mcp.tool()
80
+ async def get_web_search_results(query: str) -> str:
81
+ """Get web search results for a given query.
82
+
83
+ Args:
84
+ query: Web search query
85
+ """
86
+ args_schema: Type[BaseModel] = WebSearchToolInput
87
+ try:
88
+ return get_web_search_results_from_oi(query)
89
+ except Exception as e:
90
+ return f"Error performing web search: {str(e)}"
91
+
92
+
93
+ def main():
94
+ """Main entry point for the script."""
95
+ # Initialize and run the server
96
+ mcp.run(transport='stdio')
97
+
98
+ if __name__ == "__main__":
99
+ # Initialize and run the server
100
+ mcp.run(transport='stdio')
101
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: suse-documentation-mcp-server
3
- Version: 0.2.0
3
+ Version: 0.4.0
4
4
  Summary: Add your description here
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,6 @@
1
+ server/search_suse_documentation.py,sha256=ZKznYKFSr2VZm1aHbjKlHaJG3rBCSV_DiUZYT1gZcJk,3359
2
+ suse_documentation_mcp_server-0.4.0.dist-info/METADATA,sha256=I6BIWipFsdVs3T52YahcNCtiB9Y7B0nlXPQKAwxAoko,343
3
+ suse_documentation_mcp_server-0.4.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
4
+ suse_documentation_mcp_server-0.4.0.dist-info/entry_points.txt,sha256=IEM7kH8YFWMMJCcp4hJGv5tHzHWxiR5lZ7jOyzRCHQA,88
5
+ suse_documentation_mcp_server-0.4.0.dist-info/top_level.txt,sha256=StKOSmRhvWS5IPcvhsDRbtxUTEofJgYFGOu5AAJdSWo,7
6
+ suse_documentation_mcp_server-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ suse-documentation-mcp-server = server.search_suse_documentation:main
@@ -1,4 +0,0 @@
1
- suse_documentation_mcp_server-0.2.0.dist-info/METADATA,sha256=0fy3O3OTkesfR66aUbXsdXjUWZodR92Z3P8tp_luFnY,343
2
- suse_documentation_mcp_server-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
3
- suse_documentation_mcp_server-0.2.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
- suse_documentation_mcp_server-0.2.0.dist-info/RECORD,,