UNPKG

survey-mcp-server

Version:

Survey management server handling survey creation, response collection, analysis, and reporting with database access for data management

277 lines (225 loc) 9.16 kB
# Survey MCP Server A TypeScript-based server for handling survey management, response collection, analysis, and reporting with database access for data management. ## Features - Survey creation and management - Response collection and analysis - Fleet survey coordination - Certificate tracking and management - Class society integration - Survey reporting and analytics - Typesense integration for search - MongoDB integration for data storage ## Prerequisites - Node.js (v18 or higher) - MongoDB - Typesense - OpenAI API key - LlamaParse API key - Perplexity API key ## Configuration You can configure the server in three ways: ### 1. Environment-Specific Configuration Files The server now supports environment-specific configuration files. Create a file named `.env.{environment}` where `{environment}` matches your NODE_ENV value: ``` .env.development # Used when NODE_ENV=development (default) .env.production # Used when NODE_ENV=production .env.staging # Used when NODE_ENV=staging .env # Fallback if no environment-specific file is found ``` To use a specific environment: ```bash NODE_ENV=production node dist/index.js ``` See the `env.production.example` file for a template of production environment variables. ### 2. Environment Variables (.env file) Create a `.env` file in the root directory: ```env MONGO_URI=mongodb://localhost:27017 DB_NAME=mcp_survey TYPESENSE_HOST=localhost TYPESENSE_PORT=8108 TYPESENSE_PROTOCOL=http TYPESENSE_API_KEY=your_typesense_api_key OPENAI_API_KEY=your_openai_api_key LLAMA_API_KEY=your_llama_api_key VENDOR_MODEL=gpt-4 S3_API_TOKEN=your_s3_api_token S3_GENERATE_HTML_URL=your_s3_generate_html_url LLAMA_PARSE_URL=your_llama_parse_url PERPLEXITY_API_KEY=your_perplexity_api_key GOOGLE_CLIENT_ID=your_google_client_id GOOGLE_CLIENT_SECRET=your_google_client_secret GOOGLE_REDIRECT_URI=your_google_redirect_uri GOOGLE_API_KEY=your_google_api_key GOOGLE_SEARCH_ENGINE_ID=your_google_search_engine_id COHERE_API_KEY=your_cohere_api_key COMPANY_NAME=your_company_name # API Configuration SNAPSHOT_URL=https://dev-api.siya.com/v1.0/vessel-info/qna-snapshot JWT_TOKEN=your_jwt_token_here ``` ### 3. Command Line Arguments Command line arguments will override values from the `.env` file: ```bash node dist/index.js \ --mongo-uri mongodb://localhost:27017 \ --db-name mcp_survey \ --typesense-host localhost \ --typesense-port 8108 \ --typesense-protocol http \ --typesense-api-key your_api_key \ --openai-api-key your_openai_key \ --llama-api-key your_llama_key \ --vendor-model gpt-4 \ --s3-api-token your_s3_token \ --perplexity-api-key your_perplexity_key \ --company-name your_company_name ``` #### Available Command Line Arguments | Argument | Environment Variable | Default | Description | |----------|---------------------|---------|-------------| | `--mongo-uri` | `MONGO_URI` | `mongodb://localhost:27017` | MongoDB connection URI | | `--db-name` | `DB_NAME` | `mcp_survey` | MongoDB database name | | `--typesense-host` | `TYPESENSE_HOST` | `localhost` | Typesense server host | | `--typesense-port` | `TYPESENSE_PORT` | `8108` | Typesense server port | | `--typesense-protocol` | `TYPESENSE_PROTOCOL` | `http` | Typesense protocol (http/https) | | `--typesense-api-key` | `TYPESENSE_API_KEY` | _(empty)_ | Typesense API key | | `--openai-api-key` | `OPENAI_API_KEY` | _(empty)_ | OpenAI API key | | `--llama-api-key` | `LLAMA_API_KEY` | _(empty)_ | LlamaParse API key | | `--vendor-model` | `VENDOR_MODEL` | `gpt-4` | Default LLM model | | `--s3-api-token` | `S3_API_TOKEN` | _(empty)_ | S3 API token | | `--s3-generate-html-url` | `S3_GENERATE_HTML_URL` | _(empty)_ | S3 HTML generation URL | | `--llama-parse-url` | `LLAMA_PARSE_URL` | _(empty)_ | LlamaParse service URL | | `--perplexity-api-key` | `PERPLEXITY_API_KEY` | _(empty)_ | Perplexity API key | | `--google-client-id` | `GOOGLE_CLIENT_ID` | _(empty)_ | Google OAuth client ID | | `--google-client-secret` | `GOOGLE_CLIENT_SECRET` | _(empty)_ | Google OAuth client secret | | `--google-redirect-uri` | `GOOGLE_REDIRECT_URI` | _(empty)_ | Google OAuth redirect URI | | `--google-api-key` | `GOOGLE_API_KEY` | _(empty)_ | Google API key | | `--google-search-engine-id` | `GOOGLE_SEARCH_ENGINE_ID` | _(empty)_ | Google Custom Search Engine ID | | `--cohere-api-key` | `COHERE_API_KEY` | _(empty)_ | Cohere API key | | `--company-name` | `COMPANY_NAME` | _(required)_ | Company name (mandatory) | | `--snapshot-url` | `SNAPSHOT_URL` | `https://dev-api.siya.com/v1.0/vessel-info/qna-snapshot` | API endpoint for vessel QnA snapshots | | `--jwt-token` | `JWT_TOKEN` | _(default dev token)_ | JWT token for API authentication | ## Installation 1. Clone the repository: ```bash git clone https://github.com/syia-ai/survey_mcp_server.git cd survey_mcp_server ``` 2. Install dependencies: ```bash npm install ``` 3. Build the project: ```bash npm run build ``` 4. Start the server: ```bash npm start ``` ## Development For development with hot reload: ```bash npm run dev ``` ## Testing Test the server with MCP Inspector: ```bash npm test ``` ## MCP Tools and Resources ### Survey Management Tools - `create_survey`: Create new surveys with custom questions - `get_survey_details`: Get detailed survey information - `list_surveys_by_status`: List surveys filtered by status - `get_survey_responses`: Get survey response data - `analyze_survey_results`: Analyze survey response patterns ### Fleet Survey Tools - `get_fleet_survey_overview`: Get fleet-wide survey status - `get_vessel_survey_history`: Get vessel survey history - `get_survey_compliance_status`: Get survey compliance tracking - `export_fleet_survey_data`: Export fleet survey data ### Certificate Management Tools - `get_certificate_details`: Get certificate information - `list_certificates_by_status`: List certificates by status - `get_certificate_expiry_alerts`: Get certificate expiry alerts - `track_certificate_renewals`: Track certificate renewal status ### Class Society Tools - `get_class_society_reports`: Get class society inspection reports - `get_survey_schedules`: Get survey schedules and timelines - `get_class_condition_reports`: Get class condition assessment reports ### Search Tools - `google_search`: Perform Google searches - `universal_survey_search`: Advanced survey search with filters - `vessel_info_search`: Search for vessel information - `mongodb_find`: Direct MongoDB queries ## Project Structure ``` src/ ├── tools/ │ ├── handlers/ │ │ ├── surveyTools.ts # Survey creation and management │ │ ├── fleetSurveyTools.ts # Fleet survey coordination │ │ ├── certificateTools.ts # Certificate tracking and management │ │ ├── classSocietyTools.ts # Class society integration │ │ ├── exportTools.ts # Data export functionality │ │ └── universalTools.ts # Universal search and utility tools │ ├── schema.ts # Tool schema definitions │ └── index.ts # Main tool handler ├── config/ │ └── index.ts # Configuration management ├── types/ │ └── index.ts # TypeScript type definitions ├── prompts/ │ └── index.ts # Prompt management ├── resources/ │ └── index.ts # Resource management └── index.ts # Main application entry point ``` ## Key Features ### Survey Management - Create and manage surveys with custom questions - Collect and analyze survey responses - Track survey completion status - Generate survey reports and analytics ### Fleet Survey Coordination - Coordinate surveys across fleet vessels - Track survey compliance and status - Manage survey schedules and timelines - Export fleet survey data ### Certificate Management - Track vessel certificates and their status - Monitor certificate expiry dates - Manage certificate renewals - Generate certificate compliance reports ### Class Society Integration - Access class society inspection reports - Track survey schedules and requirements - Monitor class condition assessments - Integrate with class society databases ### Search Integration - Full-text search using Typesense - Vector search for semantic matching - Filtering and pagination support ## Error Handling The application implements comprehensive error handling: - Input validation - Database operation error handling - API integration error handling - Proper error logging - User-friendly error messages ## Logging Logging is implemented using Winston that: - Logs to console with timestamps - Includes different log levels (debug, info, error) - Provides detailed error information - Supports structured logging ## Contributing 1. Fork the repository 2. Create your feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add some amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ## License This project is licensed under the MIT License - see the LICENSE file for details.