File size: 6,546 Bytes
8ba2581
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# from mcp.server.fastmcp import FastMCP
# import json
# from typing import Dict, List, Any
# import logging

# # Set up logging
# logging.basicConfig(level=logging.INFO)
# logger = logging.getLogger(__name__)

# # Initialize MCP server
# mcp = FastMCP("intelligent-content-organizer")

# @mcp.tool()
# async def process_file(file_path: str) -> Dict[str, Any]:
#     """
#     Process a local file and extract content, generate tags, and create embeddings
    
#     Args:
#         file_path: Path to the file to process
        
#     Returns:
#         Dictionary containing processed content, tags, and metadata
#     """
#     try:
#         from mcp_tools import process_local_file
#         result = await process_local_file(file_path)
#         return result
#     except Exception as e:
#         logger.error(f"Error processing file: {str(e)}")
#         return {"error": str(e)}

# @mcp.tool()
# async def process_url(url: str) -> Dict[str, Any]:
#     """
#     Fetch and process content from a URL
    
#     Args:
#         url: URL to fetch and process
        
#     Returns:
#         Dictionary containing processed content, tags, and metadata
#     """
#     try:
#         from mcp_tools import process_web_content
#         result = await process_web_content(url)
#         return result
#     except Exception as e:
#         logger.error(f"Error processing URL: {str(e)}")
#         return {"error": str(e)}

# @mcp.tool()
# async def semantic_search(query: str, limit: int = 5) -> List[Dict[str, Any]]:
#     """
#     Perform semantic search across stored documents
    
#     Args:
#         query: Search query
#         limit: Maximum number of results to return
        
#     Returns:
#         List of relevant documents with metadata
#     """
#     try:
#         from mcp_tools import search_knowledge_base
#         results = await search_knowledge_base(query, limit)
#         return results
#     except Exception as e:
#         logger.error(f"Error performing search: {str(e)}")
#         return [{"error": str(e)}]

# @mcp.tool()
# async def get_document_summary(doc_id: str) -> Dict[str, Any]:
#     """
#     Get summary and metadata for a specific document
    
#     Args:
#         doc_id: Document ID in the knowledge base
        
#     Returns:
#         Document summary and metadata
#     """
#     try:
#         from mcp_tools import get_document_details
#         result = await get_document_details(doc_id)
#         return result
#     except Exception as e:
#         logger.error(f"Error getting document summary: {str(e)}")
#         return {"error": str(e)}

# # Server metadata
# @mcp.resource("server_info")
# async def get_server_info() -> Dict[str, Any]:
#     """Get information about this MCP server"""
#     return {
#         "name": "Intelligent Content Organizer",
#         "version": "1.0.0",
#         "description": "AI-powered knowledge management system with automatic tagging and semantic search",
#         "capabilities": [
#             "File processing (20+ formats)",
#             "Web content extraction",
#             "Automatic tagging",
#             "Semantic search",
#             "Document summarization"
#         ]
#     }

# if __name__ == "__main__":
#     # Run the MCP server
#     import asyncio
#     asyncio.run(mcp.run())

from mcp.server.fastmcp import FastMCP
import json
from typing import Dict, List, Any
import logging

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Initialize MCP server
mcp = FastMCP("intelligent-content-organizer")

@mcp.tool()
async def process_file(file_path: str) -> Dict[str, Any]:
    """
    Process a local file and extract content, generate tags, and create embeddings
    """
    try:
        from mcp_tools import process_local_file
        result = await process_local_file(file_path)
        return result
    except Exception as e:
        logger.error(f"Error processing file: {str(e)}")
        return {"error": str(e)}

@mcp.tool()
async def process_url(url: str) -> Dict[str, Any]:
    """
    Fetch and process content from a URL
    """
    try:
        from mcp_tools import process_web_content
        result = await process_web_content(url)
        return result
    except Exception as e:
        logger.error(f"Error processing URL: {str(e)}")
        return {"error": str(e)}

@mcp.tool()
async def semantic_search(query: str, limit: int = 5) -> List[Dict[str, Any]]:
    """
    Perform semantic search across stored documents
    """
    try:
        from mcp_tools import search_knowledge_base
        results = await search_knowledge_base(query, limit)
        return results
    except Exception as e:
        logger.error(f"Error performing search: {str(e)}")
        return [{"error": str(e)}]

@mcp.tool()
async def get_document_summary(doc_id: str) -> Dict[str, Any]:
    """
    Get summary and metadata for a specific document
    """
    try:
        from mcp_tools import get_document_details
        result = await get_document_details(doc_id)
        return result
    except Exception as e:
        logger.error(f"Error getting document summary: {str(e)}")
        return {"error": str(e)}

@mcp.tool()
async def get_server_info() -> Dict[str, Any]:
    """
    Get information about this MCP server
    """
    return {
        "name": "Intelligent Content Organizer",
        "version": "1.0.0",
        "description": "AI-powered knowledge management system with automatic tagging and semantic search",
        "capabilities": [
            "File processing (20+ formats)",
            "Web content extraction",
            "Automatic tagging",
            "Semantic search",
            "Document summarization"
        ],
        "tools": [
            {
                "name": "process_file",
                "description": "Process local files and extract content"
            },
            {
                "name": "process_url",
                "description": "Fetch and process web content"
            },
            {
                "name": "semantic_search",
                "description": "Search across stored documents"
            },
            {
                "name": "get_document_summary",
                "description": "Get document details"
            },
            {
                "name": "get_server_info",
                "description": "Get server information"
            }
        ]
    }

if __name__ == "__main__":
    # Run the MCP server
    import asyncio
    asyncio.run(mcp.run())