@@ -14,7 +14,6 @@ import (
1414 "github.com/gptscript-ai/gptscript/pkg/hash"
1515 "github.com/gptscript-ai/gptscript/pkg/mvl"
1616 "github.com/gptscript-ai/gptscript/pkg/types"
17- "github.com/gptscript-ai/gptscript/pkg/version"
1817 nmcp "github.com/nanobot-ai/nanobot/pkg/mcp"
1918)
2019
@@ -33,10 +32,9 @@ type Local struct {
3332}
3433
3534type Session struct {
36- ID string
37- InitResult nmcp.InitializeResult
38- Client * nmcp.Client
39- Config ServerConfig
35+ ID string
36+ Client * nmcp.Client
37+ Config ServerConfig
4038}
4139
4240type Config struct {
@@ -145,6 +143,7 @@ func (l *Local) ShutdownServer(server ServerConfig) error {
145143
146144 if session != nil && session .Client != nil {
147145 session .Client .Session .Close ()
146+ session .Client .Session .Wait ()
148147 }
149148
150149 return nil
@@ -224,7 +223,7 @@ func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName s
224223 },
225224 }
226225
227- if string (annotations ) != "{}" {
226+ if string (annotations ) != "{}" && string ( annotations ) != "null" {
228227 toolDef .MetaData = map [string ]string {
229228 "mcp-tool-annotations" : string (annotations ),
230229 }
@@ -243,7 +242,7 @@ func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName s
243242 ToolDef : types.ToolDef {
244243 Parameters : types.Parameters {
245244 Name : toolName ,
246- Description : session .InitResult .ServerInfo .Name ,
245+ Description : session .Client . Session . InitializeResult .ServerInfo .Name ,
247246 Export : toolNames ,
248247 },
249248 MetaData : map [string ]string {
@@ -252,18 +251,18 @@ func (l *Local) sessionToTools(ctx context.Context, session *Session, toolName s
252251 },
253252 }
254253
255- if session .InitResult .Instructions != "" {
254+ if session .Client . Session . InitializeResult .Instructions != "" {
256255 data , _ := json .Marshal (map [string ]any {
257256 "tools" : toolNames ,
258- "instructions" : session .InitResult .Instructions ,
257+ "instructions" : session .Client . Session . InitializeResult .Instructions ,
259258 })
260259 toolDefs = append (toolDefs , types.Tool {
261260 ToolDef : types.ToolDef {
262261 Parameters : types.Parameters {
263262 Name : session .ID ,
264263 Type : "context" ,
265264 },
266- Instructions : types .EchoPrefix + "\n " + `# START MCP SERVER INFO: ` + session .InitResult .ServerInfo .Name + "\n " +
265+ Instructions : types .EchoPrefix + "\n " + `# START MCP SERVER INFO: ` + session .Client . Session . InitializeResult .ServerInfo .Name + "\n " +
267266 `You have available the following tools from an MCP Server that has provided the following additional instructions` + "\n " +
268267 string (data ) + "\n " +
269268 `# END MCP SERVER INFO` + "\n " ,
@@ -284,7 +283,6 @@ func (l *Local) loadSession(server ServerConfig, serverName string) (*Session, e
284283 if l .sessionCtx == nil {
285284 l .sessionCtx , l .cancel = context .WithCancel (context .Background ())
286285 }
287- ctx := l .sessionCtx
288286 l .lock .Unlock ()
289287
290288 if ok {
@@ -303,22 +301,10 @@ func (l *Local) loadSession(server ServerConfig, serverName string) (*Session, e
303301 return nil , fmt .Errorf ("failed to create MCP stdio client: %w" , err )
304302 }
305303
306- initResult , err := c .Initialize (ctx , nmcp.InitializeRequest {
307- ProtocolVersion : "2025-03-26" ,
308- ClientInfo : nmcp.ClientInfo {
309- Name : version .ProgramName ,
310- Version : version .Get ().String (),
311- },
312- })
313- if err != nil {
314- return nil , fmt .Errorf ("failed to initialize MCP client: %w" , err )
315- }
316-
317304 result := & Session {
318- ID : id ,
319- InitResult : initResult ,
320- Client : c ,
321- Config : server ,
305+ ID : id ,
306+ Client : c ,
307+ Config : server ,
322308 }
323309
324310 l .lock .Lock ()
@@ -330,7 +316,7 @@ func (l *Local) loadSession(server ServerConfig, serverName string) (*Session, e
330316 }
331317
332318 if l .sessions == nil {
333- l .sessions = make (map [string ]* Session )
319+ l .sessions = make (map [string ]* Session , 1 )
334320 }
335321 l .sessions [id ] = result
336322 return result , nil
0 commit comments