Skip to content

Commit b6db184

Browse files
committed
Formatting
1 parent 08ff414 commit b6db184

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

server/errors.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import (
66

77
var (
88
// Common server errors
9-
ErrUnsupported = errors.New("not supported")
10-
ErrResourceNotFound = errors.New("resource not found")
11-
ErrPromptNotFound = errors.New("prompt not found")
12-
ErrToolNotFound = errors.New("tool not found")
13-
9+
ErrUnsupported = errors.New("not supported")
10+
ErrResourceNotFound = errors.New("resource not found")
11+
ErrPromptNotFound = errors.New("prompt not found")
12+
ErrToolNotFound = errors.New("tool not found")
13+
1414
// Session-related errors
1515
ErrSessionNotFound = errors.New("session not found")
1616
ErrSessionExists = errors.New("session already exists")
1717
ErrSessionNotInitialized = errors.New("session not properly initialized")
1818
ErrSessionDoesNotSupportTools = errors.New("session does not support per-session tools")
19-
19+
2020
// Notification-related errors
2121
ErrNotificationNotInitialized = errors.New("notification channel not initialized")
2222
ErrNotificationChannelBlocked = errors.New("notification channel full or blocked")
23-
)
23+
)

server/server.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -740,23 +740,23 @@ func (s *MCPServer) handleListTools(
740740
// Override or add session-specific tools
741741
// We need to create a map first to merge the tools properly
742742
toolMap := make(map[string]mcp.Tool)
743-
743+
744744
// Add global tools first
745745
for _, tool := range tools {
746746
toolMap[tool.Name] = tool
747747
}
748-
748+
749749
// Then override with session-specific tools
750750
for name, serverTool := range sessionTools {
751751
toolMap[name] = serverTool.Tool
752752
}
753-
753+
754754
// Convert back to slice
755755
tools = make([]mcp.Tool, 0, len(toolMap))
756756
for _, tool := range toolMap {
757757
tools = append(tools, tool)
758758
}
759-
759+
760760
// Sort again to maintain consistent ordering
761761
sort.Slice(tools, func(i, j int) bool {
762762
return tools[i].Name < tools[j].Name
@@ -783,7 +783,7 @@ func (s *MCPServer) handleListTools(
783783
err: err,
784784
}
785785
}
786-
786+
787787
result := mcp.ListToolsResult{
788788
Tools: toolsToReturn,
789789
PaginatedResult: mcp.PaginatedResult{
@@ -801,7 +801,7 @@ func (s *MCPServer) handleToolCall(
801801
// First check session-specific tools
802802
var tool ServerTool
803803
var ok bool
804-
804+
805805
session := ClientSessionFromContext(ctx)
806806
if session != nil {
807807
if sessionWithTools, ok := session.(SessionWithTools); ok {
@@ -810,7 +810,7 @@ func (s *MCPServer) handleToolCall(
810810
}
811811
}
812812
}
813-
813+
814814
// If not found in session tools, check global tools
815815
if !ok {
816816
s.toolsMu.RLock()
@@ -888,4 +888,4 @@ func createErrorResponse(
888888
Message: message,
889889
},
890890
}
891-
}
891+
}

server/session.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *MCPServer) AddSessionTools(sessionID string, tools ...ServerTool) error
183183

184184
// Send notification only to this session
185185
s.SendNotificationToSpecificClient(sessionID, "notifications/tools/list_changed", nil)
186-
186+
187187
return nil
188188
}
189189

@@ -212,6 +212,6 @@ func (s *MCPServer) DeleteSessionTools(sessionID string, names ...string) error
212212

213213
// Send notification only to this session
214214
s.SendNotificationToSpecificClient(sessionID, "notifications/tools/list_changed", nil)
215-
215+
216216
return nil
217-
}
217+
}

server/session_test.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestSessionWithTools_Integration(t *testing.T) {
109109
// Check if the session can be cast to SessionWithTools
110110
swt, ok := s.(SessionWithTools)
111111
require.True(t, ok, "Session should implement SessionWithTools")
112-
112+
113113
// Check if the tools are accessible
114114
tools := swt.GetSessionTools()
115115
require.NotNil(t, tools, "Session tools should be available")
@@ -121,13 +121,13 @@ func TestSessionWithTools_Integration(t *testing.T) {
121121
tool, exists := tools["session-tool"]
122122
require.True(t, exists, "Session tool should exist in the map")
123123
require.NotNil(t, tool, "Session tool should not be nil")
124-
124+
125125
// Now test calling directly with the handler
126126
result, err := tool.Handler(sessionCtx, testReq)
127127
require.NoError(t, err, "No error calling session tool handler directly")
128128
require.NotNil(t, result, "Result should not be nil")
129129
require.Len(t, result.Content, 1, "Result should have one content item")
130-
130+
131131
textContent, ok := result.Content[0].(mcp.TextContent)
132132
require.True(t, ok, "Content should be TextContent")
133133
assert.Equal(t, "session-tool result", textContent.Text, "Result text should match")
@@ -137,13 +137,13 @@ func TestSessionWithTools_Integration(t *testing.T) {
137137
func TestMCPServer_ToolsWithSessionTools(t *testing.T) {
138138
// Basic test to verify that session-specific tools are returned correctly in a tools list
139139
server := NewMCPServer("test-server", "1.0.0", WithToolCapabilities(true))
140-
140+
141141
// Add global tools
142142
server.AddTools(
143143
ServerTool{Tool: mcp.NewTool("global-tool-1")},
144144
ServerTool{Tool: mcp.NewTool("global-tool-2")},
145145
)
146-
146+
147147
// Create a session with tools
148148
session := &fakeSessionWithTools{
149149
sessionID: "session-1",
@@ -154,28 +154,28 @@ func TestMCPServer_ToolsWithSessionTools(t *testing.T) {
154154
"global-tool-1": {Tool: mcp.NewTool("global-tool-1", mcp.WithDescription("Overridden"))},
155155
},
156156
}
157-
157+
158158
// Register the session
159159
err := server.RegisterSession(context.Background(), session)
160160
require.NoError(t, err)
161-
161+
162162
// List tools with session context
163163
sessionCtx := server.WithContext(context.Background(), session)
164164
resp := server.HandleMessage(sessionCtx, []byte(`{
165165
"jsonrpc": "2.0",
166166
"id": 1,
167167
"method": "tools/list"
168168
}`))
169-
169+
170170
jsonResp, ok := resp.(mcp.JSONRPCResponse)
171171
require.True(t, ok, "Response should be a JSONRPCResponse")
172-
172+
173173
result, ok := jsonResp.Result.(mcp.ListToolsResult)
174174
require.True(t, ok, "Result should be a ListToolsResult")
175-
175+
176176
// Should have 3 tools - 2 global tools (one overridden) and 1 session-specific tool
177177
assert.Len(t, result.Tools, 3, "Should have 3 tools")
178-
178+
179179
// Find the overridden tool and verify its description
180180
var found bool
181181
for _, tool := range result.Tools {
@@ -205,7 +205,7 @@ func TestMCPServer_AddSessionTools(t *testing.T) {
205205
require.NoError(t, err)
206206

207207
// Add session-specific tools
208-
err = server.AddSessionTools(session.SessionID(),
208+
err = server.AddSessionTools(session.SessionID(),
209209
ServerTool{Tool: mcp.NewTool("session-tool")},
210210
)
211211
require.NoError(t, err)
@@ -321,57 +321,57 @@ func TestMCPServer_ToolFiltering(t *testing.T) {
321321
}`))
322322
resp, ok := response.(mcp.JSONRPCResponse)
323323
require.True(t, ok)
324-
324+
325325
result, ok := resp.Result.(mcp.ListToolsResult)
326326
require.True(t, ok)
327-
327+
328328
// Should only include tools with the "allow-" prefix
329329
assert.Len(t, result.Tools, 3)
330-
330+
331331
// Verify all tools start with "allow-"
332332
for _, tool := range result.Tools {
333-
assert.True(t, len(tool.Name) >= 6 && tool.Name[:6] == "allow-",
333+
assert.True(t, len(tool.Name) >= 6 && tool.Name[:6] == "allow-",
334334
"Tool should start with 'allow-', got: %s", tool.Name)
335335
}
336336
}
337337

338338
func TestMCPServer_SendNotificationToSpecificClient(t *testing.T) {
339339
server := NewMCPServer("test-server", "1.0.0")
340-
340+
341341
session1Chan := make(chan mcp.JSONRPCNotification, 10)
342342
session1 := &fakeSession{
343343
sessionID: "session-1",
344344
notificationChannel: session1Chan,
345345
initialized: true,
346346
}
347-
347+
348348
session2Chan := make(chan mcp.JSONRPCNotification, 10)
349349
session2 := &fakeSession{
350350
sessionID: "session-2",
351351
notificationChannel: session2Chan,
352352
initialized: true,
353353
}
354-
354+
355355
session3 := &fakeSession{
356356
sessionID: "session-3",
357357
notificationChannel: make(chan mcp.JSONRPCNotification, 10),
358358
initialized: false, // Not initialized
359359
}
360-
360+
361361
// Register sessions
362362
err := server.RegisterSession(context.Background(), session1)
363363
require.NoError(t, err)
364364
err = server.RegisterSession(context.Background(), session2)
365365
require.NoError(t, err)
366366
err = server.RegisterSession(context.Background(), session3)
367367
require.NoError(t, err)
368-
368+
369369
// Send notification to session 1
370370
err = server.SendNotificationToSpecificClient(session1.SessionID(), "test-method", map[string]any{
371371
"data": "test-data",
372372
})
373373
require.NoError(t, err)
374-
374+
375375
// Check that only session 1 received the notification
376376
select {
377377
case notification := <-session1Chan:
@@ -380,22 +380,22 @@ func TestMCPServer_SendNotificationToSpecificClient(t *testing.T) {
380380
case <-time.After(100 * time.Millisecond):
381381
t.Error("Expected notification not received by session 1")
382382
}
383-
383+
384384
// Verify session 2 did not receive notification
385385
select {
386386
case notification := <-session2Chan:
387387
t.Errorf("Unexpected notification received by session 2: %v", notification)
388388
case <-time.After(100 * time.Millisecond):
389389
// Expected, no notification for session 2
390390
}
391-
391+
392392
// Test sending to non-existent session
393393
err = server.SendNotificationToSpecificClient("non-existent", "test-method", nil)
394394
assert.Error(t, err)
395395
assert.Contains(t, err.Error(), "not found")
396-
396+
397397
// Test sending to uninitialized session
398398
err = server.SendNotificationToSpecificClient(session3.SessionID(), "test-method", nil)
399399
assert.Error(t, err)
400400
assert.Contains(t, err.Error(), "not properly initialized")
401-
}
401+
}

0 commit comments

Comments
 (0)