@@ -2,7 +2,6 @@ package chip
22
33import (
44 "context"
5- "errors"
65
76 "github.com/google/uuid"
87 "github.com/modelcontextprotocol/go-sdk/mcp"
@@ -12,37 +11,31 @@ type contextKey int
1211
1312const (
1413 callToolRequestKey contextKey = iota
15- toolConfigKey
14+ collibraHostKey
1615)
1716
18- func SetToolConfig (ctx context.Context , toolConfig * ToolConfig ) context.Context {
19- return context .WithValue (ctx , toolConfigKey , toolConfig )
20- }
21-
2217func SetCallToolRequest (ctx context.Context , toolRequest * mcp.CallToolRequest ) context.Context {
2318 return context .WithValue (ctx , callToolRequestKey , toolRequest )
2419}
2520
26- func GetCallToolRequest (ctx context.Context ) (* mcp.CallToolRequest , error ) {
21+ func GetCallToolRequest (ctx context.Context ) (* mcp.CallToolRequest , bool ) {
2722 toolRequest , ok := ctx .Value (callToolRequestKey ).(* mcp.CallToolRequest )
28- if ! ok || toolRequest == nil {
29- return nil , errors .New ("CallToolRequest not found in ctx" )
30- }
31- return toolRequest , nil
23+ return toolRequest , ok
3224}
3325
34- func GetToolConfig (ctx context.Context ) (* ToolConfig , error ) {
35- config , ok := ctx .Value (toolConfigKey ).(* ToolConfig )
36- if ! ok || config == nil {
37- return nil , errors .New ("ToolConfig not found in ctx" )
38- }
39- return config , nil
26+ func SetCollibraHost (ctx context.Context , collibraHost string ) context.Context {
27+ return context .WithValue (ctx , collibraHostKey , collibraHost )
28+ }
29+
30+ func GetCollibraHost (ctx context.Context ) (string , bool ) {
31+ collibraHost , ok := ctx .Value (collibraHostKey ).(string )
32+ return collibraHost , ok
4033}
4134
42- func GetSessionId (toolRequest * mcp. CallToolRequest ) string {
43- sessionId := toolRequest . GetSession (). ID ( )
44- if sessionId == "" {
45- return uuid . New ().String ()
35+ func GetSessionId (ctx context. Context ) string {
36+ toolRequest , ok := GetCallToolRequest ( ctx )
37+ if ok {
38+ return toolRequest . GetSession ().ID ()
4639 }
47- return sessionId
40+ return uuid . New (). String ()
4841}
0 commit comments