@sparkleideas/mcp 3.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/analysis/analyze-code-quality.md +179 -0
- package/.claude/agents/analysis/code-analyzer.md +210 -0
- package/.claude/agents/analysis/code-review/analyze-code-quality.md +179 -0
- package/.claude/agents/architecture/arch-system-design.md +157 -0
- package/.claude/agents/architecture/system-design/arch-system-design.md +155 -0
- package/.claude/agents/consensus/byzantine-coordinator.md +63 -0
- package/.claude/agents/consensus/crdt-synchronizer.md +997 -0
- package/.claude/agents/consensus/gossip-coordinator.md +63 -0
- package/.claude/agents/consensus/performance-benchmarker.md +851 -0
- package/.claude/agents/consensus/quorum-manager.md +823 -0
- package/.claude/agents/consensus/raft-manager.md +63 -0
- package/.claude/agents/consensus/security-manager.md +622 -0
- package/.claude/agents/core/coder.md +453 -0
- package/.claude/agents/core/planner.md +375 -0
- package/.claude/agents/core/researcher.md +369 -0
- package/.claude/agents/core/reviewer.md +520 -0
- package/.claude/agents/core/tester.md +512 -0
- package/.claude/agents/custom/test-long-runner.md +44 -0
- package/.claude/agents/data/data-ml-model.md +445 -0
- package/.claude/agents/data/ml/data-ml-model.md +193 -0
- package/.claude/agents/development/backend/dev-backend-api.md +142 -0
- package/.claude/agents/development/dev-backend-api.md +345 -0
- package/.claude/agents/devops/ci-cd/ops-cicd-github.md +164 -0
- package/.claude/agents/devops/ops-cicd-github.md +165 -0
- package/.claude/agents/documentation/api-docs/docs-api-openapi.md +174 -0
- package/.claude/agents/documentation/docs-api-openapi.md +355 -0
- package/.claude/agents/flow-nexus/app-store.md +88 -0
- package/.claude/agents/flow-nexus/authentication.md +69 -0
- package/.claude/agents/flow-nexus/challenges.md +81 -0
- package/.claude/agents/flow-nexus/neural-network.md +88 -0
- package/.claude/agents/flow-nexus/payments.md +83 -0
- package/.claude/agents/flow-nexus/sandbox.md +76 -0
- package/.claude/agents/flow-nexus/swarm.md +76 -0
- package/.claude/agents/flow-nexus/user-tools.md +96 -0
- package/.claude/agents/flow-nexus/workflow.md +84 -0
- package/.claude/agents/github/code-review-swarm.md +377 -0
- package/.claude/agents/github/github-modes.md +173 -0
- package/.claude/agents/github/issue-tracker.md +576 -0
- package/.claude/agents/github/multi-repo-swarm.md +553 -0
- package/.claude/agents/github/pr-manager.md +438 -0
- package/.claude/agents/github/project-board-sync.md +509 -0
- package/.claude/agents/github/release-manager.md +605 -0
- package/.claude/agents/github/release-swarm.md +583 -0
- package/.claude/agents/github/repo-architect.md +398 -0
- package/.claude/agents/github/swarm-issue.md +573 -0
- package/.claude/agents/github/swarm-pr.md +428 -0
- package/.claude/agents/github/sync-coordinator.md +452 -0
- package/.claude/agents/github/workflow-automation.md +903 -0
- package/.claude/agents/goal/agent.md +816 -0
- package/.claude/agents/goal/goal-planner.md +73 -0
- package/.claude/agents/optimization/benchmark-suite.md +665 -0
- package/.claude/agents/optimization/load-balancer.md +431 -0
- package/.claude/agents/optimization/performance-monitor.md +672 -0
- package/.claude/agents/optimization/resource-allocator.md +674 -0
- package/.claude/agents/optimization/topology-optimizer.md +808 -0
- package/.claude/agents/payments/agentic-payments.md +126 -0
- package/.claude/agents/sona/sona-learning-optimizer.md +74 -0
- package/.claude/agents/sparc/architecture.md +699 -0
- package/.claude/agents/sparc/pseudocode.md +520 -0
- package/.claude/agents/sparc/refinement.md +802 -0
- package/.claude/agents/sparc/specification.md +478 -0
- package/.claude/agents/specialized/mobile/spec-mobile-react-native.md +225 -0
- package/.claude/agents/specialized/spec-mobile-react-native.md +227 -0
- package/.claude/agents/sublinear/consensus-coordinator.md +338 -0
- package/.claude/agents/sublinear/matrix-optimizer.md +185 -0
- package/.claude/agents/sublinear/pagerank-analyzer.md +299 -0
- package/.claude/agents/sublinear/performance-optimizer.md +368 -0
- package/.claude/agents/sublinear/trading-predictor.md +246 -0
- package/.claude/agents/swarm/adaptive-coordinator.md +1127 -0
- package/.claude/agents/swarm/hierarchical-coordinator.md +710 -0
- package/.claude/agents/swarm/mesh-coordinator.md +963 -0
- package/.claude/agents/templates/automation-smart-agent.md +205 -0
- package/.claude/agents/templates/base-template-generator.md +268 -0
- package/.claude/agents/templates/coordinator-swarm-init.md +90 -0
- package/.claude/agents/templates/github-pr-manager.md +177 -0
- package/.claude/agents/templates/implementer-sparc-coder.md +259 -0
- package/.claude/agents/templates/memory-coordinator.md +187 -0
- package/.claude/agents/templates/orchestrator-task.md +139 -0
- package/.claude/agents/templates/performance-analyzer.md +199 -0
- package/.claude/agents/templates/sparc-coordinator.md +514 -0
- package/.claude/agents/testing/production-validator.md +395 -0
- package/.claude/agents/testing/tdd-london-swarm.md +244 -0
- package/.claude/agents/v3/adr-architect.md +184 -0
- package/.claude/agents/v3/aidefence-guardian.md +282 -0
- package/.claude/agents/v3/claims-authorizer.md +208 -0
- package/.claude/agents/v3/collective-intelligence-coordinator.md +993 -0
- package/.claude/agents/v3/ddd-domain-expert.md +220 -0
- package/.claude/agents/v3/injection-analyst.md +236 -0
- package/.claude/agents/v3/memory-specialist.md +995 -0
- package/.claude/agents/v3/performance-engineer.md +1233 -0
- package/.claude/agents/v3/pii-detector.md +151 -0
- package/.claude/agents/v3/reasoningbank-learner.md +213 -0
- package/.claude/agents/v3/security-architect-aidefence.md +410 -0
- package/.claude/agents/v3/security-architect.md +867 -0
- package/.claude/agents/v3/security-auditor.md +771 -0
- package/.claude/agents/v3/sparc-orchestrator.md +182 -0
- package/.claude/agents/v3/swarm-memory-manager.md +157 -0
- package/.claude/agents/v3/v3-integration-architect.md +205 -0
- package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +54 -0
- package/.claude/commands/analysis/README.md +9 -0
- package/.claude/commands/analysis/bottleneck-detect.md +162 -0
- package/.claude/commands/analysis/performance-bottlenecks.md +59 -0
- package/.claude/commands/analysis/performance-report.md +25 -0
- package/.claude/commands/analysis/token-efficiency.md +45 -0
- package/.claude/commands/analysis/token-usage.md +25 -0
- package/.claude/commands/automation/README.md +9 -0
- package/.claude/commands/automation/auto-agent.md +122 -0
- package/.claude/commands/automation/self-healing.md +106 -0
- package/.claude/commands/automation/session-memory.md +90 -0
- package/.claude/commands/automation/smart-agents.md +73 -0
- package/.claude/commands/automation/smart-spawn.md +25 -0
- package/.claude/commands/automation/workflow-select.md +25 -0
- package/.claude/commands/claude-flow-help.md +103 -0
- package/.claude/commands/claude-flow-memory.md +107 -0
- package/.claude/commands/claude-flow-swarm.md +205 -0
- package/.claude/commands/github/README.md +11 -0
- package/.claude/commands/github/code-review-swarm.md +514 -0
- package/.claude/commands/github/code-review.md +25 -0
- package/.claude/commands/github/github-modes.md +147 -0
- package/.claude/commands/github/github-swarm.md +121 -0
- package/.claude/commands/github/issue-tracker.md +292 -0
- package/.claude/commands/github/issue-triage.md +25 -0
- package/.claude/commands/github/multi-repo-swarm.md +519 -0
- package/.claude/commands/github/pr-enhance.md +26 -0
- package/.claude/commands/github/pr-manager.md +170 -0
- package/.claude/commands/github/project-board-sync.md +471 -0
- package/.claude/commands/github/release-manager.md +338 -0
- package/.claude/commands/github/release-swarm.md +544 -0
- package/.claude/commands/github/repo-analyze.md +25 -0
- package/.claude/commands/github/repo-architect.md +367 -0
- package/.claude/commands/github/swarm-issue.md +482 -0
- package/.claude/commands/github/swarm-pr.md +285 -0
- package/.claude/commands/github/sync-coordinator.md +301 -0
- package/.claude/commands/github/workflow-automation.md +442 -0
- package/.claude/commands/hooks/README.md +11 -0
- package/.claude/commands/hooks/overview.md +58 -0
- package/.claude/commands/hooks/post-edit.md +117 -0
- package/.claude/commands/hooks/post-task.md +112 -0
- package/.claude/commands/hooks/pre-edit.md +113 -0
- package/.claude/commands/hooks/pre-task.md +111 -0
- package/.claude/commands/hooks/session-end.md +118 -0
- package/.claude/commands/hooks/setup.md +103 -0
- package/.claude/commands/monitoring/README.md +9 -0
- package/.claude/commands/monitoring/agent-metrics.md +25 -0
- package/.claude/commands/monitoring/agents.md +44 -0
- package/.claude/commands/monitoring/real-time-view.md +25 -0
- package/.claude/commands/monitoring/status.md +46 -0
- package/.claude/commands/monitoring/swarm-monitor.md +25 -0
- package/.claude/commands/optimization/README.md +9 -0
- package/.claude/commands/optimization/auto-topology.md +62 -0
- package/.claude/commands/optimization/cache-manage.md +25 -0
- package/.claude/commands/optimization/parallel-execute.md +25 -0
- package/.claude/commands/optimization/parallel-execution.md +50 -0
- package/.claude/commands/optimization/topology-optimize.md +25 -0
- package/.claude/commands/sparc/analyzer.md +52 -0
- package/.claude/commands/sparc/architect.md +53 -0
- package/.claude/commands/sparc/ask.md +97 -0
- package/.claude/commands/sparc/batch-executor.md +54 -0
- package/.claude/commands/sparc/code.md +89 -0
- package/.claude/commands/sparc/coder.md +54 -0
- package/.claude/commands/sparc/debug.md +83 -0
- package/.claude/commands/sparc/debugger.md +54 -0
- package/.claude/commands/sparc/designer.md +53 -0
- package/.claude/commands/sparc/devops.md +109 -0
- package/.claude/commands/sparc/docs-writer.md +80 -0
- package/.claude/commands/sparc/documenter.md +54 -0
- package/.claude/commands/sparc/innovator.md +54 -0
- package/.claude/commands/sparc/integration.md +83 -0
- package/.claude/commands/sparc/mcp.md +117 -0
- package/.claude/commands/sparc/memory-manager.md +54 -0
- package/.claude/commands/sparc/optimizer.md +54 -0
- package/.claude/commands/sparc/orchestrator.md +132 -0
- package/.claude/commands/sparc/post-deployment-monitoring-mode.md +83 -0
- package/.claude/commands/sparc/refinement-optimization-mode.md +83 -0
- package/.claude/commands/sparc/researcher.md +54 -0
- package/.claude/commands/sparc/reviewer.md +54 -0
- package/.claude/commands/sparc/security-review.md +80 -0
- package/.claude/commands/sparc/sparc-modes.md +174 -0
- package/.claude/commands/sparc/sparc.md +111 -0
- package/.claude/commands/sparc/spec-pseudocode.md +80 -0
- package/.claude/commands/sparc/supabase-admin.md +348 -0
- package/.claude/commands/sparc/swarm-coordinator.md +54 -0
- package/.claude/commands/sparc/tdd.md +54 -0
- package/.claude/commands/sparc/tester.md +54 -0
- package/.claude/commands/sparc/tutorial.md +79 -0
- package/.claude/commands/sparc/workflow-manager.md +54 -0
- package/.claude/helpers/README.md +97 -0
- package/.claude/helpers/adr-compliance.sh +186 -0
- package/.claude/helpers/auto-commit.sh +178 -0
- package/.claude/helpers/checkpoint-manager.sh +251 -0
- package/.claude/helpers/daemon-manager.sh +252 -0
- package/.claude/helpers/ddd-tracker.sh +144 -0
- package/.claude/helpers/github-safe.js +106 -0
- package/.claude/helpers/github-setup.sh +28 -0
- package/.claude/helpers/guidance-hook.sh +13 -0
- package/.claude/helpers/guidance-hooks.sh +102 -0
- package/.claude/helpers/health-monitor.sh +108 -0
- package/.claude/helpers/learning-hooks.sh +329 -0
- package/.claude/helpers/learning-optimizer.sh +127 -0
- package/.claude/helpers/learning-service.mjs +1144 -0
- package/.claude/helpers/memory.js +83 -0
- package/.claude/helpers/metrics-db.mjs +488 -0
- package/.claude/helpers/pattern-consolidator.sh +86 -0
- package/.claude/helpers/perf-worker.sh +160 -0
- package/.claude/helpers/post-commit +16 -0
- package/.claude/helpers/pre-commit +26 -0
- package/.claude/helpers/quick-start.sh +19 -0
- package/.claude/helpers/router.js +66 -0
- package/.claude/helpers/security-scanner.sh +127 -0
- package/.claude/helpers/session.js +127 -0
- package/.claude/helpers/setup-mcp.sh +18 -0
- package/.claude/helpers/standard-checkpoint-hooks.sh +189 -0
- package/.claude/helpers/statusline-hook.sh +21 -0
- package/.claude/helpers/statusline.cjs +509 -0
- package/.claude/helpers/statusline.js +316 -0
- package/.claude/helpers/swarm-comms.sh +353 -0
- package/.claude/helpers/swarm-hooks.sh +761 -0
- package/.claude/helpers/swarm-monitor.sh +211 -0
- package/.claude/helpers/sync-v3-metrics.sh +245 -0
- package/.claude/helpers/update-v3-progress.sh +166 -0
- package/.claude/helpers/v3-quick-status.sh +58 -0
- package/.claude/helpers/v3.sh +111 -0
- package/.claude/helpers/validate-v3-config.sh +216 -0
- package/.claude/helpers/worker-manager.sh +170 -0
- package/.claude/settings.json +237 -0
- package/.claude/skills/agentdb-advanced/SKILL.md +550 -0
- package/.claude/skills/agentdb-learning/SKILL.md +545 -0
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +339 -0
- package/.claude/skills/agentdb-optimization/SKILL.md +509 -0
- package/.claude/skills/agentdb-vector-search/SKILL.md +339 -0
- package/.claude/skills/github-code-review/SKILL.md +1140 -0
- package/.claude/skills/github-multi-repo/SKILL.md +874 -0
- package/.claude/skills/github-project-management/SKILL.md +1277 -0
- package/.claude/skills/github-release-management/SKILL.md +1081 -0
- package/.claude/skills/github-workflow-automation/SKILL.md +1065 -0
- package/.claude/skills/hooks-automation/SKILL.md +1201 -0
- package/.claude/skills/pair-programming/SKILL.md +1202 -0
- package/.claude/skills/reasoningbank-agentdb/SKILL.md +446 -0
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/skill-builder/SKILL.md +910 -0
- package/.claude/skills/sparc-methodology/SKILL.md +1115 -0
- package/.claude/skills/stream-chain/SKILL.md +563 -0
- package/.claude/skills/swarm-advanced/SKILL.md +973 -0
- package/.claude/skills/swarm-orchestration/SKILL.md +179 -0
- package/.claude/skills/v3-cli-modernization/SKILL.md +872 -0
- package/.claude/skills/v3-core-implementation/SKILL.md +797 -0
- package/.claude/skills/v3-ddd-architecture/SKILL.md +442 -0
- package/.claude/skills/v3-integration-deep/SKILL.md +241 -0
- package/.claude/skills/v3-mcp-optimization/SKILL.md +777 -0
- package/.claude/skills/v3-memory-unification/SKILL.md +174 -0
- package/.claude/skills/v3-performance-optimization/SKILL.md +390 -0
- package/.claude/skills/v3-security-overhaul/SKILL.md +82 -0
- package/.claude/skills/v3-swarm-coordination/SKILL.md +340 -0
- package/.claude/skills/verification-quality/SKILL.md +649 -0
- package/CLAUDE.md +711 -0
- package/README.md +428 -0
- package/__tests__/integration.test.ts +449 -0
- package/__tests__/mcp.test.ts +641 -0
- package/package.json +44 -0
- package/src/connection-pool.ts +344 -0
- package/src/index.ts +253 -0
- package/src/oauth.ts +447 -0
- package/src/prompt-registry.ts +296 -0
- package/src/rate-limiter.ts +266 -0
- package/src/resource-registry.ts +530 -0
- package/src/sampling.ts +363 -0
- package/src/schema-validator.ts +213 -0
- package/src/server.ts +1134 -0
- package/src/session-manager.ts +339 -0
- package/src/task-manager.ts +427 -0
- package/src/tool-registry.ts +475 -0
- package/src/transport/http.ts +532 -0
- package/src/transport/index.ts +233 -0
- package/src/transport/stdio.ts +252 -0
- package/src/transport/websocket.ts +396 -0
- package/src/types.ts +664 -0
- package/tmp.json +0 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +13 -0
package/README.md
ADDED
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
# @claude-flow/mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@claude-flow/mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
[](https://modelcontextprotocol.io)
|
|
7
|
+
[](https://github.com/ruvnet/claude-flow)
|
|
8
|
+
|
|
9
|
+
> **MCP 2025-11-25 Compliant** - Standalone Model Context Protocol server implementation with full Resources, Prompts, and Tasks support
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **MCP 2025-11-25 Compliant** - Full specification support
|
|
14
|
+
- **High-Performance Server** - <400ms startup time
|
|
15
|
+
- **Multiple Transports** - stdio, HTTP, WebSocket, in-process
|
|
16
|
+
- **Resources** - list, read, subscribe with caching
|
|
17
|
+
- **Prompts** - templates with arguments and embedded resources
|
|
18
|
+
- **Tasks** - Async operations with progress and cancellation
|
|
19
|
+
- **Pagination** - Cursor-based pagination for large datasets
|
|
20
|
+
- **Connection Pooling** - Max 10 connections, configurable
|
|
21
|
+
- **Fast Tool Registry** - O(1) lookup, <10ms registration
|
|
22
|
+
- **Session Management** - Timeout handling, authentication
|
|
23
|
+
- **Security** - CORS, Helmet, auth tokens
|
|
24
|
+
- **Zero Dependencies** - No @claude-flow/* dependencies
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @claude-flow/mcp
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Quick Start
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { quickStart, defineTool } from '@claude-flow/mcp';
|
|
36
|
+
|
|
37
|
+
// Create and start server
|
|
38
|
+
const server = await quickStart({
|
|
39
|
+
transport: 'stdio',
|
|
40
|
+
name: 'My MCP Server',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Register custom tools
|
|
44
|
+
server.registerTool(defineTool(
|
|
45
|
+
'greet',
|
|
46
|
+
'Greet a user',
|
|
47
|
+
{
|
|
48
|
+
type: 'object',
|
|
49
|
+
properties: {
|
|
50
|
+
name: { type: 'string', description: 'User name' }
|
|
51
|
+
},
|
|
52
|
+
required: ['name']
|
|
53
|
+
},
|
|
54
|
+
async ({ name }) => ({ message: `Hello, ${name}!` })
|
|
55
|
+
));
|
|
56
|
+
|
|
57
|
+
// Start listening
|
|
58
|
+
await server.start();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Transports
|
|
62
|
+
|
|
63
|
+
### Stdio (Default)
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { createMCPServer } from '@claude-flow/mcp';
|
|
67
|
+
|
|
68
|
+
const server = createMCPServer({
|
|
69
|
+
transport: 'stdio',
|
|
70
|
+
name: 'Stdio Server',
|
|
71
|
+
}, logger);
|
|
72
|
+
|
|
73
|
+
await server.start();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### HTTP
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const server = createMCPServer({
|
|
80
|
+
transport: 'http',
|
|
81
|
+
host: 'localhost',
|
|
82
|
+
port: 3000,
|
|
83
|
+
corsEnabled: true,
|
|
84
|
+
corsOrigins: ['http://localhost:8080'],
|
|
85
|
+
auth: {
|
|
86
|
+
enabled: true,
|
|
87
|
+
method: 'token',
|
|
88
|
+
tokens: ['secret-token'],
|
|
89
|
+
},
|
|
90
|
+
}, logger);
|
|
91
|
+
|
|
92
|
+
await server.start();
|
|
93
|
+
// Server at http://localhost:3000
|
|
94
|
+
// WebSocket at ws://localhost:3000/ws
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### WebSocket
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const server = createMCPServer({
|
|
101
|
+
transport: 'websocket',
|
|
102
|
+
host: 'localhost',
|
|
103
|
+
port: 3001,
|
|
104
|
+
maxConnections: 100,
|
|
105
|
+
heartbeatInterval: 30000,
|
|
106
|
+
}, logger);
|
|
107
|
+
|
|
108
|
+
await server.start();
|
|
109
|
+
// WebSocket at ws://localhost:3001/ws
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Tool Registry
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
import { createToolRegistry, defineTool } from '@claude-flow/mcp';
|
|
116
|
+
|
|
117
|
+
const registry = createToolRegistry(logger);
|
|
118
|
+
|
|
119
|
+
// Register tool
|
|
120
|
+
registry.register({
|
|
121
|
+
name: 'calculate',
|
|
122
|
+
description: 'Perform calculations',
|
|
123
|
+
inputSchema: {
|
|
124
|
+
type: 'object',
|
|
125
|
+
properties: {
|
|
126
|
+
expression: { type: 'string' }
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
handler: async ({ expression }) => {
|
|
130
|
+
return { result: eval(expression) };
|
|
131
|
+
},
|
|
132
|
+
category: 'math',
|
|
133
|
+
tags: ['calculator'],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Execute tool
|
|
137
|
+
const result = await registry.execute('calculate', { expression: '2 + 2' });
|
|
138
|
+
|
|
139
|
+
// Search tools
|
|
140
|
+
const mathTools = registry.getByCategory('math');
|
|
141
|
+
const stats = registry.getStats();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Session Management
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import { createSessionManager } from '@claude-flow/mcp';
|
|
148
|
+
|
|
149
|
+
const sessions = createSessionManager(logger, {
|
|
150
|
+
maxSessions: 100,
|
|
151
|
+
sessionTimeout: 30 * 60 * 1000, // 30 minutes
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Create session
|
|
155
|
+
const session = sessions.createSession('http');
|
|
156
|
+
|
|
157
|
+
// Initialize with client info
|
|
158
|
+
sessions.initializeSession(session.id, {
|
|
159
|
+
protocolVersion: { major: 2024, minor: 11, patch: 5 },
|
|
160
|
+
capabilities: { tools: { listChanged: true } },
|
|
161
|
+
clientInfo: { name: 'Claude', version: '1.0' },
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Get metrics
|
|
165
|
+
const metrics = sessions.getSessionMetrics();
|
|
166
|
+
// { total: 1, active: 1, authenticated: 0, expired: 0 }
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Connection Pool
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { createConnectionPool } from '@claude-flow/mcp';
|
|
173
|
+
|
|
174
|
+
const pool = createConnectionPool({
|
|
175
|
+
maxConnections: 10,
|
|
176
|
+
minConnections: 2,
|
|
177
|
+
idleTimeout: 30000,
|
|
178
|
+
acquireTimeout: 5000,
|
|
179
|
+
}, logger, 'http');
|
|
180
|
+
|
|
181
|
+
// Acquire connection
|
|
182
|
+
const conn = await pool.acquire();
|
|
183
|
+
|
|
184
|
+
// Use connection...
|
|
185
|
+
|
|
186
|
+
// Release back to pool
|
|
187
|
+
pool.release(conn);
|
|
188
|
+
|
|
189
|
+
// Get stats
|
|
190
|
+
const stats = pool.getStats();
|
|
191
|
+
// { totalConnections: 5, idleConnections: 4, busyConnections: 1, ... }
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## API Reference
|
|
195
|
+
|
|
196
|
+
### Server
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface IMCPServer {
|
|
200
|
+
start(): Promise<void>;
|
|
201
|
+
stop(): Promise<void>;
|
|
202
|
+
registerTool(tool: MCPTool): boolean;
|
|
203
|
+
registerTools(tools: MCPTool[]): { registered: number; failed: string[] };
|
|
204
|
+
getHealthStatus(): Promise<{ healthy: boolean; error?: string; metrics?: Record<string, number> }>;
|
|
205
|
+
getMetrics(): MCPServerMetrics;
|
|
206
|
+
getSessions(): MCPSession[];
|
|
207
|
+
getSession(sessionId: string): MCPSession | undefined;
|
|
208
|
+
terminateSession(sessionId: string): boolean;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Tool
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
interface MCPTool<TInput = unknown, TOutput = unknown> {
|
|
216
|
+
name: string;
|
|
217
|
+
description: string;
|
|
218
|
+
inputSchema: JSONSchema;
|
|
219
|
+
handler: (input: TInput, context?: ToolContext) => Promise<TOutput>;
|
|
220
|
+
category?: string;
|
|
221
|
+
tags?: string[];
|
|
222
|
+
cacheable?: boolean;
|
|
223
|
+
cacheTTL?: number;
|
|
224
|
+
timeout?: number;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Transport
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
interface ITransport {
|
|
232
|
+
readonly type: TransportType;
|
|
233
|
+
start(): Promise<void>;
|
|
234
|
+
stop(): Promise<void>;
|
|
235
|
+
onRequest(handler: RequestHandler): void;
|
|
236
|
+
onNotification(handler: NotificationHandler): void;
|
|
237
|
+
sendNotification?(notification: MCPNotification): Promise<void>;
|
|
238
|
+
getHealthStatus(): Promise<TransportHealthStatus>;
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Built-in Tools
|
|
243
|
+
|
|
244
|
+
The server automatically registers these system tools:
|
|
245
|
+
|
|
246
|
+
| Tool | Description |
|
|
247
|
+
|------|-------------|
|
|
248
|
+
| `system/info` | Get server information |
|
|
249
|
+
| `system/health` | Get health status |
|
|
250
|
+
| `system/metrics` | Get server metrics |
|
|
251
|
+
| `tools/list-detailed` | List all tools with details |
|
|
252
|
+
|
|
253
|
+
## Resources (MCP 2025-11-25)
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { createMCPServer, createTextResource } from '@claude-flow/mcp';
|
|
257
|
+
|
|
258
|
+
const server = createMCPServer({ transport: 'stdio' }, logger);
|
|
259
|
+
const resourceRegistry = server.getResourceRegistry();
|
|
260
|
+
|
|
261
|
+
// Register a text resource
|
|
262
|
+
const { resource, handler } = createTextResource(
|
|
263
|
+
'file://readme.txt',
|
|
264
|
+
'README',
|
|
265
|
+
'Welcome to the application!',
|
|
266
|
+
{ mimeType: 'text/plain' }
|
|
267
|
+
);
|
|
268
|
+
resourceRegistry.registerResource(resource, handler);
|
|
269
|
+
|
|
270
|
+
// Register with custom handler
|
|
271
|
+
resourceRegistry.registerResource(
|
|
272
|
+
{
|
|
273
|
+
uri: 'db://users/{id}',
|
|
274
|
+
name: 'User Data',
|
|
275
|
+
description: 'Get user by ID',
|
|
276
|
+
mimeType: 'application/json',
|
|
277
|
+
},
|
|
278
|
+
async (uri) => {
|
|
279
|
+
const id = uri.split('/').pop();
|
|
280
|
+
const user = await fetchUser(id);
|
|
281
|
+
return [{ uri, mimeType: 'application/json', text: JSON.stringify(user) }];
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
// Subscribe to updates
|
|
286
|
+
resourceRegistry.subscribe('file://readme.txt', (uri, content) => {
|
|
287
|
+
console.log('Resource updated:', uri);
|
|
288
|
+
});
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Prompts (MCP 2025-11-25)
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
import { createMCPServer, definePrompt, textMessage, interpolate } from '@claude-flow/mcp';
|
|
295
|
+
|
|
296
|
+
const server = createMCPServer({ transport: 'stdio' }, logger);
|
|
297
|
+
const promptRegistry = server.getPromptRegistry();
|
|
298
|
+
|
|
299
|
+
// Define a prompt with arguments
|
|
300
|
+
const codeReviewPrompt = definePrompt(
|
|
301
|
+
'code_review',
|
|
302
|
+
'Review code for quality and best practices',
|
|
303
|
+
async (args) => [
|
|
304
|
+
textMessage('user', `Please review this ${args.language} code:\n\n${args.code}`),
|
|
305
|
+
],
|
|
306
|
+
{
|
|
307
|
+
title: 'Code Review',
|
|
308
|
+
arguments: [
|
|
309
|
+
{ name: 'code', description: 'The code to review', required: true },
|
|
310
|
+
{ name: 'language', description: 'Programming language', required: false },
|
|
311
|
+
],
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
promptRegistry.register(codeReviewPrompt);
|
|
316
|
+
|
|
317
|
+
// Get prompt with arguments
|
|
318
|
+
const result = await promptRegistry.get('code_review', {
|
|
319
|
+
code: 'function hello() { return "world"; }',
|
|
320
|
+
language: 'JavaScript',
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Tasks (MCP 2025-11-25)
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import { createMCPServer } from '@claude-flow/mcp';
|
|
328
|
+
|
|
329
|
+
const server = createMCPServer({ transport: 'stdio' }, logger);
|
|
330
|
+
const taskManager = server.getTaskManager();
|
|
331
|
+
|
|
332
|
+
// Create a long-running task
|
|
333
|
+
const taskId = taskManager.createTask(async (reportProgress, signal) => {
|
|
334
|
+
for (let i = 0; i <= 100; i += 10) {
|
|
335
|
+
if (signal.aborted) throw new Error('Task cancelled');
|
|
336
|
+
|
|
337
|
+
reportProgress({
|
|
338
|
+
progress: i,
|
|
339
|
+
total: 100,
|
|
340
|
+
message: `Processing... ${i}%`,
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
await new Promise(r => setTimeout(r, 100));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return { success: true, processedItems: 100 };
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
// Get task status
|
|
350
|
+
const status = taskManager.getTask(taskId);
|
|
351
|
+
|
|
352
|
+
// Wait for completion
|
|
353
|
+
const result = await taskManager.waitForTask(taskId);
|
|
354
|
+
|
|
355
|
+
// Cancel a task
|
|
356
|
+
taskManager.cancelTask(taskId, 'User requested cancellation');
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## MCP Methods Supported
|
|
360
|
+
|
|
361
|
+
| Method | Description |
|
|
362
|
+
|--------|-------------|
|
|
363
|
+
| `initialize` | Initialize connection |
|
|
364
|
+
| `tools/list` | List available tools |
|
|
365
|
+
| `tools/call` | Execute a tool |
|
|
366
|
+
| `resources/list` | List resources with pagination |
|
|
367
|
+
| `resources/read` | Read resource content |
|
|
368
|
+
| `resources/subscribe` | Subscribe to updates |
|
|
369
|
+
| `resources/unsubscribe` | Unsubscribe from updates |
|
|
370
|
+
| `prompts/list` | List prompts with pagination |
|
|
371
|
+
| `prompts/get` | Get prompt with arguments |
|
|
372
|
+
| `tasks/status` | Get task status |
|
|
373
|
+
| `tasks/cancel` | Cancel a running task |
|
|
374
|
+
| `completion/complete` | Auto-complete arguments |
|
|
375
|
+
| `logging/setLevel` | Set log level |
|
|
376
|
+
| `ping` | Keep-alive |
|
|
377
|
+
|
|
378
|
+
## Performance Targets
|
|
379
|
+
|
|
380
|
+
| Metric | Target |
|
|
381
|
+
|--------|--------|
|
|
382
|
+
| Server startup | <400ms |
|
|
383
|
+
| Tool registration | <10ms |
|
|
384
|
+
| Tool execution overhead | <50ms |
|
|
385
|
+
| Connection acquire | <5ms |
|
|
386
|
+
| Connection release | <1ms |
|
|
387
|
+
|
|
388
|
+
## Security
|
|
389
|
+
|
|
390
|
+
### Authentication
|
|
391
|
+
|
|
392
|
+
```typescript
|
|
393
|
+
const server = createMCPServer({
|
|
394
|
+
auth: {
|
|
395
|
+
enabled: true,
|
|
396
|
+
method: 'token',
|
|
397
|
+
tokens: ['your-secret-token'],
|
|
398
|
+
},
|
|
399
|
+
}, logger);
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### CORS
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
const server = createMCPServer({
|
|
406
|
+
transport: 'http',
|
|
407
|
+
corsEnabled: true,
|
|
408
|
+
corsOrigins: ['https://your-domain.com'],
|
|
409
|
+
}, logger);
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
## Error Codes
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
const ErrorCodes = {
|
|
416
|
+
PARSE_ERROR: -32700,
|
|
417
|
+
INVALID_REQUEST: -32600,
|
|
418
|
+
METHOD_NOT_FOUND: -32601,
|
|
419
|
+
INVALID_PARAMS: -32602,
|
|
420
|
+
INTERNAL_ERROR: -32603,
|
|
421
|
+
SERVER_NOT_INITIALIZED: -32002,
|
|
422
|
+
AUTHENTICATION_REQUIRED: -32001,
|
|
423
|
+
};
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## License
|
|
427
|
+
|
|
428
|
+
MIT
|