-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathserver.py
More file actions
86 lines (66 loc) · 2.87 KB
/
Copy pathserver.py
File metadata and controls
86 lines (66 loc) · 2.87 KB
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
"""
OpenProject MCP Server - FastMCP Implementation
Main server file that initializes FastMCP and registers all tools.
"""
import os
import logging
from dotenv import load_dotenv
from fastmcp import FastMCP
from src.client import OpenProjectClient
# Load environment variables
load_dotenv()
# Configure logging
logging.basicConfig(
level=os.getenv("LOG_LEVEL", "INFO"),
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)
# Initialize FastMCP server
mcp = FastMCP(
name="openproject-mcp"
)
# Initialize OpenProject client as global variable
_client = None
try:
base_url = os.getenv("OPENPROJECT_URL")
api_key = os.getenv("OPENPROJECT_API_KEY")
proxy = os.getenv("OPENPROJECT_PROXY")
if not base_url or not api_key:
raise ValueError(
"Missing required environment variables: OPENPROJECT_URL and OPENPROJECT_API_KEY must be set"
)
_client = OpenProjectClient(
base_url=base_url,
api_key=api_key,
proxy=proxy
)
logger.info(f"✅ OpenProject MCP Server initialized")
logger.info(f" Server: {base_url}")
logger.info(f" Proxy: {proxy if proxy else 'None'}")
except Exception as e:
logger.error(f"❌ Failed to initialize OpenProject client: {e}")
raise
# Dependency injection helper for tools
def get_client():
"""Get OpenProject client instance."""
return _client
# Import ALL tool modules (decorators auto-register tools)
logger.info("Loading tool modules...")
try:
# Phase 1: Priority tools (7 tools)
from src.tools import connection # 2 tools: test_connection, check_permissions
from src.tools import work_packages # 7 tools: list, create, update, delete, list_types, list_statuses, list_priorities
from src.tools import projects # 5 tools: list, get, create, update, delete
# Phase 2: Additional tools (28 tools)
from src.tools import users # 6 tools: list_users, get_user, list_roles, get_role, list_project_members, list_user_projects
from src.tools import memberships # 5 tools: list, get, create, update, delete
from src.tools import hierarchy # 3 tools: set_parent, remove_parent, list_children
from src.tools import relations # 5 tools: create, list, get, update, delete
from src.tools import time_entries # 5 tools: list, create, update, delete, list_activities
from src.tools import versions # 2 tools: list, create
from src.tools import weekly_reports # 4 tools: generate_weekly_report, get_report_data, generate_this_week_report, generate_last_week_report
from src.tools import news # 5 tools: list_news, create_news, get_news, update_news, delete_news
logger.info("✅ All 49 tool modules loaded successfully")
except ImportError as e:
logger.warning(f"⚠️ Some tool modules failed to import: {e}")
raise