MCP Tool Manager
by Nagendda
README.md
# MCP Tool Manager
> **A production-hardened, AI-native tool registry and agent management system built on the Model Context Protocol (MCP).**
[](https://nodejs.org)
[](LICENSE)
[](https://modelcontextprotocol.io)
[](mcp-server-project/security/)
---
## ๐ Table of Contents
1. [What Is This?](#what-is-this)
2. [Architecture Overview](#architecture-overview)
3. [Project Structure](#project-structure)
4. [Quick Start](#quick-start)
5. [Configuration Reference](#configuration-reference)
6. [API Reference](#api-reference)
7. [Implementation Plan](#implementation-plan)
8. [Security Model](#security-model)
9. [Monitoring & Observability](#monitoring--observability)
10. [Roadmap](#roadmap)
11. [Contributing](#contributing)
---
## What Is This?
MCP Tool Manager is a **dual-server platform** that solves the hardest operational problems in AI-integrated tool systems:
| Problem | Solution |
|---|---|
| LLMs burning context windows on huge API responses | Per-tool byte budget with graceful truncation signalling |
| Upstream API failures cascading to the LLM | Per-tool circuit breaker (CLOSED โ OPEN โ HALF-OPEN) |
| All data lost on server restart | Automatic periodic disk snapshots, restored on startup |
| Brute force / injection attacks on the API gateway | 10-family threat detector + tiered rate limiting + IP auto-block |
| No way to trace a request end-to-end | X-Trace-ID header propagated across all layers and to upstream APIs |
| Tools/agents registered in volatile memory only | File-persisted call log + agent JSON configs + state snapshots |
---
## Architecture Overview
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MCP Tool Manager Platform โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Manager Server โ โ Hardened MCP Server โ โ
โ โ src/server โ โ mcp-server-project โ โ
โ โ โ โ โ โ
โ โ โข REST API (CRUD) โ โ โข MCP Protocol endpoint โ โ
โ โ โข JWT + API key auth โ โ โข Agent API key auth + expiry โ โ
โ โ โข Tool registry โ โ โข Circuit breaker per tool โ โ
โ โ โข Agent management โ โ โข Retry + exponential backoff โ โ
โ โ โข Credential vault โ โ โข Response cache (TTL per tool) โ โ
โ โ โข Audit log โ โ โข Context window limiting โ โ
โ โ โข State snapshots โ โ โข File-persisted call log โ โ
โ โ โข WebSocket events โ โ โข 10-family threat detection โ โ
โ โ โข Response cache โ โ โข Admin /metrics endpoint โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโโโผโโโโโโโโโโโโ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ React Dashboard โ โ Claude Desktop / LLM Agent โ โ
โ โ src/dashboard โ โ (connects via MCP SDK) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Cross-cutting: X-Trace-ID ยท Rate Limiting ยท Helmet CSP ยท โ โ
โ โ Structured Logging ยท Connection Limit ยท Compression โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
---
## Project Structure
```
mcp/
โโโ .env.example # Template โ copy to .env and fill in values
โโโ .gitignore # Excludes .env, node_modules, logs, snapshots
โโโ package.json # Root scripts โ start both servers, CLI, tests
โโโ README.md # This file
โโโ REPORT.md # Full technical capability report
โโโ CHANGELOG.md # Version history
โ
โโโ src/
โ โโโ server/ # Manager Server (REST API)
โ โ โโโ index.js # Entry point โ snapshot restore + server start
โ โ โโโ app.js # Express app โ all middleware wired
โ โ โโโ routes/
โ โ โ โโโ tools.js # CRUD + test execution for tools
โ โ โ โโโ agents.js # Agent management + tool discovery
โ โ โ โโโ auth.js # Login, register, API key management
โ โ โ โโโ credentials.js # Encrypted credential vault
โ โ โ โโโ monitoring.js # Stats, audit log, cache, snapshot status
โ โ โโโ middleware/
โ โ โ โโโ auth.js # JWT + API key auth + RBAC
โ โ โ โโโ error-handler.js # Typed errors + global handler
โ โ โโโ storage/
โ โ โ โโโ in-memory-store.js # All in-memory Maps + operations
โ โ โ โโโ seeder.js # Initial data (skipped if snapshot exists)
โ โ โ โโโ state-snapshot.js # Periodic disk snapshots (JSON files)
โ โ โโโ utils/
โ โ โ โโโ trace.js # X-Trace-ID middleware
โ โ โ โโโ context-limit.js # Response byte budget + pagination guard
โ โ โ โโโ response-cache.js # node-cache wrapper + TTL presets
โ โ โ โโโ encryption.js # AES-256-CBC for credential vault
โ โ โ โโโ logger.js # Levelled logger (error/warn/info/debug)
โ โ โโโ websocket.js # Real-time events via WebSocket
โ โ
โ โโโ dashboard/ # React + Vite management UI
โ โ โโโ src/
โ โ โ โโโ pages/ # Dashboard, Tools, Agents, Monitoring, Settings
โ โ โ โโโ components/ # Sidebar, Topbar, ToastContainer
โ โ โ โโโ services/api.js # Axios client for Manager Server
โ โ โ โโโ styles/ # global.css, sidebar.css
โ โ โโโ vite.config.js
โ โ
โ โโโ sdk/
โ โ โโโ index.js # Developer SDK โ npm-publishable client
โ โ
โ โโโ cli/
โ โโโ index.js # Admin CLI (17 commands)
โ
โโโ mcp-server-project/ # Hardened MCP Server
โ โโโ package.json
โ โโโ src/
โ โ โโโ server.js # Boot sequence โ all 7 security layers
โ โ โโโ mcp-protocol.js # MCP spec endpoint (/mcp/tools, /mcp/invoke)
โ โ โโโ routes/
โ โ โ โโโ invoke.js # Tool invocation (retry + CB + cache + limit)
โ โ โ โโโ info.js # Tool discovery per agent
โ โ โ โโโ metrics.js # Admin monitoring endpoint
โ โ โโโ middleware/
โ โ โ โโโ auth.js # Agent auth + expiry + scope + disabled check
โ โ โ โโโ trace.js # X-Trace-ID attachment
โ โ โ โโโ context-limit.js # Response byte budget
โ โ โโโ state/
โ โ โ โโโ call-log.js # Disk-persisted call log (NDJSON)
โ โ โ โโโ circuit-breaker.js # Per-tool CLOSED/OPEN/HALF state machine
โ โ โ โโโ response-cache.js # TTL cache with auto-eviction
โ โ โโโ loaders/
โ โ โ โโโ registry.js # Central tool+agent in-memory registry
โ โ โ โโโ tool-loader.js # Loads *.json from /tools/
โ โ โ โโโ agent-loader.js # Loads *.json from /agents/
โ โ โ โโโ credential-loader.js # Merges .env + JSON credentials
โ โ โโโ watcher.js # chokidar hot-reload on /tools/ and /agents/
โ โโโ security/
โ โ โโโ middleware/
โ โ โ โโโ security-headers.js # Strict Helmet CSP + CORS
โ โ โ โโโ rate-limiter.js # 3-tier rate limiting + IP auto-block
โ โ โ โโโ threat-detector.js # 10-family injection/attack detector
โ โ โโโ logger/
โ โ โโโ security-log.js # Structured security event log (5 levels)
โ โโโ tools/ # Tool definition JSON files
โ โโโ agents/ # Agent definition JSON files
โ โโโ credentials/ # .env and JSON secrets (gitignored)
โ โโโ logs/ # Security log + call log (gitignored)
โ โโโ security-tests/ # Attack simulation suite + benchmark
โ
โโโ snapshots/ # Manager server state snapshots (gitignored)
โโโ examples/ # Example tool/agent JSON files
```
---
## Quick Start
### Prerequisites
| Requirement | Version |
|---|---|
| Node.js | โฅ 16.0.0 |
| npm | โฅ 7.0.0 |
| Git | any |
### 1. Clone
```bash
git clone https://github.com/YOUR_USERNAME/mcp-tool-manager.git
cd mcp-tool-manager
```
### 2. Install dependencies
```bash
# Root (Manager Server + CLI + SDK)
npm install
# Dashboard
cd src/dashboard && npm install && cd ../..
# MCP Server
cd mcp-server-project && npm install && cd ..
```
### 3. Configure
```bash
# Manager Server
cp .env.example .env
# Edit .env with your JWT_SECRET, ENCRYPTION_KEY, etc.
# MCP Server
cp mcp-server-project/credentials/.env.example mcp-server-project/credentials/.env
# Edit credentials/.env with your agent keys and tool API keys
```
### 4. Run
```bash
# Terminal 1 โ Manager Server (port 5000)
npm run dev:server
# Terminal 2 โ React Dashboard (port 3000)
npm run dev:dashboard
# Terminal 3 โ MCP Server (port 5001 by default)
cd mcp-server-project && npm start
```
### 5. Access
| Interface | URL |
|---|---|
| Dashboard | http://localhost:3000 |
| Manager API | http://localhost:5000 |
| Manager Health | http://localhost:5000/api/monitoring/health |
| MCP Server | http://localhost:5001 |
| MCP Health | http://localhost:5001/health |
| MCP Metrics | http://localhost:5001/metrics/health |
### Default Login (Manager)
```
Email: admin@mcp-tool-manager.dev
Password: admin123
```
> โ ๏ธ Change this immediately in production via `ADMIN_USERNAME` / `ADMIN_PASSWORD` env vars.
---
## Configuration Reference
### Manager Server (`.env`)
```dotenv
# Core
NODE_ENV=development
MCP_SERVER_PORT=5000
MCP_SERVER_HOST=localhost
LOG_LEVEL=info
# Auth
JWT_SECRET=your-super-secret-key-min-32-chars
JWT_EXPIRY=24h
ENCRYPTION_KEY=your-encryption-key-exactly-32-ch
# Context Window
MCP_MAX_RESPONSE_BYTES=65536 # 64 KB default response budget
MCP_MAX_PAGE_SIZE=100 # Max items per paginated endpoint
# Scalability
MCP_MAX_CONNECTIONS=500 # TCP connection limit
SNAPSHOT_DIR=./snapshots # State persistence directory
SNAPSHOT_INTERVAL_SECS=60 # Save state every 60 seconds
SNAPSHOT_RESTORE=true # Restore state on startup
# Cache TTLs (seconds)
CACHE_TTL_TOOL_LIST=30
CACHE_TTL_TOOL_ITEM=60
CACHE_TTL_AGENT_LIST=30
CACHE_TTL_STATS=10
CACHE_TTL_ACTIVITY=300
# Future (not yet wired โ provide connection string to enable)
DATABASE_URL=postgresql://user:password@localhost:5432/mcp_tools
REDIS_URL=redis://localhost:6379
```
### MCP Server (`mcp-server-project/credentials/.env`)
```dotenv
# Agent API Keys (convention: AGENT_<AGENTID_UPPERCASE>_KEY)
AGENT_MY_AGENT_KEY=your-agent-secret-key
# Tool credentials (referenced by credential_ref in tool JSON)
OPENAI_API_KEY=sk-...
WEATHER_API_KEY=...
SLACK_BOT_TOKEN=xoxb-...
# Admin
ADMIN_KEY=your-admin-key-for-metrics-endpoint
# Server
MCP_PORT=5001
MCP_MAX_CONNECTIONS=200
MCP_MAX_RESPONSE_BYTES=32768 # 32 KB default per tool response
```
### Tool JSON Fields (MCP Server)
```json
{
"name": "my_tool",
"description": "Human-readable description for the LLM",
"endpoint_url": "https://api.example.com/endpoint",
"method": "POST",
"credential_ref": "MY_API_KEY",
"parameters": {
"type": "object",
"properties": {
"query": { "type": "string", "description": "Search query" }
},
"required": ["query"]
},
"cache_ttl_seconds": 60,
"max_response_bytes": 8192,
"retry_max": 3,
"timeout_ms": 10000,
"circuit_failure_threshold": 5,
"circuit_open_window_ms": 30000
}
```
### Agent JSON Fields (MCP Server)
```json
{
"agent_id": "my-agent",
"allowed_tools": ["weather_lookup", "send_email"],
"expires_at": "2027-01-01T00:00:00Z",
"disabled": false
}
```
---
## API Reference
### Manager Server (`http://localhost:5000`)
#### Auth
| Method | Path | Auth | Description |
|---|---|:---:|---|
| POST | `/api/auth/login` | โ | Get JWT token |
| POST | `/api/auth/register` | โ | Create account |
| GET | `/api/auth/me` | โ
| Current user + API keys |
| POST | `/api/auth/api-keys` | โ
| Generate new API key |
| DELETE | `/api/auth/api-keys/:key` | โ
| Revoke API key |
#### Tools
| Method | Path | Auth | Description |
|---|---|:---:|---|
| GET | `/api/tools` | โ
| List tools (paginated) |
| POST | `/api/tools` | โ
| Register new tool |
| GET | `/api/tools/:id` | โ
| Tool details |
| PUT | `/api/tools/:id` | โ
| Update tool |
| DELETE | `/api/tools/:id` | โ
| Remove tool |
| POST | `/api/tools/:id/test` | โ
| Test tool invocation |
#### Agents
| Method | Path | Auth | Description |
|---|---|:---:|---|
| GET | `/api/agents` | โ
| List agents |
| POST | `/api/agents` | โ
| Register agent |
| GET | `/api/agents/:id` | โ
| Agent details |
| PUT | `/api/agents/:id` | โ
| Update agent |
| DELETE | `/api/agents/:id` | โ
| Remove agent |
| POST | `/api/agents/:id/tools` | โ
| Discover tools for agent |
#### Monitoring
| Method | Path | Auth | Description |
|---|---|:---:|---|
| GET | `/api/monitoring/health` | โ | Liveness probe |
| GET | `/api/monitoring/stats` | โ
| Full system stats + cache + snapshot |
| GET | `/api/monitoring/activity` | โ
| Real hourly call timeline (24h) |
| GET | `/api/monitoring/top-tools` | โ
| Top N tools by call count |
| GET | `/api/monitoring/audit-log` | โ
| Audit entries |
| GET | `/api/monitoring/cache` | โ
| Cache hit-rate + entries |
| GET | `/api/monitoring/snapshot` | โ
| Last snapshot timestamp + counts |
### MCP Server (`http://localhost:5001`)
| Method | Path | Auth | Description |
|---|---|:---:|---|
| GET | `/health` | โ | Liveness probe |
| GET | `/info` | AGENT_KEY | List tools for calling agent |
| GET | `/info/all` | ADMIN_KEY | All tools + all agents |
| GET | `/mcp/tools` | โ | Claude Desktop compatible tool list |
| POST | `/mcp/invoke/:tool` | โ | MCP protocol invocation |
| POST | `/invoke/:toolName` | AGENT_KEY | Direct tool invocation |
| GET | `/metrics` | ADMIN_KEY | Full monitoring dashboard |
| GET | `/metrics/health` | โ | Lightweight liveness probe |
| GET | `/metrics/calls` | ADMIN_KEY | Recent call history |
---
## Implementation Plan
This section documents the complete roadmap โ what is built, what is in progress, and what requires infrastructure decisions.
### Phase 1 โ Foundation โ
Complete
- [x] Manager Server REST API (tools, agents, auth, credentials, monitoring)
- [x] In-memory store with full CRUD operations
- [x] JWT + API key dual authentication with RBAC
- [x] AES-256-CBC credential vault
- [x] React dashboard (Tools, Agents, Monitoring, Settings pages)
- [x] WebSocket real-time event broadcasting
- [x] Developer SDK (`src/sdk/index.js`)
- [x] Admin CLI with 17 commands (`src/cli/index.js`)
- [x] MCP Protocol endpoint (Claude Desktop compatible)
- [x] File-based tool/agent registry with hot-reload (`chokidar`)
- [x] Audit log with rolling ring buffer
### Phase 2 โ Security Hardening โ
Complete
- [x] 10-family threat detector (SQL/NoSQL/XSS/SSRF/Shell/Template/Path/CMDi/Null/Header injection)
- [x] Scanner user-agent blocking (sqlmap, nikto, nmap, Burp Suite, 20+ scanners)
- [x] 3-tier rate limiting (global + strict + speed slow-down)
- [x] Auto IP block after brute force (20+ hits)
- [x] Structured security event log with 5 severity levels
- [x] Helmet strict CSP (`defaultSrc: 'none'`)
- [x] Agent key expiry + disabled flag
- [x] Scope enforcement (`requireScope` middleware)
- [x] Auth failure + scope violation security logging
- [x] Security test suite + benchmark (compare hardened vs. unprotected)
### Phase 3 โ Operational Capabilities โ
Complete (This Release)
- [x] **X-Trace-ID** โ unique request correlator, propagated through all layers and upstream APIs
- [x] **Circuit Breaker** โ CLOSED/OPEN/HALF-OPEN per tool (configurable thresholds)
- [x] **Retry with exponential backoff** โ 200ms โ 400ms โ 800ms, skips 4xx errors
- [x] **Response cache** โ TTL per tool/data-type, hit-rate tracking, prefix invalidation
- [x] **Context window limiting** โ per-tool byte budget, graceful truncation with signalling
- [x] **Pagination guard** โ global `?limit` clamp (default max 100 items)
- [x] **State snapshots** โ atomic periodic writes, restored on startup (tools/agents/users survive restart)
- [x] **Connection limit guard** โ drops TCP sockets over configurable max
- [x] **Rate limiting activated** (Manager) โ 300 global + 15 auth per minute per IP
- [x] **Real monitoring** โ activity timeline from actual call data (removed Math.random() mock)
- [x] **`/metrics` endpoint** (MCP) โ full admin dashboard (calls, cache, circuit breakers, memory)
- [x] **node-cache activated** (Manager) โ TTL presets per data type, hit-rate tracking
- [x] **`/api/monitoring/cache`** and **`/api/monitoring/snapshot`** new endpoints
### Phase 4 โ Persistence & Distribution ๐ฒ Pending Your Input
> These require infrastructure. `pg` and `ioredis` are already installed โ only connection strings needed.
- [ ] **PostgreSQL** โ migrate `in-memory-store.js` to persistent database
- `tools`, `agents`, `users`, `api_keys`, `credentials`, `audit_log` tables
- Connection pool via `pg` (`DATABASE_URL` already in `.env.example`)
- [ ] **Redis** โ shared rate limit + session + response cache store
- Replace node-cache with ioredis for multi-instance safety
- Shared IP block list across all server instances
- (`REDIS_URL` already in `.env.example`)
- [ ] **Horizontal scaling** โ once Redis + Postgres are wired, deploy N instances behind nginx
### Phase 5 โ Developer Experience ๐ฒ Optional
- [ ] OpenAPI/Swagger spec auto-generation (`swagger-jsdoc`)
- [ ] `zod` env schema validation at startup (fail-fast on missing config)
- [ ] JWT refresh tokens + blacklist
- [ ] Prometheus metrics export (`/metrics/prometheus` endpoint)
- [ ] OpenTelemetry distributed tracing
- [ ] Tool compatibility matrix
- [ ] WebSocket dashboard for real-time circuit breaker state
---
## Security Model
### Manager Server
```
Request
โ
โโโ X-Trace-ID attachment (Layer 0)
โโโ Helmet strict CSP (Layer 1)
โโโ Global rate limit 300/min (Layer 2a)
โโโ Auth rate limit 15/min on /api/auth (Layer 2b)
โโโ Body size limit 2 MB (Layer 3)
โโโ Context window budget (Layer 4)
โโโ Pagination guard max 100 items (Layer 5)
โโโ JWT / API key verification (per-route)
โโโ RBAC role check (per-route)
```
### MCP Server
```
Request
โ
โโโ X-Trace-ID attachment (Layer 0)
โโโ Strict Helmet CSP (Layer 1)
โโโ IP block list check (Layer 2)
โโโ Body size guard (Layer 3)
โโโ Context window budget (Layer 4)
โโโ HTTP method whitelist (Layer 5)
โโโ Scanner user-agent block (Layer 6)
โโโ Global rate limit + speed slow-down (Layer 7)
โโโ 10-family threat detection (Layer 8)
โโโ Agent API key auth + expiry + disabled check (per-route)
โโโ Tool scope enforcement (per-route)
โโโ Circuit breaker check (per-tool)
โโโ Response cache lookup (per-tool)
โโโ Retry + context limit on upstream call (per-tool)
```
---
## Monitoring & Observability
### Available Data
| Source | What it shows |
|---|---|
| `GET /api/monitoring/stats` | System overview, cache stats, snapshot info, context limit config |
| `GET /api/monitoring/activity` | Real 24h hourly call timeline (success + error counts) |
| `GET /api/monitoring/top-tools` | Top tools by call count + success rate |
| `GET /api/monitoring/audit-log` | All admin actions (tool create/delete, agent add/remove) |
| `GET /api/monitoring/cache` | Cache hit-rate, entry count, evictions |
| `GET /api/monitoring/snapshot` | Last snapshot timestamp + record counts |
| `GET /metrics` (MCP, admin) | Circuit breaker states, call log, cache stats, system memory |
| `GET /metrics/health` (MCP, public) | Uptime + memory (lightweight probe) |
| `logs/calls.ndjson` (MCP) | Full call history: trace ID, agent, tool, latency, success, retries |
| `logs/security.log` (MCP) | All security events: AUTH failures, threats, rate limits, circuit trips |
| `snapshots/meta.json` (Manager) | Last snapshot: timestamp + counts for all data types |
### X-Trace-ID Flow
```
Client โ [generates or passes X-Trace-ID]
โ Manager/MCP Server [attaches to req.traceId, echoes in X-Trace-ID response header]
โ Security log entries [include traceId]
โ Call log entries [include traceId]
โ Upstream API call [X-Trace-ID forwarded in headers]
โ Response [traceId in JSON body]
```
---
## Roadmap
### v2.1 (Next)
- Wire PostgreSQL for persistent storage
- Wire Redis for distributed rate limiting + cache
- `zod` env schema validation at startup
### v2.2
- JWT refresh token + blacklist
- Prometheus metrics export
- Per-API-key rate limiting (not IP-based)
### v3.0
- Full OpenAPI spec
- OpenTelemetry distributed tracing
- OAuth2/OIDC federated agent identity
---
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for branch strategy, PR process, and code style guide.
---
## License
MIT ยฉ MCP Tool Manager Team
---
*See [REPORT.md](REPORT.md) for the full technical capability assessment.*
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues