MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / handleInitialize

Method handleInitialize

server/mcp/handler.go:217–254  ·  view source on GitHub ↗
(c *gin.Context, req request)

Source from the content-addressed store, hash-verified

215}
216
217func (s *Server) handleInitialize(c *gin.Context, req request) {
218 var params initializeParams
219 if len(req.Params) > 0 {
220 if err := json.Unmarshal(req.Params, &params); err != nil {
221 c.JSON(http.StatusBadRequest, response{
222 JSONRPC: "2.0",
223 ID: req.ID,
224 Error: &rpcError{Code: -32602, Message: "invalid initialize params"},
225 })
226 return
227 }
228 }
229
230 protocolVersion := negotiateProtocolVersion(params.ProtocolVersion)
231 currentSession := s.initializeSession(
232 c.Request.Context().Value(conf.UserKey).(*model.User).ID,
233 c.GetHeader(SessionHeader),
234 protocolVersion,
235 )
236 c.Header(SessionHeader, currentSession.id)
237 c.JSON(http.StatusOK, response{
238 JSONRPC: "2.0",
239 ID: req.ID,
240 Result: map[string]any{
241 "protocolVersion": protocolVersion,
242 "capabilities": map[string]any{
243 "tools": map[string]any{
244 "listChanged": false,
245 },
246 },
247 "serverInfo": map[string]any{
248 "name": "OpenList MCP",
249 "version": conf.Version,
250 },
251 "instructions": "Complete initialization with notifications/initialized, then use tools/list and tools/call. Available tools include openlist.fs.list, openlist.fs.get, and openlist.fs.link.",
252 },
253 })
254}
255
256func (s *Server) initializeSession(userID uint, requestedID string, protocolVersion string) *session {
257 s.mu.Lock()

Callers 1

handlePostMethod · 0.95

Calls 4

initializeSessionMethod · 0.95
negotiateProtocolVersionFunction · 0.85
HeaderMethod · 0.80
UnmarshalMethod · 0.45

Tested by

no test coverage detected