MCPcopy Index your code
hub / github.com/coder/coder / loadCachedWorkspaceContext

Method loadCachedWorkspaceContext

coderd/x/chatd/chatd.go:515–536  ·  view source on GitHub ↗

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),
)

Source from the content-addressed store, hash-verified

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.
515func (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

Callers 1

Calls 3

NewWorkspaceMCPToolFunction · 0.92
DeleteMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected