MCPcopy Create free account
hub / github.com/astercloud/aster / ensureBridgeServer

Method ensureBridgeServer

pkg/tools/builtin/codeexecute.go:91–127  ·  view source on GitHub ↗

ensureBridgeServer 确保 HTTP 桥接服务器已启动 (PTC 支持)

(tc *tools.ToolContext)

Source from the content-addressed store, hash-verified

89
90// ensureBridgeServer 确保 HTTP 桥接服务器已启动 (PTC 支持)
91func (t *CodeExecuteTool) ensureBridgeServer(tc *tools.ToolContext) error {
92 t.mu.Lock()
93 defer t.mu.Unlock()
94
95 // 如果已经启动,直接返回
96 if t.serverStarted {
97 return nil
98 }
99
100 // 如果没有 toolBridge,不启动服务器(非 PTC 模式)
101 if t.toolBridge == nil {
102 return nil
103 }
104
105 // 创建并启动 HTTP 桥接服务器
106 t.httpServer = bridge.NewHTTPBridgeServer(t.toolBridge, t.bridgeURL)
107
108 // 设置工具上下文工厂
109 t.httpServer.SetContextFactory(func() *tools.ToolContext {
110 return tc
111 })
112
113 // 异步启动服务器
114 if err := t.httpServer.StartAsync(); err != nil {
115 return fmt.Errorf("failed to start HTTP bridge server: %w", err)
116 }
117
118 // 获取可用工具列表
119 availableTools := t.toolBridge.ListAvailableTools()
120
121 // 设置 RuntimeManager 的工具列表和桥接 URL
122 t.runtimeManager.SetPythonTools(availableTools)
123 t.runtimeManager.SetPythonBridgeURL(t.bridgeURL)
124
125 t.serverStarted = true
126 return nil
127}
128
129func (t *CodeExecuteTool) Execute(ctx context.Context, input map[string]any, tc *tools.ToolContext) (any, error) {
130 // 确保 HTTP 桥接服务器已启动 (PTC 支持)

Callers 1

ExecuteMethod · 0.95

Calls 6

NewHTTPBridgeServerFunction · 0.92
SetContextFactoryMethod · 0.80
ListAvailableToolsMethod · 0.80
SetPythonToolsMethod · 0.80
SetPythonBridgeURLMethod · 0.80
StartAsyncMethod · 0.65

Tested by

no test coverage detected