1
- // src/index.ts --------------------------------------------------------------
2
1
import { Server } from "@modelcontextprotocol/sdk/server/index.js" ;
3
2
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js" ;
4
-
5
3
import {
6
4
InitializeRequestSchema ,
7
5
ListToolsRequestSchema ,
8
6
CallToolRequestSchema ,
9
7
CallToolRequest
10
8
} from "@modelcontextprotocol/sdk/types.js" ;
11
-
12
9
import { z } from "zod" ;
13
10
14
11
import {
@@ -21,21 +18,23 @@ import {
21
18
vibeLearnTool , VibeLearnInput , VibeLearnOutput
22
19
} from "./tools/vibeLearn.js" ;
23
20
24
- /* --------------------------------------------------------------------- */
25
- /* 0. optional Gemini startup */
26
- /* --------------------------------------------------------------------- */
21
+ // ────────────────────────────────
22
+ // 0. optional Gemini startup
23
+ // ────────────────────────────────
27
24
if ( process . env . GEMINI_API_KEY ) {
28
25
try {
29
26
// initializeGemini(process.env.GEMINI_API_KEY);
30
27
console . error ( "[LOG] Gemini initialised" ) ;
31
28
} catch ( e ) {
32
29
console . error ( "[ERR] Gemini init failed:" , e ) ;
33
30
}
31
+ } else {
32
+ console . error ( "[WARN] GEMINI_API_KEY not set – Gemini tools will fail" ) ;
34
33
}
35
34
36
- /* --------------------------------------------------------------------- */
37
- /* 1. Zod schemas (single source of truth) */
38
- /* --------------------------------------------------------------------- */
35
+ // ────────────────────────────────
36
+ // 1. Zod schemas
37
+ // ────────────────────────────────
39
38
const vibeCheckSchema = z . object ( {
40
39
plan : z . string ( ) ,
41
40
userRequest : z . string ( ) ,
@@ -52,71 +51,78 @@ const vibeLearnSchema = z.object({
52
51
solution : z . string ( )
53
52
} ) ;
54
53
55
- /* --------------------------------------------------------------------- */
56
- /* 2. create Server with “ tools” capability */
57
- /* --------------------------------------------------------------------- */
54
+ // ────────────────────────────────
55
+ // 2. Server with tools capability
56
+ // ────────────────────────────────
58
57
const server = new Server ( {
59
58
name : "vibe-check-mcp" ,
60
59
version : "0.2.0" ,
61
60
capabilities : { tools : { } }
62
61
} ) ;
63
62
64
- /* --------------------------------------------------------------------- */
65
- /* 3. initialize handler – MUST reply within 30 s */
66
- /* --------------------------------------------------------------------- */
63
+ // ────────────────────────────────
64
+ // 3. initialize handler
65
+ // ────────────────────────────────
67
66
server . setRequestHandler ( InitializeRequestSchema , async req => ( {
68
67
protocolVersion : req . params . protocolVersion ,
69
68
serverInfo : { name : "vibe-check-mcp" , version : "0.2.0" } ,
70
- capabilities : server . capabilities // echoes { tools: {} }
69
+ capabilities : { tools : { } } // ← fixed line
71
70
} ) ) ;
72
71
73
- /* --------------------------------------------------------------------- */
74
- /* 4. tools/list handler – static descriptors */
75
- /* --------------------------------------------------------------------- */
72
+ // ────────────────────────────────
73
+ // 4. tools/list handler
74
+ // ────────────────────────────────
76
75
const toolList = [
77
76
{ name : "vibe_check" , description : "Metacognitive check …" , inputSchema : vibeCheckSchema } ,
78
77
{ name : "vibe_distill" , description : "Distils a plan …" , inputSchema : vibeDistillSchema } ,
79
78
{ name : "vibe_learn" , description : "Logs mistake patterns" , inputSchema : vibeLearnSchema }
80
79
] ;
81
80
server . setRequestHandler ( ListToolsRequestSchema , async ( ) => ( { tools : toolList } ) ) ;
82
81
83
- /* --------------------------------------------------------------------- */
84
- /* 5. tools/call dispatcher */
85
- /* --------------------------------------------------------------------- */
82
+ // ────────────────────────────────
83
+ // 5. tools/call dispatcher
84
+ // ────────────────────────────────
86
85
server . setRequestHandler ( CallToolRequestSchema , async ( req : CallToolRequest ) => {
87
86
const { name, arguments : raw = { } } = req . params ;
88
87
89
88
switch ( name ) {
90
89
case "vibe_check" : {
91
90
const args : VibeCheckInput = vibeCheckSchema . parse ( raw ) ;
92
91
const out : VibeCheckOutput = await vibeCheckTool ( args ) ;
93
- return { content :[ { type :"text" ,
94
- text : out . questions + ( out . patternAlert ? `\n\n**Pattern Alert:** ${ out . patternAlert } ` : "" )
95
- } ] } ;
92
+ return {
93
+ content :[ { type :"text" ,
94
+ text : out . questions +
95
+ ( out . patternAlert ? `\n\n**Pattern Alert:** ${ out . patternAlert } ` : "" )
96
+ } ]
97
+ } ;
96
98
}
97
99
case "vibe_distill" : {
98
100
const args : VibeDistillInput = vibeDistillSchema . parse ( raw ) ;
99
101
const out : VibeDistillOutput = await vibeDistillTool ( args ) ;
100
- return { content :[ { type :"markdown" ,
101
- markdown : `${ out . distilledPlan } \n\n**Rationale:** ${ out . rationale } `
102
- } ] } ;
102
+ return {
103
+ content :[ { type :"markdown" ,
104
+ markdown : `${ out . distilledPlan } \n\n**Rationale:** ${ out . rationale } `
105
+ } ]
106
+ } ;
103
107
}
104
108
case "vibe_learn" : {
105
109
const args : VibeLearnInput = vibeLearnSchema . parse ( raw ) ;
106
110
const out : VibeLearnOutput = await vibeLearnTool ( args ) ;
107
111
const summary = out . topCategories . map ( c => `- ${ c . category } (${ c . count } )` ) . join ( "\n" ) ;
108
- return { content :[ { type :"text" ,
109
- text :`✅ Logged. Current tally: ${ out . currentTally } \n\n${ summary } `
110
- } ] } ;
112
+ return {
113
+ content :[ { type :"text" ,
114
+ text :`✅ Logged. Current tally: ${ out . currentTally } \n\n${ summary } `
115
+ } ]
116
+ } ;
111
117
}
112
118
default :
113
119
throw new Error ( `Unknown tool "${ name } "` ) ;
114
120
}
115
121
} ) ;
116
122
117
- /* --------------------------------------------------------------------- */
118
- /* 6. connect via STDIO */
119
- /* --------------------------------------------------------------------- */
123
+ // ────────────────────────────────
124
+ // 6. STDIO transport
125
+ // ────────────────────────────────
120
126
const transport = new StdioServerTransport ( ) ;
121
127
await server . connect ( transport ) ;
122
128
console . error ( "[OK] vibe‑check‑mcp ready (stdio)" ) ;
0 commit comments