* fix(mcp-server): make tool input schemas JSON Schema compatible Replace z.date() on MCP tool inputs (forRange, BaseEntitySchema timestamps, create_activity_log) with ISO datetime strings so tools/list no longer fails with -32603 under Zod v4. Co-authored-by: Cursor <cursoragent@cursor.com> * test(mcp-server): harden schema regression and share tool registration Extract registerAllMcpTools for production and tests to cut duplicated registration lists (Sonar new-code duplication), and fail the capturing server.tool mock on unrecognized signatures so input schemas cannot be skipped. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(mcp-server): address PR review on forRange, employee, and lets Map working-employee forRange to startDate/endDate for API filtering, keep create_activity_log employee payload as a JSON-safe optional record, and use let for conceptually mutable arrays in the schema regression test. Co-authored-by: Cursor <cursoragent@cursor.com> * test(mcp-server): assert date-time format and cover tools/list protocol Strengthen forRange assertions with format date-time and add an in-memory initialize → tools/list regression against the production MCP server setup. * test(mcp-server): align JSON-RPC wait timeout under Jest limit Use 4s so the helper error surfaces before the generic Jest timeout, and restore transport.onmessage when the wait timer fires. * fix(mcp-server): allow timezone offsets in working-employee date ranges Match API moment.utc() acceptance by using datetime({ offset: true }) on both forRange schemas, and assert offset ISO strings parse in tests. * refactor(mcp-server): dedupe working-employee forRange schema and fetch Share one datetime offset schema and API helper across list/count tools, and centralize forRange date-time assertions to clear Sonar duplication. * test(mcp-server): let the tools/list schema spec compile under the package jest config The committed tsconfig.spec.json inherits strict and lacks esModuleInterop, so the new input-schema-json spec failed with TS1192 at session-store.ts:2 and ran 0 tests. Match tsconfig.lib.json's relaxed options (type-checking stays on) and fix two prefer-const lint errors in the spec. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * test(mcp-server): move test env defaults into a setup file; cspell words - the static-checks typecheck-configs job compiles every jest.config.ts without Node types, so the process.env defaults at the top of the mcp-server jest config failed it (TS2591); they now live in src/test-setup.ts (setupFilesAfterEnv, excluded from the lib build) - cspell: add nocheck (existing // @ts-nocheck lines) and Hostinger (README on develop), and reword a Zod's comment the cspell action flags Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Ruslan Konviser <evereq@gmail.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Gauzy MCP Server - Shared Package
A comprehensive TypeScript package that provides the core MCP (Model Context Protocol) server implementation for the Gauzy platform. This package serves as the foundation for both the standalone MCP server and the Electron desktop application.
Overview
The @gauzy/mcp-server package contains all the shared functionality needed to interact with Gauzy's API through the Model Context Protocol. It provides a complete set of tools, authentication management, and server utilities that can be used by different consumer applications.
Architecture
This package is designed to be consumed by:
🚀 Standalone App: apps/mcp
- Direct integration with AI assistants (Claude Desktop, ChatGPT, etc.)
- Stdio-based transport for AI assistant communication
- Lightweight command-line interface
🖥️ Desktop App: apps/server-mcp
- Electron desktop application with modern UI
- Server management and monitoring interface
- System tray integration and auto-updater support
Installation
# Install as a dependency
npm install @gauzy/mcp-server
# Or with yarn
yarn add @gauzy/mcp-server
Package Build
# Build the shared package
yarn nx build mcp-server
# Run tests
yarn nx test mcp-server
# Lint the code
yarn nx lint mcp-server
Usage
Basic Server Setup
import { McpServer } from '@gauzy/mcp-server';
import { environment } from './environments/environment';
// Create and start the MCP server
const server = new McpServer(environment);
server.start();
Using Individual Tools
import { AuthTool, TimerTool, ProjectTool } from '@gauzy/mcp-server/tools';
import { ApiClient } from '@gauzy/mcp-server';
// Initialize API client
const apiClient = new ApiClient({
baseUrl: 'https://api.gauzy.co',
email: 'user@example.com',
password: 'password'
});
// Use specific tools
const authTool = new AuthTool(apiClient);
const timerTool = new TimerTool(apiClient);
const projectTool = new ProjectTool(apiClient);
Server Manager
import { McpServerManager } from '@gauzy/mcp-server';
const manager = new McpServerManager();
// Start server with configuration
await manager.start({
apiBaseUrl: 'https://api.gauzy.co',
authEmail: 'user@example.com',
authPassword: 'password',
autoLogin: true
});
// Stop server
await manager.stop();
// Get server status
const status = manager.getStatus();
Core Features
- Smart Authentication: Automatic user context detection
- Token Management: Handles access and refresh tokens automatically
- Session Persistence: Maintains authentication state across sessions
- Auto-login: Configurable automatic login on server start
- OAuth 2.0 Authorization: OAuth 2.0 bearer authorization (RFC 6749, RFC 6750)
- Protected Resource Metadata: RFC 9728 /.well-known/oauth-protected-resource for clients/AS discovery
- Token Validation: JWT and token introspection support with audience validation
- Scope Management: Fine-grained access control with OAuth 2.0 scopes
🛠️ Comprehensive Tool Suite (323 tools across 22 categories)
Authentication (5 tools)
- User login and logout functionality
- Authentication status monitoring
- Token refresh and management
- Auto-login capabilities
Employee Management (15 tools)
- Employee CRUD operations with bulk support
- Employee statistics and analytics
- Profile management and updates
- Organization member management
Task Management (16 tools)
- Complete task lifecycle management
- Bulk operations for efficiency
- Task assignment to employees
- Personal and team task views
- Task statistics and reporting
Project Management (14 tools)
- Full project CRUD with bulk operations
- Project assignment management
- Project analytics and reporting
- Team project collaboration
Daily Planning (17 tools)
- Personal and team daily plans
- Task integration with daily plans
- Bulk planning operations
- Planning analytics and statistics
Organization Contacts (17 tools)
- Contact management with full CRUD
- Bulk contact operations
- Employee contact assignments
- Contact categorization and filtering
Timer & Time Tracking (3 tools)
- Start/stop time tracking
- Real-time timer status
- Integration with projects and tasks
Testing & Diagnostics (3 tools)
- API connectivity testing
- Server capability enumeration
- Health check and monitoring
Financial Management (37 tools)
- Payments (14 tools): Payment processing and management
- Expenses (9 tools): Expense tracking and reporting
- Invoices (14 tools): Invoice creation and management
Activity & Logging (12 tools)
- Activity tracking and audit logging
- User action monitoring
- System event recording
Candidate Management (15 tools)
- Recruitment process management
- Candidate tracking and evaluation
- Interview scheduling and feedback
Content & Communication (15 tools)
- Comment and discussion management
- Team communication tools
- Content collaboration features
Sales & CRM (23 tools)
- Deals (15 tools): Sales opportunity tracking
- Pipelines (8 tools): Sales pipeline management
Goal Management (24 tools)
- Goals (12 tools): Objective setting and tracking
- Key Results (12 tools): OKR management system
Inventory & Equipment (21 tools)
- Equipment (16 tools): Asset and equipment tracking
- Warehouses (5 tools): Inventory location management
Product Management (18 tools)
- Products (13 tools): Product catalog management
- Product Categories (5 tools): Product organization
Income Management (13 tools)
- Revenue tracking and reporting
- Income categorization and analysis
Merchant Management (14 tools)
- Vendor and supplier management
- Merchant relationship tracking
Skills Management (10 tools)
- Employee skill tracking
- Competency assessment and development
Time Off Management (20 tools)
- Leave request and approval system
- PTO tracking and management
- Holiday and absence planning
Reporting (4 tools)
- Data analytics and insights
- Custom report generation
HR & Awards (7 tools)
- Employee recognition programs
- Achievement tracking and rewards
🏗️ Technical Features
- 📝 Schema Validation: Comprehensive Zod schemas with TypeScript support
- 🔄 Bulk Operations: Efficient batch processing for all major entities
- 📊 Analytics: Built-in statistics and reporting capabilities
- 🔗 Relationship Management: Support for entity relationships and eager loading
- 📄 Pagination: Efficient data browsing with configurable page sizes
- 🏷️ Assignment Operations: Employee assignment/unassignment workflows
- 🔄 Auto-refresh: Automatic token refresh and session management
- 🛡️ Error Handling: Robust error handling with detailed messages
- 📋 Logging: Comprehensive logging with configurable levels
Package Structure
packages/mcp-server/
├── src/
│ ├── lib/
│ │ ├── mcp-server.ts # Core MCP server implementation
│ │ ├── mcp-server-manager.ts # Server lifecycle management
│ │ ├── tools/ # MCP tool implementations
│ │ │ ├── auth.ts # Authentication tools
│ │ │ ├── timer.ts # Time tracking tools
│ │ │ ├── projects.ts # Project management tools
│ │ │ ├── tasks.ts # Task management tools
│ │ │ ├── employees.ts # Employee management tools
│ │ │ ├── daily-plan.ts # Daily planning tools
│ │ │ ├── organization-contact.ts # Contact tools
│ │ │ └── test-connection.ts # Testing tools
│ │ ├── common/ # Shared utilities
│ │ │ ├── api-client.ts # API client implementation
│ │ │ ├── auth-manager.ts # Authentication management
│ │ │ ├── version.ts # Version information
│ │ │ └── types.ts # TypeScript type definitions
│ │ └── environments/ # Environment configurations
│ │ └── environment.ts # Environment interface
│ └── index.ts # Package exports
├── package.json # Package configuration
├── project.json # Nx configuration
├── tsconfig.lib.json # TypeScript configuration
└── README.md # This file
Development
Adding New Tools
-
Create the tool: Add your tool implementation to
src/lib/tools/// src/lib/tools/my-new-tool import { Tool } from '@modelcontextprotocol/sdk/types.js'; import { ApiClient } from '../common/api-client'; export class MyNewTool { constructor(private apiClient: ApiClient) {} getTools(): Tool[] { return [ { name: 'my_new_tool', description: 'Description of what this tool does', inputSchema: { type: 'object', properties: { // Define your parameters here } } } ]; } } -
Export the tool: Add it to the tools index file
// src/lib/tools/index.ts export * from './my-new-tool'; -
Register the tool: Include it in the main server
// src/lib/mcp-server.ts import { MyNewTool } from './tools/my-new-tool'; // Register the tool in the tools array -
Export from package: Add to main index if needed
// src/index.ts export * from './lib/tools/my-new-tool';
Configuration
The package uses environment-based configuration:
// Environment interface
export interface Environment {
apiBaseUrl: string;
authEmail?: string;
authPassword?: string;
autoLogin?: boolean;
debug?: boolean;
}
Building and Testing
# Build the package
yarn nx build mcp-server
# Run tests
yarn nx test mcp-server
# Run linting
yarn nx lint mcp-server
# Type checking
yarn nx type-check mcp-server
API Reference
Core Classes
McpServer
Main server class that implements the MCP protocol.
class McpServer {
constructor(environment: Environment)
start(): Promise<void>
stop(): Promise<void>
getStatus(): ServerStatus
}
McpServerManager
Manages server lifecycle and provides higher-level operations.
class McpServerManager {
start(config: ServerConfig): Promise<void>
stop(): Promise<void>
restart(): Promise<void>
getStatus(): ManagerStatus
}
ApiClient
HTTP client for communicating with Gauzy API.
class ApiClient {
constructor(config: ApiConfig)
login(email: string, password: string): Promise<AuthResponse>
get<T>(endpoint: string, params?: any): Promise<T>
post<T>(endpoint: string, data?: any): Promise<T>
put<T>(endpoint: string, data?: any): Promise<T>
delete<T>(endpoint: string): Promise<T>
}
AuthManager
Handles authentication and token management.
class AuthManager {
login(email: string, password: string): Promise<void>
logout(): Promise<void>
refreshToken(): Promise<void>
isAuthenticated(): boolean
getCurrentUser(): User | null
}
Environment Configuration
Required Variables
API_BASE_URL=https://api.gauzy.co # Gauzy API endpoint
Optional Variables
GAUZY_AUTH_EMAIL=user@example.com # Auto-login email
GAUZY_AUTH_PASSWORD=password # Auto-login password
GAUZY_AUTO_LOGIN=true # Enable auto-login
GAUZY_MCP_DEBUG=true # Enable debug logging
NODE_ENV=development # Environment mode
Troubleshooting
Package Build Issues
-
TypeScript compilation errors
# Check TypeScript configuration yarn nx lint mcp-server # Fix type issues and rebuild yarn nx build mcp-server -
Missing dependencies
# Install all dependencies yarn install # Clean and rebuild yarn nx reset yarn nx build mcp-server
Runtime Issues
-
Authentication failures
- Verify API_BASE_URL is correct
- Check email/password credentials
- Ensure API server is accessible
-
Tool registration errors
- Verify tool exports in index files
- Check tool implementation follows MCP spec
- Review server logs for specific errors
Debug Mode
Enable comprehensive debugging:
GAUZY_MCP_DEBUG=true yarn nx build mcp-server
This provides:
- Detailed API request/response logging
- Tool execution tracing
- Authentication flow debugging
- Error stack traces
Contributing
Development Workflow
- Fork and clone the repository
- Install dependencies:
yarn install - Create feature branch:
git checkout -b feature/my-feature - Make changes to the package
- Build and test:
yarn nx build mcp-server && yarn nx test mcp-server - Submit pull request
Code Style
- Follow existing TypeScript conventions
- Use Zod schemas for data validation
- Include comprehensive error handling
- Add JSDoc comments for public APIs
- Write unit tests for new functionality
Adding New Tools
New tools should:
- Extend the base tool pattern
- Include proper TypeScript types
- Provide comprehensive input validation
- Handle errors gracefully
- Include documentation and examples