@@ -6,15 +6,38 @@ import (
66 "time"
77)
88
9- // Protocol version and server info.
9+ // Supported protocol versions (newest first).
10+ var supportedVersions = []string {
11+ "2025-03-26" ,
12+ "2024-11-05" ,
13+ }
14+
15+ // latestVersion is the most recent protocol version this server supports.
16+ const latestVersion = "2025-03-26"
17+
18+ // Server info constants.
1019const (
11- protocolVersion = "2024-11-05"
12- serverName = "nylas-mcp"
13- serverVersion = "1.0.0"
20+ serverName = "nylas-mcp"
21+ serverVersion = "1.0.0"
1422)
1523
24+ // negotiateVersion returns the newest version both client and server support.
25+ // If the client's requested version is in our supported list, return it.
26+ // Otherwise, return the latest version we support.
27+ func negotiateVersion (requested string ) string {
28+ for _ , v := range supportedVersions {
29+ if v == requested {
30+ return v
31+ }
32+ }
33+ return latestVersion
34+ }
35+
1636// handleInitialize responds to the MCP initialize request with server capabilities.
1737func (s * Server ) handleInitialize (req * Request ) []byte {
38+ params := parseInitializeParams (req .Params )
39+ negotiated := negotiateVersion (params .ProtocolVersion )
40+
1841 // Detect user's timezone for guidance
1942 localZone , _ := time .Now ().Zone ()
2043 tzName := time .Local .String ()
@@ -28,11 +51,11 @@ IMPORTANT - Timezone Consistency:
2851The user's local timezone is: %s (%s)
2952When displaying ANY timestamps to users (from emails, events, availability, etc.):
30531. Always use epoch_to_datetime tool with timezone "%s" to convert Unix timestamps
31- 2. Display ALL times in %s, never in UTC or the event's original timezone
54+ 2. Display ALL times in %s, never in UTC
32553. Format times clearly (e.g., "2:00 PM %s")` , tzName , localZone , tzName , localZone , localZone )
3356
3457 result := map [string ]any {
35- "protocolVersion" : protocolVersion ,
58+ "protocolVersion" : negotiated ,
3659 "capabilities" : map [string ]any {
3760 "tools" : map [string ]any {},
3861 },
@@ -57,8 +80,9 @@ func (s *Server) handleToolsList(req *Request) []byte {
5780
5881// handleToolCall dispatches a tool call to the appropriate executor.
5982func (s * Server ) handleToolCall (ctx context.Context , req * Request ) []byte {
60- name := req .Params .Name
61- args := req .Params .Arguments
83+ params := parseToolCallParams (req .Params )
84+ name := params .Name
85+ args := params .Arguments
6286 if args == nil {
6387 args = make (map [string ]any )
6488 }
@@ -183,7 +207,7 @@ func (s *Server) handleToolCall(ctx context.Context, req *Request) []byte {
183207 result = s .executeDatetimeToEpoch (args )
184208
185209 default :
186- result = toolError ( fmt .Sprintf ("unknown tool: %s" , name ))
210+ return errorResponse ( req . ID , codeInvalidParams , fmt .Sprintf ("unknown tool: %s" , name ))
187211 }
188212
189213 return successResponse (req .ID , result )
0 commit comments