|
| 1 | +from __future__ import annotations |
| 2 | +from typing import List |
1 | 3 | import asyncio |
2 | 4 | import os |
| 5 | +import argparse |
3 | 6 | import mcp.server.stdio |
4 | 7 | import mcp.types as types |
5 | 8 | from mcp.server import NotificationOptions, Server |
|
19 | 22 | from .tool_manager import ToolManager |
20 | 23 | from .service import Service |
21 | 24 |
|
| 25 | +def parse_args(): |
| 26 | + parser = argparse.ArgumentParser(description='Appwrite MCP Server') |
| 27 | + parser.add_argument('--databases', action='store_true', help='Enable Databases service') |
| 28 | + parser.add_argument('--users', action='store_true', help='Enable Users service') |
| 29 | + parser.add_argument('--teams', action='store_true', help='Enable Teams service') |
| 30 | + parser.add_argument('--storage', action='store_true', help='Enable Storage service') |
| 31 | + parser.add_argument('--functions', action='store_true', help='Enable Functions service') |
| 32 | + parser.add_argument('--messaging', action='store_true', help='Enable Messaging service') |
| 33 | + parser.add_argument('--locale', action='store_true', help='Enable Locale service') |
| 34 | + parser.add_argument('--avatars', action='store_true', help='Enable Avatars service') |
| 35 | + parser.add_argument('--all', action='store_true', help='Enable all services') |
| 36 | + return parser.parse_args() |
| 37 | + |
22 | 38 | # Load environment variables from .env file |
23 | 39 | load_dotenv() |
24 | 40 |
|
|
36 | 52 | client.set_project(project_id) |
37 | 53 | client.set_key(api_key) |
38 | 54 |
|
39 | | -# Initialize tools manager and register services |
| 55 | +# Initialize tools manager |
40 | 56 | tools_manager = ToolManager() |
41 | | -tools_manager.register_service(Service(Users(client), "users")) |
42 | | -# tools_manager.register_service(Service(Teams(client), "teams")) |
43 | | -tools_manager.register_service(Service(Databases(client), "databases")) |
44 | | -# tools_manager.register_service(Service(Storage(client), "storage")) |
45 | | -# tools_manager.register_service(Service(Functions(client), "functions")) |
46 | | -# tools_manager.register_service(Service(Messaging(client), "messaging")) |
| 57 | + |
| 58 | +def register_services(args): |
| 59 | + # If --all is specified, enable all services |
| 60 | + if args.all: |
| 61 | + args.databases = args.users = args.teams = args.storage = True |
| 62 | + args.functions = args.messaging = args.locale = args.avatars = True |
| 63 | + |
| 64 | + # Register services based on CLI arguments |
| 65 | + if args.databases: |
| 66 | + tools_manager.register_service(Service(Databases(client), "databases")) |
| 67 | + if args.users: |
| 68 | + tools_manager.register_service(Service(Users(client), "users")) |
| 69 | + if args.teams: |
| 70 | + tools_manager.register_service(Service(Teams(client), "teams")) |
| 71 | + if args.storage: |
| 72 | + tools_manager.register_service(Service(Storage(client), "storage")) |
| 73 | + if args.functions: |
| 74 | + tools_manager.register_service(Service(Functions(client), "functions")) |
| 75 | + if args.messaging: |
| 76 | + tools_manager.register_service(Service(Messaging(client), "messaging")) |
| 77 | + if args.locale: |
| 78 | + tools_manager.register_service(Service(Locale(client), "locale")) |
| 79 | + if args.avatars: |
| 80 | + tools_manager.register_service(Service(Avatars(client), "avatars")) |
| 81 | + |
| 82 | + # If no services were specified, enable databases by default |
| 83 | + if not any([args.databases, args.users, args.teams, args.storage, |
| 84 | + args.functions, args.messaging, args.locale, args.avatars]): |
| 85 | + tools_manager.register_service(Service(Databases(client), "databases")) |
47 | 86 |
|
48 | 87 | async def serve() -> Server: |
49 | 88 | server = Server("Appwrite MCP Server") |
@@ -76,14 +115,17 @@ async def handle_call_tool( |
76 | 115 | return server |
77 | 116 |
|
78 | 117 | async def _run(): |
| 118 | + args = parse_args() |
| 119 | + register_services(args) |
| 120 | + |
79 | 121 | async with mcp.server.stdio.stdio_server() as (read_stream, write_stream): |
80 | 122 | server = await serve() |
81 | 123 | await server.run( |
82 | 124 | read_stream, |
83 | 125 | write_stream, |
84 | 126 | InitializationOptions( |
85 | 127 | server_name="appwrite", |
86 | | - server_version="0.1.0", |
| 128 | + server_version="0.1.3", |
87 | 129 | capabilities=server.get_capabilities( |
88 | 130 | notification_options=NotificationOptions(), |
89 | 131 | experimental_capabilities={}, |
|
0 commit comments