UNPKG

dingtalk-appmanage-mcp

Version:

钉钉应用管理MCP服务器 - 为AI助手提供完整的企业应用管理能力

142 lines (129 loc) 5.22 kB
#!/usr/bin/env node /** * DingTalk Application Management MCP Server CLI * Command-line interface for running the DingTalk App Management MCP server */ import { DingTalkAppManageServer } from './DingTalkAppManageServer.js'; async function main() { // Check for help flag if (process.argv.includes('--help') || process.argv.includes('-h')) { console.log(` DingTalk Application Management MCP Server v1.0.0 DESCRIPTION: A Model Context Protocol server for DingTalk application management capabilities. Provides AI assistants with enterprise application management tools including: - Application creation, update, and listing - Application scope management (users, departments, roles) - Mini-program version management and publishing - Application permission and visibility control USAGE: dingtalk-appmanage-mcp [options] OPTIONS: --help, -h Show this help message --version, -v Show version information --config <path> Path to YAML configuration file (default: ./dingtalk_appmanage_mcp.yaml) --token-cache <path> Path to token cache file (default: ./.dingtalk_token_cache.json) ENVIRONMENT VARIABLES: DINGTALK_ACCESS_TOKEN Direct access token (optional) DINGTALK_Client_ID Application key for token refresh DINGTALK_Client_Secret Application secret for token refresh CONFIGURATION: The server reads tool definitions from a YAML configuration file. Default location: ./dingtalk_appmanage_mcp.yaml AUTHENTICATION: 1. Direct token: Set DINGTALK_ACCESS_TOKEN environment variable 2. Auto-refresh: Set DINGTALK_Client_ID and DINGTALK_Client_Secret The server will automatically cache and refresh tokens as needed. TOOLS PROVIDED: - createInnerApp: Create enterprise internal applications - updateInnerApp: Update enterprise internal applications - listAllApp: List all enterprise applications - listAllInnerApps: List internal applications only - listUserVilebleApp: List applications visible to specific user - getMicroAppScope: Get application scope settings - setMicroAppScope: Update application scope settings - publishInnerAppVersion: Publish mini-program versions - rollbackInnerAppVersion: Rollback mini-program versions - listInnerAppVersion: List mini-program versions - pageInnerAppHistoryVersion: Paginate mini-program version history EXAMPLES: # Run with environment variables export DINGTALK_Client_ID="your_app_key" export DINGTALK_Client_Secret="your_app_secret" dingtalk-appmanage-mcp # Run with direct token export DINGTALK_ACCESS_TOKEN="your_access_token" dingtalk-appmanage-mcp # Run with custom config dingtalk-appmanage-mcp --config ./my-config.yaml INTEGRATION: Add to your Cursor/MCP client configuration: { "mcpServers": { "dingtalk-appmanage": { "command": "node", "args": ["dist/cli.js"], "cwd": "/path/to/dingtalk-appmanage-mcp", "env": { "DINGTALK_Client_ID": "your_app_key_here", "DINGTALK_Client_Secret": "your_app_secret_here" } } } } For more information, visit: https://github.com/your-org/dingtalk-appmanage-mcp `); process.exit(0); } // Check for version flag if (process.argv.includes('--version') || process.argv.includes('-v')) { console.log('dingtalk-appmanage-mcp v1.0.0'); process.exit(0); } // Parse command line arguments const args = process.argv.slice(2); const options = {}; for (let i = 0; i < args.length; i++) { const arg = args[i]; if (arg === '--config' && i + 1 < args.length) { options.configPath = args[i + 1]; i++; // Skip next argument } else if (arg === '--token-cache' && i + 1 < args.length) { options.tokenCacheFile = args[i + 1]; i++; // Skip next argument } } try { // Initialize and start the server const server = new DingTalkAppManageServer(options); await server.run(); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; console.error('Failed to start DingTalk App Management MCP server:', errorMessage); if (errorMessage.includes('DINGTALK_')) { console.error('\nPlease ensure you have set the required environment variables:'); console.error('- DINGTALK_ACCESS_TOKEN (for direct token) OR'); console.error('- DINGTALK_Client_ID and DINGTALK_Client_Secret (for auto-refresh)'); console.error('\nFor more information, run: dingtalk-appmanage-mcp --help'); } process.exit(1); } } // Handle graceful shutdown process.on('SIGINT', () => { console.error('\nShutting down DingTalk App Management MCP server...'); process.exit(0); }); process.on('SIGTERM', () => { console.error('\nShutting down DingTalk App Management MCP server...'); process.exit(0); }); // Run the main function main().catch((error) => { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; console.error('Unexpected error:', errorMessage); process.exit(1); }); //# sourceMappingURL=cli.js.map