Dms
Dynamic MCP Server
Installation
npx dmsAsk AI about Dms
Powered by Claude Β· Grounded in docs
I know everything about Dms. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
Dynamic MCP Server
A dynamic Model Context Protocol (MCP) server implementation in Go that reads tool configurations from JSON files and provides both WebSocket and HTTP interfaces for tool execution.
Features
- Dynamic Tool Loading: Load tool configurations from JSON files at runtime
- Session Management: Automatic session creation, refresh, and cleanup
- Authentication: Support for session tokens and API keys
- WebSocket Support: Full MCP protocol implementation over WebSocket
- HTTP API: RESTful endpoints for tool listing and execution
- Redis Integration: Session storage and management
- Graceful Shutdown: Proper cleanup of resources and connections
Project Structure
.
βββ cmd/
β βββ mcp-server/
β βββ main.go # Main entry point
βββ internal/
β βββ auth/
β β βββ client.go # Authentication client
β β βββ errors.go # Authentication errors
β β βββ manager.go # Session manager
β βββ config/
β β βββ loader.go # Configuration loader
β β βββ types.go # Configuration types
β βββ server/
β βββ executor.go # API execution logic
β βββ server.go # Core MCP server
β βββ types.go # Server types
βββ go.mod # Go module file
βββ go.sum # Go dependencies
βββ config.json # Clean configuration file
βββ mcp_tool.json # Original file with examples (can be removed)
βββ README.md # This file
Configuration
The server reads tool configurations from JSON files. The main configuration file is config.json which contains:
- Session Management: Authentication service configuration
- Tool Definitions: API endpoints, parameters, and authentication requirements
- Server Settings: Port, timeouts, and other server options
Configuration Structure
{
"session_management": {
"auth_service_url": "https://api.yourstore.com/v1/auth",
"session_endpoint": "/session",
"refresh_endpoint": "/refresh",
"validate_endpoint": "/validate",
"logout_endpoint": "/logout"
},
"mcp_server_session_config": {
"settings": {
"session_cache_type": "memory",
"session_cache_ttl": 3600,
"refresh_before_expiry_seconds": 300,
"cleanup_interval_seconds": 60,
"max_sessions_per_apikey": 5
}
},
"tools": {}
}
Adding Tools
To add tools, update the tools section in your configuration file:
{
"tools": {
"product_search": {
"config": {
"name": "product_search",
"description": "Search for products in the catalog",
"method": "GET",
"url": "https://api.example.com/products/search",
"auth_required": true,
"auth_type": "session_token",
"timeout": 30
},
"params_schema": {
"query": {
"type": "string",
"description": "Search query",
"required": true
},
"category": {
"type": "string",
"description": "Product category filter"
}
}
}
}
}
Installation
- Clone the repository:
git clone <repository-url>
cd dms
- Install dependencies:
go mod tidy
- Set up Redis (required for session management):
# Using Docker
docker run -d -p 6379:6379 redis:alpine
# Or install locally
brew install redis # macOS
sudo apt-get install redis-server # Ubuntu
Usage
Running the Server
# Run with default configuration (config.json)
go run cmd/mcp-server/main.go
# Run with custom configuration file
go run cmd/mcp-server/main.go -config /path/to/config.json
Environment Variables
MCP_CONFIG_FILE: Path to configuration file (default:./config.json)MCP_PORT: Server port (default:8080)REDIS_URL: Redis connection URL (default:redis://localhost:6379)
WebSocket Connection
Connect to the MCP server via WebSocket:
ws://localhost:8080/mcp
The server implements the full MCP protocol for tool discovery and execution.
HTTP API
List Available Tools
curl http://localhost:8080/tools
Execute a Tool
curl -X POST http://localhost:8080/tools/product_search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <session_token>" \
-d '{"query": "laptop", "category": "electronics"}'
Development
Building
# Build for current platform
go build -o bin/mcp-server cmd/mcp-server/main.go
# Build for Linux
GOOS=linux GOARCH=amd64 go build -o bin/mcp-server-linux cmd/mcp-server/main.go
Testing
# Run tests
go test ./...
# Run tests with coverage
go test -cover ./...
Adding New Tools
- Add tool configuration to your JSON file:
{
"tools": {
"new_tool": {
"config": {
"name": "new_tool",
"description": "Description of the new tool",
"method": "POST",
"url": "https://api.example.com/new-endpoint",
"auth_required": true,
"timeout": 30
},
"params_schema": {
"param1": {
"type": "string",
"description": "Parameter description",
"required": true
}
}
}
}
}
- Restart the server to load the new configuration
Authentication
The server supports multiple authentication methods:
- Session Token: Bearer token authentication
- API Key: X-API-Key header authentication
Sessions are automatically managed with refresh and cleanup capabilities.
Logging
The server uses structured logging with different levels:
INFO: General informationWARN: Warning messagesERROR: Error conditionsDEBUG: Debug information (when enabled)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
