loadCachedWorkspaceContext checks the MCP tools cache for the given chat and agent. Returns non-nil tools when the cache hits, which signals the caller to skip the slow MCP discovery path.
( chatID uuid.UUID, agent database.WorkspaceAgent, getConn func(context.Context) (workspacesdk.AgentConn, error), )
| 513 | // given chat and agent. Returns non-nil tools when the cache hits, |
| 514 | // which signals the caller to skip the slow MCP discovery path. |
| 515 | func (p *Server) loadCachedWorkspaceContext( |
| 516 | chatID uuid.UUID, |
| 517 | agent database.WorkspaceAgent, |
| 518 | getConn func(context.Context) (workspacesdk.AgentConn, error), |
| 519 | ) []fantasy.AgentTool { |
| 520 | cached, ok := p.workspaceMCPToolsCache.Load(chatID) |
| 521 | if !ok { |
| 522 | return nil |
| 523 | } |
| 524 | entry, ok := cached.(*cachedWorkspaceMCPTools) |
| 525 | if !ok || entry.agentID != agent.ID { |
| 526 | return nil |
| 527 | } |
| 528 | |
| 529 | var tools []fantasy.AgentTool |
| 530 | invalidate := func() { p.workspaceMCPToolsCache.Delete(chatID) } |
| 531 | for _, t := range entry.tools { |
| 532 | tools = append(tools, chattool.NewWorkspaceMCPTool(t, getConn, invalidate)) |
| 533 | } |
| 534 | |
| 535 | return tools |
| 536 | } |
| 537 | |
| 538 | // discoverWorkspaceMCPTools resolves the chat's workspace agent and |
| 539 | // lists the workspace MCP tools advertised by that agent. Results are |
no test coverage detected